From 9897128cb96d6b73590b8e3841243ebe63b7bb0f Mon Sep 17 00:00:00 2001 From: Fredrik Holmqvist Date: Sat, 11 Jul 2020 13:25:06 +0200 Subject: [PATCH] Update to ISL 0.22.1 Change-Id: I9d707083f0a9e71d3bcc02b3265bfb233bdbe46c Reviewed-on: https://review.haiku-os.org/c/buildtools/+/3019 Reviewed-by: Adrien Destugues --- gcc/isl/AUTHORS | 13 +++++++++++-- gcc/isl/ChangeLog | 30 ++++++++++++++++++++++++++++++ gcc/isl/GIT_HEAD_ID | 2 +- gcc/isl/Makefile.am | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/Makefile.in | 515 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/README | 4 ++-- gcc/isl/aclocal.m4 | 51 +++++++++++++++++++++++++++------------------------ gcc/isl/basis_reduction_templ.c | 17 ++++++++--------- gcc/isl/bound.c | 10 +++++++--- gcc/isl/cat.c | 1 + gcc/isl/closure.c | 2 +- gcc/isl/codegen.c | 5 ++++- gcc/isl/config.guess | 176 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- gcc/isl/config.sub | 66 ++++++++++++++++++++---------------------------------------------- gcc/isl/configure | 829 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/configure.ac | 21 ++++++++++++++++++--- gcc/isl/depcomp | 6 +++--- gcc/isl/install-sh | 25 +++++++++---------------- gcc/isl/isl_aff.c | 2026 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- gcc/isl/isl_aff_private.h | 39 ++++++++++++++++++++++++++++++++++++++- gcc/isl/isl_affine_hull.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_arg.c | 28 ++++++++++++++-------------- gcc/isl/isl_ast.c | 605 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_ast_build.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- gcc/isl/isl_ast_build_expr.c | 221 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_ast_build_private.h | 9 ++++----- gcc/isl/isl_ast_codegen.c | 409 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_ast_graft.c | 252 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_ast_graft_private.h | 5 ++++- gcc/isl/isl_ast_private.h | 7 ++++--- gcc/isl/isl_bernstein.c | 181 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_bound.c | 47 ++++++++++++++++++++++++++++------------------- gcc/isl/isl_coalesce.c | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_config.h.in | 14 +++++++++++++- gcc/isl/isl_config_post.h | 2 +- gcc/isl/isl_constraint.c | 264 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_constraint_private.h | 3 +++ gcc/isl/isl_convex_hull.c | 390 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_ctx.c | 32 ++++++++++++++++++++++++++++++-- gcc/isl/isl_dim_map.c | 41 +++++++++++++++++++++++++++++------------ gcc/isl/isl_dim_map.h | 7 ++++--- gcc/isl/isl_equalities.c | 45 ++++++++++++++++++++++----------------------- gcc/isl/isl_factorization.c | 27 ++++++++++++--------------- gcc/isl/isl_farkas.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- gcc/isl/isl_flow.c | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_fold.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_hash.c | 34 ++++++++++++++++++++-------------- gcc/isl/isl_hash_private.h | 8 -------- gcc/isl/isl_id.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------- gcc/isl/isl_id_private.h | 7 +++++++ gcc/isl/isl_id_to_ast_expr.c | 3 ++- gcc/isl/isl_id_to_id.c | 4 +++- gcc/isl/isl_id_to_pw_aff.c | 3 ++- gcc/isl/isl_ilp.c | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_input.c | 689 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_list_templ.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_local.c | 279 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_local.h | 19 ++++++++++++++++--- gcc/isl/isl_local_space.c | 477 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_local_space_private.h | 24 +++++++++++++++++++++--- gcc/isl/isl_lp.c | 12 +++++++++--- gcc/isl/isl_map.c | 4250 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- gcc/isl/isl_map_list.c | 12 ++++++------ gcc/isl/isl_map_private.h | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- gcc/isl/isl_map_simplify.c | 730 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_map_subtract.c | 62 +++++++++++++++++++++++++++++++++++++++----------------------- gcc/isl/isl_mat.c | 76 ++++++++++++++++++++++++++++++++++++++++------------------------------------ gcc/isl/isl_mat_private.h | 7 ++++++- gcc/isl/isl_morph.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- gcc/isl/isl_morph.h | 8 ++++---- gcc/isl/isl_multi_apply_templ.c | 4 ++-- gcc/isl/isl_multi_cmp.c | 2 +- gcc/isl/isl_multi_coalesce.c | 6 +++--- gcc/isl/isl_multi_dims.c | 26 ++++++++++++++++++++------ gcc/isl/isl_multi_floor.c | 4 ++-- gcc/isl/isl_multi_hash.c | 2 +- gcc/isl/isl_multi_intersect.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_multi_macro.h | 10 ++++------ gcc/isl/isl_multi_templ.c | 1016 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- gcc/isl/isl_multi_templ.h | 23 ++++++++++++++++++++++- gcc/isl/isl_options.c | 10 +++++++++- gcc/isl/isl_options_private.h | 1 + gcc/isl/isl_output.c | 919 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_point.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_point_private.h | 17 ++++++++++++++++- gcc/isl/isl_polynomial.c | 2520 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- gcc/isl/isl_polynomial_private.h | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- gcc/isl/isl_printer.c | 3 +++ gcc/isl/isl_pw_macro.h | 4 ++++ gcc/isl/isl_pw_templ.c | 656 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_range.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ gcc/isl/isl_reordering.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_reordering.h | 11 ++++++++--- gcc/isl/isl_sample.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- gcc/isl/isl_scan.c | 8 +++++--- gcc/isl/isl_schedule.c | 2 +- gcc/isl/isl_schedule_band.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------- gcc/isl/isl_schedule_band.h | 2 +- gcc/isl/isl_schedule_constraints.c | 50 +++++++++++++++++++++++++++++++------------------- gcc/isl/isl_schedule_constraints.h | 3 ++- gcc/isl/isl_schedule_node.c | 500 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_schedule_read.c | 7 +++++-- gcc/isl/isl_schedule_tree.c | 285 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_schedule_tree.h | 4 ++-- gcc/isl/isl_scheduler.c | 643 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_set_list.c | 12 ++++++------ gcc/isl/isl_space.c | 1442 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_space_private.h | 40 +++++++++++++++++++++++++++++++++------- gcc/isl/isl_srcdir.c.in | 2 +- gcc/isl/isl_stream.c | 8 +++++--- gcc/isl/isl_stride.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- gcc/isl/isl_tab.c | 224 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_tab.h | 6 ++++-- gcc/isl/isl_tab_lexopt_templ.c | 11 ++++++++--- gcc/isl/isl_tab_pip.c | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_test.c | 3480 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_transitive_closure.c | 627 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_union_eval.c | 6 ++++-- gcc/isl/isl_union_macro.h | 6 ++++++ gcc/isl/isl_union_map.c | 517 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_union_map_private.h | 5 +++++ gcc/isl/isl_union_multi.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_union_single.c | 25 ++++++++----------------- gcc/isl/isl_union_templ.c | 478 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/isl_val.c | 227 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- gcc/isl/isl_val_gmp.c | 14 +++++++------- gcc/isl/isl_val_imath.c | 14 +++++++------- gcc/isl/isl_val_private.h | 22 ++++------------------ gcc/isl/isl_val_sioimath.c | 14 +++++++------- gcc/isl/isl_vec.c | 17 +++++++++++++---- gcc/isl/isl_vertices.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------- gcc/isl/pip.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++------------- gcc/isl/polyhedron_minimize.c | 6 +++--- gcc/isl/polytope_scan.c | 9 ++++++--- gcc/isl/print.c | 3 +++ gcc/isl/print_templ.c | 8 +++++++- gcc/isl/schedule_test.sh.in | 10 ++++++++-- gcc/isl/doc/Makefile.in | 11 +++++++++-- gcc/isl/doc/manual.pdf | 0 gcc/isl/doc/user.pod | 1299 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/interface/Makefile.am | 33 +++++---------------------------- gcc/isl/interface/Makefile.in | 555 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- gcc/isl/interface/all.c | 1 - gcc/isl/interface/all.h | 11 ----------- gcc/isl/interface/extract_interface.cc | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/interface/generator.cc | 592 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/interface/generator.h | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/interface/isl.py | 14581 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- gcc/isl/interface/isl.py.top | 29 ----------------------------- gcc/isl/interface/isl_test_python.py | 201 -------------------------------------------------------------------------------- gcc/isl/interface/python.cc | 786 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/interface/python.h | 37 +++++++++++++++++++++++++++++-------- gcc/isl/m4/ax_detect_clang.m4 | 29 ++++++++++++++++++++++++++--- gcc/isl/include/isl/aff.h | 232 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/include/isl/aff_type.h | 8 +++++--- gcc/isl/include/isl/arg.h | 9 +++++---- gcc/isl/include/isl/ast.h | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- gcc/isl/include/isl/ast_build.h | 7 +++++-- gcc/isl/include/isl/ast_type.h | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------- gcc/isl/include/isl/constraint.h | 13 +++++++------ gcc/isl/include/isl/ctx.h | 4 ++++ gcc/isl/include/isl/flow.h | 2 +- gcc/isl/include/isl/hash.h | 9 +++++---- gcc/isl/include/isl/hmap_templ.c | 18 +++++++++++++----- gcc/isl/include/isl/id.h | 18 +++++++++++++++--- gcc/isl/include/isl/id_to_ast_expr.h | 2 +- gcc/isl/include/isl/id_to_id.h | 2 +- gcc/isl/include/isl/id_to_pw_aff.h | 2 +- gcc/isl/include/isl/ilp.h | 12 ++++++++++-- gcc/isl/include/isl/list.h | 45 ++++++++++++++++++++++++++++++++++++++------- gcc/isl/include/isl/local_space.h | 4 ++-- gcc/isl/include/isl/lp.h | 2 +- gcc/isl/include/isl/map.h | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- gcc/isl/include/isl/mat.h | 8 ++++---- gcc/isl/include/isl/multi.h | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/include/isl/options.h | 3 +++ gcc/isl/include/isl/point.h | 8 ++++---- gcc/isl/include/isl/polynomial.h | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gcc/isl/include/isl/polynomial_type.h | 5 +++++ gcc/isl/include/isl/printer.h | 2 +- gcc/isl/include/isl/schedule.h | 3 ++- gcc/isl/include/isl/schedule_node.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- gcc/isl/include/isl/set.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ gcc/isl/include/isl/space.h | 86 +++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- gcc/isl/include/isl/stream.h | 2 +- gcc/isl/include/isl/union_map.h | 45 +++++++++++++++++++++++++++++++++++++++------ gcc/isl/include/isl/union_map_type.h | 2 +- gcc/isl/include/isl/union_set.h | 23 ++++++++++++++++++++--- gcc/isl/include/isl/val.h | 29 ++++++++++++++++++----------- gcc/isl/include/isl/val_gmp.h | 2 +- gcc/isl/include/isl/vec.h | 5 +++-- gcc/isl/include/isl/vertices.h | 8 ++++---- gcc/isl/test_inputs/codegen/correlation.c | 2 +- gcc/isl/test_inputs/codegen/shift2.c | 13 +++++-------- gcc/isl/test_inputs/codegen/stride7.c | 12 +++++++----- gcc/isl/test_inputs/codegen/unroll4.c | 4 ++-- gcc/isl/test_inputs/codegen/cloog/classen.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------- 197 files changed, 35391 insertions(+), 15127 deletions(-) diff --git a/gcc/isl/AUTHORS b/gcc/isl/AUTHORS index 411b2bd..8ce9223 100644 --- a/gcc/isl/AUTHORS +++ a/gcc/isl/AUTHORS @@ -23,7 +23,11 @@ Domaine de Voluceau - Rocquencourt, B.P. 105 78153 Le Chesnay France -2015-2016 Polly Labs +2015-2019 Polly Labs +2018-2019 Cerebras Systems + 175 S San Antonio Rd + Los Altos, CA + USA Contributions by @@ -33,18 +37,23 @@ Albert Cohen Ray Donnelly Johannes Doerfert +Andi Drebes +Clement Foyer Armin Groesslinger Tobias Grosser +Frederik Harwath Alexandre Isoard Andreas Kloeckner Michael Kruse +Manjunath Kudlur Alexander Matz Sebastian Pop Louis-Noel Pouchet Benoit Pradelle -Uday Kumar Reddy +Uday Bondhugula Andreas Simbuerger Malhar Thakkar +Sergei Trofimovich Sven van Haastregt Oleksandr Zinenko diff --git a/gcc/isl/ChangeLog b/gcc/isl/ChangeLog index 56c9ad2..2193a72 100644 --- a/gcc/isl/ChangeLog +++ a/gcc/isl/ChangeLog @@ -1,3 +1,33 @@ +version: 0.22.1 +date: Sun Jan 12 10:48:18 CET 2020 +changes: + - fix error handling +--- +version: 0.22 +date: Fri Nov 1 18:39:30 CET 2019 +changes: + - improved bindings + - scheduler fix involving fixed dimensions + - accept ranges in tuples during parsing + - add some convenience functions +--- +version: 0.21 +date: Sat Mar 9 15:25:29 CET 2019 +changes: + - preliminary C++ bindings + - use incremental scheduler by default + - introduce isl_size type + - rename isl_ast_op_type to isl_ast_expr_op_type + - fix coalescing bugs + - use isl_bool to return extra boolean argument +--- +version: 0.20 +date: Sat Jul 21 18:10:08 CEST 2018 +changes: + - keep track of domain in 0D isl_multi_pw_aff and isl_multi_union_pw_aff + - add isl_aff_eval and isl_pw_aff_eval + - add fixed-size rectangular box hull +--- version: 0.19 date: Sat Mar 3 10:44:49 CET 2018 changes: diff --git a/gcc/isl/GIT_HEAD_ID b/gcc/isl/GIT_HEAD_ID index 67b746d..24f5623 100644 --- a/gcc/isl/GIT_HEAD_ID +++ a/gcc/isl/GIT_HEAD_ID @@ -1,1 +1,1 @@ -isl-0.19 +isl-0.22.1 diff --git a/gcc/isl/Makefile.am b/gcc/isl/Makefile.am index 4852c7e..2097df8 100644 --- a/gcc/isl/Makefile.am +++ a/gcc/isl/Makefile.am @@ -1,6 +1,11 @@ if HAVE_CLANG - MAYBE_INTERFACE = interface +if HAVE_CXX11 +MAYBE_INTERFACE = interface +FORCE: +interface/extract_interface: FORCE + $(MAKE) $(AM_MAKEFLAGS) -C interface extract_interface endif +endif SUBDIRS = . $(MAYBE_INTERFACE) doc DIST_SUBDIRS = $(MAYBE_INTERFACE) doc @@ -15,6 +20,30 @@ isl_flow isl_flow_cmp isl_schedule_cmp TESTS = isl_test codegen_test.sh pip_test.sh bound_test.sh isl_test_int \ flow_test.sh schedule_test.sh +if HAVE_CPP_ISL_H + CPP_H = include/isl/cpp.h +if HAVE_CXX11 + noinst_PROGRAMS += isl_test_cpp + TESTS += isl_test_cpp +endif +endif +if HAVE_CLANG +if HAVE_CXX11 + noinst_PROGRAMS += isl_test_cpp-checked isl_test_cpp-checked-conversion + TESTS += isl_test_cpp-checked isl_test_cpp-checked-conversion +if HAVE_PYTHON + TESTS += isl_test_python.py + noinst_PYTHON = interface/isl.py + isl_test_python.py: interface/isl.py libisl.la +endif +endif +endif +TEST_EXTENSIONS = .py +AM_TESTS_ENVIRONMENT = \ + export PYTHONPATH=interface; \ + export ISL_DYLD_LIBRARY_PATH=.libs; \ + export LD_LIBRARY_PATH=".libs:$(LD_LIBRARY_PATH)"; +PY_LOG_COMPILER = $(PYTHON) if IMATH_FOR_MP @@ -58,12 +87,14 @@ MP_INCLUDE_H = include/isl/val_gmp.h endif -AM_CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/include -Iinclude/ @MP_CPPFLAGS@ -AM_CFLAGS = @WARNING_FLAGS@ +includes = -I. -I$(srcdir) -I$(srcdir)/include -Iinclude/ +AM_CPPFLAGS = $(includes) @MP_CPPFLAGS@ +AM_CFLAGS = @WARNING_FLAGS@ @MP_CFLAGS@ libisl_la_SOURCES = \ $(MP_SRC) \ isl_aff.c \ + isl_aff_map.c \ isl_aff_private.h \ isl_affine_hull.c \ isl_arg.c \ @@ -84,6 +115,7 @@ isl_blk.h \ isl_bound.c \ isl_bound.h \ + isl_box.c \ isl_coalesce.c \ isl_constraint.c \ isl_constraint_private.h \ @@ -102,7 +134,6 @@ isl_flow.c \ isl_fold.c \ isl_hash.c \ - isl_hash_private.h \ isl_id_to_ast_expr.c \ isl_id_to_id.c \ isl_id_to_pw_aff.c \ @@ -110,6 +141,7 @@ isl_ilp_private.h \ isl_input.c \ isl_int.h \ + isl_local_private.h \ isl_local.h \ isl_local.c \ isl_local_space_private.h \ @@ -169,6 +201,8 @@ isl_stream_private.h \ isl_seq.c \ isl_seq.h \ + isl_set_to_ast_graft_list.c \ + isl_set_to_ast_graft_list.h \ isl_stride.c \ isl_tab.c \ isl_tab.h \ @@ -262,9 +296,77 @@ isl_closure_SOURCES = \ closure.c +isl_test_cpp_SOURCES = \ + isl_test_cpp.cc \ + include/isl/cpp.h +isl_test_cpp_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_LDADD = libisl.la @MP_LIBS@ + +isl_test_cpp_checked_SOURCES = \ + isl_test_cpp-checked.cc \ + include/isl/cpp-checked.h +isl_test_cpp_checked_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_checked_LDADD = libisl.la @MP_LIBS@ + +isl_test_cpp_checked_conversion_SOURCES = \ + isl_test_cpp-checked-conversion.cc \ + include/isl/cpp-checked-conversion.h +isl_test_cpp_checked_conversion_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_checked_conversion_LDADD = libisl.la @MP_LIBS@ + +# dummy library that captures the dependencies on all headers +# that are relevant for the bindings +noinst_LIBRARIES = libdep.a +libdep_a_SOURCES = dep.c + +if HAVE_CLANG +if HAVE_CXX11 +interface/isldlname.py: libisl.la + $(AM_V_GEN) $(GREP) dlname $< | $(SED) -e 's/dlname/isl_dlname/' > $@ +interface/isl.py: interface/extract_interface libdep.a python/isl.py.top \ + interface/isldlname.py + (cat interface/isldlname.py $(srcdir)/python/isl.py.top && \ + interface/extract_interface$(EXEEXT) --language=python \ + $(includes) $(srcdir)/all.h) \ + > $@ || (rm $@ && false) + +include/isl/cpp.h: interface/extract_interface libdep.a \ + cpp/cpp.h.top cpp/cpp.h.pre cpp/cpp.h.bot + $(MKDIR_P) "include/isl/cpp" && \ + (cat $(srcdir)/cpp/cpp.h.top $(srcdir)/all.h \ + $(srcdir)/cpp/cpp.h.pre && \ + interface/extract_interface$(EXEEXT) --language=cpp \ + $(includes) $(srcdir)/all.h && \ + cat $(srcdir)/cpp/cpp.h.bot) \ + > $@ || (rm $@ && false) + +include/isl/cpp-checked.h: interface/extract_interface libdep.a \ + cpp/cpp-checked.h.top \ + cpp/cpp-checked.h.pre cpp/cpp-checked.h.bot + (cat $(srcdir)/cpp/cpp-checked.h.top $(srcdir)/all.h \ + $(srcdir)/cpp/cpp-checked.h.pre && \ + interface/extract_interface$(EXEEXT) \ + --language=cpp-checked \ + $(includes) $(srcdir)/all.h && \ + cat $(srcdir)/cpp/cpp-checked.h.bot) \ + > $@ || (rm $@ && false) + +include/isl/cpp-checked-conversion.h: interface/extract_interface libdep.a \ + cpp/cpp-checked-conversion.h.top \ + cpp/cpp-checked-conversion.h.bot + (cat $(srcdir)/cpp/cpp-checked-conversion.h.top && \ + interface/extract_interface$(EXEEXT) \ + --language=cpp-checked-conversion \ + $(includes) $(srcdir)/all.h && \ + cat $(srcdir)/cpp/cpp-checked-conversion.h.bot) \ + > $@ || (rm $@ && false) +endif +endif + nodist_pkginclude_HEADERS = \ include/isl/stdint.h pkginclude_HEADERS = \ + $(CPP_H) \ $(MP_INCLUDE_H) \ include/isl/aff.h \ include/isl/aff_type.h \ @@ -274,8 +376,10 @@ include/isl/ast_build.h \ include/isl/constraint.h \ include/isl/ctx.h \ + include/isl/fixed_box.h \ include/isl/flow.h \ include/isl/id.h \ + include/isl/id_type.h \ include/isl/id_to_ast_expr.h \ include/isl/id_to_id.h \ include/isl/id_to_pw_aff.h \ @@ -310,20 +414,34 @@ include/isl/set.h \ include/isl/set_type.h \ include/isl/space.h \ + include/isl/space_type.h \ include/isl/stream.h \ + include/isl/stride_info.h \ include/isl/union_map.h \ include/isl/union_map_type.h \ include/isl/union_set.h \ include/isl/union_set_type.h \ include/isl/val.h \ + include/isl/val_type.h \ include/isl/vec.h \ include/isl/version.h \ include/isl/vertices.h -BUILT_SOURCES = gitversion.h - +if HAVE_CLANG +if HAVE_CXX11 + CPP_INTERFACES = \ + include/isl/cpp.h \ + include/isl/cpp-checked.h \ + include/isl/cpp-checked-conversion.h +endif +endif +BUILT_SOURCES = gitversion.h $(CPP_INTERFACES) CLEANFILES = \ - gitversion.h + gitversion.h \ + interface/isldlname.py \ + interface/isl.py \ + interface/isl.pyc \ + $(CPP_INTERFACES) DISTCLEANFILES = \ isl-uninstalled.sh \ @@ -336,38 +454,79 @@ LICENSE \ isl_config_post.h \ basis_reduction_templ.c \ + isl_bind_domain_templ.c \ bset_to_bmap.c \ bset_from_bmap.c \ + check_reparse_templ.c \ + check_reparse_test_templ.c \ + check_type_range_templ.c \ + isl_domain_factor_templ.c \ extract_key.c \ + has_single_reference_templ.c \ + isl_list_macro.h \ isl_list_templ.c \ isl_list_templ.h \ isl_map_lexopt_templ.c \ + isl_maybe_ast_graft_list.h \ isl_maybe_map.h \ isl_multi_macro.h \ + isl_multi_bind_templ.c \ + isl_multi_explicit_domain.c \ + isl_multi_pw_aff_explicit_domain.c \ + isl_multi_union_pw_aff_explicit_domain.c \ + isl_multi_no_explicit_domain.c \ + isl_multi_no_domain_templ.c \ isl_multi_templ.c \ isl_multi_templ.h \ + isl_multi_align_templ.c \ + isl_multi_align_set.c \ + isl_multi_align_union_set.c \ isl_multi_apply_templ.c \ isl_multi_apply_set.c \ isl_multi_apply_union_set.c \ + isl_multi_arith_templ.c \ + isl_multi_bind_domain_templ.c \ isl_multi_cmp.c \ isl_multi_coalesce.c \ + isl_multi_dim_id_templ.c \ isl_multi_dims.c \ + isl_multi_domain_templ.c \ isl_multi_floor.c \ + isl_multi_from_base_templ.c \ isl_multi_gist.c \ isl_multi_hash.c \ isl_multi_intersect.c \ + isl_multi_identity_templ.c \ + isl_multi_locals_templ.c \ + isl_multi_move_dims_templ.c \ + isl_multi_nan_templ.c \ + isl_multi_param_templ.c \ + isl_multi_product_templ.c \ + isl_multi_read_no_explicit_domain_templ.c \ + isl_multi_splice_templ.c \ + isl_multi_tuple_id_templ.c \ + isl_multi_zero_templ.c \ + opt_type.h \ print_templ.c \ print_templ_yaml.c \ + print_yaml_field_templ.c \ isl_power_templ.c \ + isl_project_out_all_params_templ.c \ isl_pw_macro.h \ isl_pw_templ.c \ + isl_pw_templ.h \ + isl_pw_bind_domain_templ.c \ + isl_pw_eval.c \ isl_pw_hash.c \ isl_pw_union_opt.c \ read_in_string_templ.c \ set_to_map.c \ set_from_map.c \ + set_list_from_map_list_inl.c \ isl_tab_lexopt_templ.c \ + isl_test_list_templ.c \ uset_to_umap.c \ + uset_from_umap.c \ isl_union_macro.h \ isl_union_templ.c \ isl_union_single.c \ @@ -389,9 +548,11 @@ imath/imath.h \ imath/imrat.c \ imath/imrat.h \ - interface/all.h \ - interface/isl.py.top \ - interface/isl_test_python.py \ + all.h \ + cpp \ + python \ + isl_test_cpp-generic.cc \ + isl_test_python.py \ test_inputs dist-hook: diff --git a/gcc/isl/Makefile.in b/gcc/isl/Makefile.in index 209ab45..a7cf336 100644 --- a/gcc/isl/Makefile.in +++ a/gcc/isl/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2014 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -17,6 +17,7 @@ + VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ @@ -98,17 +99,23 @@ isl_closure$(EXEEXT) isl_bound$(EXEEXT) isl_schedule$(EXEEXT) \ isl_codegen$(EXEEXT) isl_test_int$(EXEEXT) isl_flow$(EXEEXT) \ isl_flow_cmp$(EXEEXT) isl_schedule_cmp$(EXEEXT) \ - $(am__EXEEXT_1) + $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) TESTS = isl_test$(EXEEXT) codegen_test.sh pip_test.sh bound_test.sh \ isl_test_int$(EXEEXT) flow_test.sh schedule_test.sh \ - $(am__EXEEXT_1) -@IMATH_FOR_MP_TRUE@am__append_1 = isl_test_imath -@IMATH_FOR_MP_TRUE@am__append_2 = isl_test_imath -@IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_TRUE@am__append_3 = isl_int_sioimath.h \ + $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__append_5) \ + $(am__EXEEXT_3) +@HAVE_CPP_ISL_H_TRUE@@HAVE_CXX11_TRUE@am__append_1 = isl_test_cpp +@HAVE_CPP_ISL_H_TRUE@@HAVE_CXX11_TRUE@am__append_2 = isl_test_cpp +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@am__append_3 = isl_test_cpp-checked isl_test_cpp-checked-conversion +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@am__append_4 = isl_test_cpp-checked isl_test_cpp-checked-conversion +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@@HAVE_PYTHON_TRUE@am__append_5 = isl_test_python.py +@IMATH_FOR_MP_TRUE@am__append_6 = isl_test_imath +@IMATH_FOR_MP_TRUE@am__append_7 = isl_test_imath +@IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_TRUE@am__append_8 = isl_int_sioimath.h \ @IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_TRUE@ isl_int_sioimath.c \ @IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_TRUE@ isl_val_sioimath.c -@IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_FALSE@am__append_4 = isl_val_imath.c +@IMATH_FOR_MP_TRUE@@SMALL_INT_OPT_FALSE@am__append_9 = isl_val_imath.c subdir = . ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ @@ -117,6 +124,8 @@ $(top_srcdir)/m4/ax_compiler_vendor.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \ $(top_srcdir)/m4/ax_detect_clang.m4 \ $(top_srcdir)/m4/ax_detect_git_head.m4 \ $(top_srcdir)/m4/ax_detect_gmp.m4 \ @@ -132,8 +141,8 @@ am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ $(ACLOCAL_M4) DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ - $(am__configure_deps) $(am__pkginclude_HEADERS_DIST) \ - $(am__DIST_COMMON) + $(am__configure_deps) $(am__noinst_PYTHON_DIST) \ + $(am__pkginclude_HEADERS_DIST) $(am__DIST_COMMON) am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d @@ -141,6 +150,16 @@ CONFIG_CLEAN_FILES = isl_srcdir.c bound_test.sh codegen_test.sh \ pip_test.sh flow_test.sh schedule_test.sh CONFIG_CLEAN_VPATH_FILES = +LIBRARIES = $(noinst_LIBRARIES) +ARFLAGS = cru +AM_V_AR = $(am__v_AR_@AM_V@) +am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) +am__v_AR_0 = @echo " AR " $@; +am__v_AR_1 = +libdep_a_AR = $(AR) $(ARFLAGS) +libdep_a_LIBADD = +am_libdep_a_OBJECTS = dep.$(OBJEXT) +libdep_a_OBJECTS = $(am_libdep_a_OBJECTS) am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj = case $$p in \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ @@ -178,20 +197,20 @@ imath_wrap/imrat.h imath_wrap/wrap.h imath_wrap/gmp_compat.c \ imath_wrap/imath.c imath_wrap/imrat.c isl_int_sioimath.h \ isl_int_sioimath.c isl_val_sioimath.c isl_val_imath.c \ - isl_aff.c isl_aff_private.h isl_affine_hull.c isl_arg.c \ - isl_ast.c isl_ast_private.h isl_ast_build.c \ + isl_aff.c isl_aff_map.c isl_aff_private.h isl_affine_hull.c \ + isl_arg.c isl_ast.c isl_ast_private.h isl_ast_build.c \ isl_ast_build_private.h isl_ast_build_expr.c \ isl_ast_build_expr.h isl_ast_codegen.c isl_ast_graft.c \ isl_ast_graft_private.h isl_basis_reduction.h \ basis_reduction_tab.c isl_bernstein.c isl_bernstein.h \ - isl_blk.c isl_blk.h isl_bound.c isl_bound.h isl_coalesce.c \ - isl_constraint.c isl_constraint_private.h isl_convex_hull.c \ - isl_ctx.c isl_ctx_private.h isl_deprecated.c isl_dim_map.h \ - isl_dim_map.c isl_equalities.c isl_equalities.h \ + isl_blk.c isl_blk.h isl_bound.c isl_bound.h isl_box.c \ + isl_coalesce.c isl_constraint.c isl_constraint_private.h \ + isl_convex_hull.c isl_ctx.c isl_ctx_private.h isl_deprecated.c \ + isl_dim_map.h isl_dim_map.c isl_equalities.c isl_equalities.h \ isl_factorization.c isl_factorization.h isl_farkas.c isl_ffs.c \ - isl_flow.c isl_fold.c isl_hash.c isl_hash_private.h \ - isl_id_to_ast_expr.c isl_id_to_id.c isl_id_to_pw_aff.c \ - isl_ilp.c isl_ilp_private.h isl_input.c isl_int.h isl_local.h \ + isl_flow.c isl_fold.c isl_hash.c isl_id_to_ast_expr.c \ + isl_id_to_id.c isl_id_to_pw_aff.c isl_ilp.c isl_ilp_private.h \ + isl_input.c isl_int.h isl_local_private.h isl_local.h \ isl_local.c isl_local_space_private.h isl_local_space.c \ isl_lp.c isl_lp_private.h isl_map.c isl_map_list.c \ isl_map_simplify.c isl_map_subtract.c isl_map_private.h \ @@ -208,9 +227,10 @@ isl_schedule_constraints.c isl_schedule_constraints.h \ isl_scheduler.c isl_set_list.c isl_sort.c isl_sort.h \ isl_space.c isl_space_private.h isl_stream.c \ - isl_stream_private.h isl_seq.c isl_seq.h isl_stride.c \ - isl_tab.c isl_tab.h isl_tab_pip.c isl_tarjan.c isl_tarjan.h \ - isl_transitive_closure.c isl_union_map.c \ + isl_stream_private.h isl_seq.c isl_seq.h \ + isl_set_to_ast_graft_list.c isl_set_to_ast_graft_list.h \ + isl_stride.c isl_tab.c isl_tab.h isl_tab_pip.c isl_tarjan.c \ + isl_tarjan.h isl_transitive_closure.c isl_union_map.c \ isl_union_map_private.h isl_union_set_private.h isl_val.c \ isl_val_private.h isl_vec_private.h isl_vec.c isl_version.c \ isl_vertices_private.h isl_vertices.c isl_yaml.h @@ -229,25 +249,26 @@ @GMP_FOR_MP_FALSE@@IMATH_FOR_MP_TRUE@ $(am__objects_3) @GMP_FOR_MP_TRUE@am__objects_4 = $(am__objects_1) isl_gmp.lo \ @GMP_FOR_MP_TRUE@ isl_val_gmp.lo -am_libisl_la_OBJECTS = $(am__objects_4) isl_aff.lo isl_affine_hull.lo \ - isl_arg.lo isl_ast.lo isl_ast_build.lo isl_ast_build_expr.lo \ - isl_ast_codegen.lo isl_ast_graft.lo basis_reduction_tab.lo \ - isl_bernstein.lo isl_blk.lo isl_bound.lo isl_coalesce.lo \ - isl_constraint.lo isl_convex_hull.lo isl_ctx.lo \ - isl_deprecated.lo isl_dim_map.lo isl_equalities.lo \ - isl_factorization.lo isl_farkas.lo isl_ffs.lo isl_flow.lo \ - isl_fold.lo isl_hash.lo isl_id_to_ast_expr.lo isl_id_to_id.lo \ - isl_id_to_pw_aff.lo isl_ilp.lo isl_input.lo isl_local.lo \ - isl_local_space.lo isl_lp.lo isl_map.lo isl_map_list.lo \ - isl_map_simplify.lo isl_map_subtract.lo \ - isl_map_to_basic_set.lo isl_mat.lo isl_morph.lo isl_id.lo \ - isl_obj.lo isl_options.lo isl_output.lo isl_point.lo \ - isl_polynomial.lo isl_printer.lo print.lo isl_range.lo \ - isl_reordering.lo isl_sample.lo isl_scan.lo isl_schedule.lo \ - isl_schedule_band.lo isl_schedule_node.lo isl_schedule_read.lo \ - isl_schedule_tree.lo isl_schedule_constraints.lo \ - isl_scheduler.lo isl_set_list.lo isl_sort.lo isl_space.lo \ - isl_stream.lo isl_seq.lo isl_stride.lo isl_tab.lo \ +am_libisl_la_OBJECTS = $(am__objects_4) isl_aff.lo isl_aff_map.lo \ + isl_affine_hull.lo isl_arg.lo isl_ast.lo isl_ast_build.lo \ + isl_ast_build_expr.lo isl_ast_codegen.lo isl_ast_graft.lo \ + basis_reduction_tab.lo isl_bernstein.lo isl_blk.lo \ + isl_bound.lo isl_box.lo isl_coalesce.lo isl_constraint.lo \ + isl_convex_hull.lo isl_ctx.lo isl_deprecated.lo isl_dim_map.lo \ + isl_equalities.lo isl_factorization.lo isl_farkas.lo \ + isl_ffs.lo isl_flow.lo isl_fold.lo isl_hash.lo \ + isl_id_to_ast_expr.lo isl_id_to_id.lo isl_id_to_pw_aff.lo \ + isl_ilp.lo isl_input.lo isl_local.lo isl_local_space.lo \ + isl_lp.lo isl_map.lo isl_map_list.lo isl_map_simplify.lo \ + isl_map_subtract.lo isl_map_to_basic_set.lo isl_mat.lo \ + isl_morph.lo isl_id.lo isl_obj.lo isl_options.lo isl_output.lo \ + isl_point.lo isl_polynomial.lo isl_printer.lo print.lo \ + isl_range.lo isl_reordering.lo isl_sample.lo isl_scan.lo \ + isl_schedule.lo isl_schedule_band.lo isl_schedule_node.lo \ + isl_schedule_read.lo isl_schedule_tree.lo \ + isl_schedule_constraints.lo isl_scheduler.lo isl_set_list.lo \ + isl_sort.lo isl_space.lo isl_stream.lo isl_seq.lo \ + isl_set_to_ast_graft_list.lo isl_stride.lo isl_tab.lo \ isl_tab_pip.lo isl_tarjan.lo isl_transitive_closure.lo \ isl_union_map.lo isl_val.lo isl_vec.lo isl_version.lo \ isl_vertices.lo @@ -259,7 +280,11 @@ libisl_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(libisl_la_LDFLAGS) $(LDFLAGS) -o $@ -@IMATH_FOR_MP_TRUE@am__EXEEXT_1 = isl_test_imath$(EXEEXT) +@HAVE_CPP_ISL_H_TRUE@@HAVE_CXX11_TRUE@am__EXEEXT_1 = \ +@HAVE_CPP_ISL_H_TRUE@@HAVE_CXX11_TRUE@ isl_test_cpp$(EXEEXT) +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@am__EXEEXT_2 = isl_test_cpp-checked$(EXEEXT) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ isl_test_cpp-checked-conversion$(EXEEXT) +@IMATH_FOR_MP_TRUE@am__EXEEXT_3 = isl_test_imath$(EXEEXT) PROGRAMS = $(noinst_PROGRAMS) am_isl_bound_OBJECTS = bound.$(OBJEXT) isl_bound_OBJECTS = $(am_isl_bound_OBJECTS) @@ -335,6 +360,28 @@ isl_test_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(isl_test_LDFLAGS) $(LDFLAGS) -o $@ +am_isl_test_cpp_OBJECTS = isl_test_cpp.$(OBJEXT) +isl_test_cpp_OBJECTS = $(am_isl_test_cpp_OBJECTS) +isl_test_cpp_DEPENDENCIES = libisl.la +isl_test_cpp_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(isl_test_cpp_LDFLAGS) $(LDFLAGS) -o $@ +am_isl_test_cpp_checked_OBJECTS = isl_test_cpp-checked.$(OBJEXT) +isl_test_cpp_checked_OBJECTS = $(am_isl_test_cpp_checked_OBJECTS) +isl_test_cpp_checked_DEPENDENCIES = libisl.la +isl_test_cpp_checked_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(AM_CXXFLAGS) $(CXXFLAGS) $(isl_test_cpp_checked_LDFLAGS) \ + $(LDFLAGS) -o $@ +am_isl_test_cpp_checked_conversion_OBJECTS = \ + isl_test_cpp-checked-conversion.$(OBJEXT) +isl_test_cpp_checked_conversion_OBJECTS = \ + $(am_isl_test_cpp_checked_conversion_OBJECTS) +isl_test_cpp_checked_conversion_DEPENDENCIES = libisl.la +isl_test_cpp_checked_conversion_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ + $(AM_CXXFLAGS) $(CXXFLAGS) \ + $(isl_test_cpp_checked_conversion_LDFLAGS) $(LDFLAGS) -o $@ isl_test_imath_SOURCES = isl_test_imath.c isl_test_imath_OBJECTS = isl_test_imath.$(OBJEXT) @IMATH_FOR_MP_TRUE@isl_test_imath_DEPENDENCIES = libisl.la @@ -382,23 +429,46 @@ am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(libisl_la_SOURCES) $(isl_bound_SOURCES) $(isl_cat_SOURCES) \ - $(isl_closure_SOURCES) $(isl_codegen_SOURCES) \ - $(isl_flow_SOURCES) $(isl_flow_cmp_SOURCES) $(isl_pip_SOURCES) \ +CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ + $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) +LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CXXFLAGS) $(CXXFLAGS) +AM_V_CXX = $(am__v_CXX_@AM_V@) +am__v_CXX_ = $(am__v_CXX_@AM_DEFAULT_V@) +am__v_CXX_0 = @echo " CXX " $@; +am__v_CXX_1 = +CXXLD = $(CXX) +CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ + $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CXXLD = $(am__v_CXXLD_@AM_V@) +am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) +am__v_CXXLD_0 = @echo " CXXLD " $@; +am__v_CXXLD_1 = +SOURCES = $(libdep_a_SOURCES) $(libisl_la_SOURCES) \ + $(isl_bound_SOURCES) $(isl_cat_SOURCES) $(isl_closure_SOURCES) \ + $(isl_codegen_SOURCES) $(isl_flow_SOURCES) \ + $(isl_flow_cmp_SOURCES) $(isl_pip_SOURCES) \ $(isl_polyhedron_detect_equalities_SOURCES) \ $(isl_polyhedron_minimize_SOURCES) \ $(isl_polyhedron_sample_SOURCES) $(isl_polytope_scan_SOURCES) \ $(isl_schedule_SOURCES) $(isl_schedule_cmp_SOURCES) isl_test.c \ - isl_test_imath.c isl_test_int.c -DIST_SOURCES = $(am__libisl_la_SOURCES_DIST) $(isl_bound_SOURCES) \ - $(isl_cat_SOURCES) $(isl_closure_SOURCES) \ + $(isl_test_cpp_SOURCES) $(isl_test_cpp_checked_SOURCES) \ + $(isl_test_cpp_checked_conversion_SOURCES) isl_test_imath.c \ + isl_test_int.c +DIST_SOURCES = $(libdep_a_SOURCES) $(am__libisl_la_SOURCES_DIST) \ + $(isl_bound_SOURCES) $(isl_cat_SOURCES) $(isl_closure_SOURCES) \ $(isl_codegen_SOURCES) $(isl_flow_SOURCES) \ $(isl_flow_cmp_SOURCES) $(isl_pip_SOURCES) \ $(isl_polyhedron_detect_equalities_SOURCES) \ $(isl_polyhedron_minimize_SOURCES) \ $(isl_polyhedron_sample_SOURCES) $(isl_polytope_scan_SOURCES) \ $(isl_schedule_SOURCES) $(isl_schedule_cmp_SOURCES) isl_test.c \ - isl_test_imath.c isl_test_int.c + $(isl_test_cpp_SOURCES) $(isl_test_cpp_checked_SOURCES) \ + $(isl_test_cpp_checked_conversion_SOURCES) isl_test_imath.c \ + isl_test_int.c RECURSIVE_TARGETS = all-recursive check-recursive cscopelist-recursive \ ctags-recursive dvi-recursive html-recursive info-recursive \ install-data-recursive install-dvi-recursive \ @@ -412,31 +482,37 @@ n|no|NO) false;; \ *) (install-info --version) >/dev/null 2>&1;; \ esac +am__noinst_PYTHON_DIST = interface/isl.py +am__py_compile = PYTHON=$(PYTHON) $(SHELL) $(py_compile) +py_compile = $(top_srcdir)/py-compile DATA = $(pkgconfig_DATA) -am__pkginclude_HEADERS_DIST = include/isl/val_gmp.h include/isl/aff.h \ - include/isl/aff_type.h include/isl/arg.h include/isl/ast.h \ - include/isl/ast_type.h include/isl/ast_build.h \ - include/isl/constraint.h include/isl/ctx.h include/isl/flow.h \ - include/isl/id.h include/isl/id_to_ast_expr.h \ - include/isl/id_to_id.h include/isl/id_to_pw_aff.h \ - include/isl/ilp.h include/isl/hash.h include/isl/hmap.h \ - include/isl/hmap_templ.c include/isl/list.h \ - include/isl/local_space.h include/isl/lp.h include/isl/mat.h \ - include/isl/map.h include/isl/map_to_basic_set.h \ - include/isl/map_type.h include/isl/maybe.h \ - include/isl/maybe_ast_expr.h include/isl/maybe_basic_set.h \ - include/isl/maybe_id.h include/isl/maybe_pw_aff.h \ - include/isl/maybe_templ.h include/isl/multi.h \ - include/isl/obj.h include/isl/options.h include/isl/point.h \ - include/isl/polynomial.h include/isl/polynomial_type.h \ - include/isl/printer.h include/isl/printer_type.h \ - include/isl/schedule.h include/isl/schedule_node.h \ - include/isl/schedule_type.h include/isl/set.h \ - include/isl/set_type.h include/isl/space.h \ - include/isl/stream.h include/isl/union_map.h \ +am__pkginclude_HEADERS_DIST = include/isl/cpp.h include/isl/val_gmp.h \ + include/isl/aff.h include/isl/aff_type.h include/isl/arg.h \ + include/isl/ast.h include/isl/ast_type.h \ + include/isl/ast_build.h include/isl/constraint.h \ + include/isl/ctx.h include/isl/fixed_box.h include/isl/flow.h \ + include/isl/id.h include/isl/id_type.h \ + include/isl/id_to_ast_expr.h include/isl/id_to_id.h \ + include/isl/id_to_pw_aff.h include/isl/ilp.h \ + include/isl/hash.h include/isl/hmap.h include/isl/hmap_templ.c \ + include/isl/list.h include/isl/local_space.h include/isl/lp.h \ + include/isl/mat.h include/isl/map.h \ + include/isl/map_to_basic_set.h include/isl/map_type.h \ + include/isl/maybe.h include/isl/maybe_ast_expr.h \ + include/isl/maybe_basic_set.h include/isl/maybe_id.h \ + include/isl/maybe_pw_aff.h include/isl/maybe_templ.h \ + include/isl/multi.h include/isl/obj.h include/isl/options.h \ + include/isl/point.h include/isl/polynomial.h \ + include/isl/polynomial_type.h include/isl/printer.h \ + include/isl/printer_type.h include/isl/schedule.h \ + include/isl/schedule_node.h include/isl/schedule_type.h \ + include/isl/set.h include/isl/set_type.h include/isl/space.h \ + include/isl/space_type.h include/isl/stream.h \ + include/isl/stride_info.h include/isl/union_map.h \ include/isl/union_map_type.h include/isl/union_set.h \ include/isl/union_set_type.h include/isl/val.h \ - include/isl/vec.h include/isl/version.h include/isl/vertices.h + include/isl/val_type.h include/isl/vec.h include/isl/version.h \ + include/isl/vertices.h HEADERS = $(nodist_pkginclude_HEADERS) $(pkginclude_HEADERS) RECURSIVE_CLEAN_TARGETS = mostlyclean-recursive clean-recursive \ distclean-recursive maintainer-clean-recursive @@ -624,7 +700,6 @@ bases=`echo $$bases` RECHECK_LOGS = $(TEST_LOGS) TEST_SUITE_LOG = test-suite.log -TEST_EXTENSIONS = @EXEEXT@ .test LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver LOG_COMPILE = $(LOG_COMPILER) $(AM_LOG_FLAGS) $(LOG_FLAGS) am__set_b = \ @@ -639,16 +714,15 @@ esac am__test_logs1 = $(TESTS:=.log) am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) -TEST_LOGS = $(am__test_logs2:.test.log=.log) -TEST_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver -TEST_LOG_COMPILE = $(TEST_LOG_COMPILER) $(AM_TEST_LOG_FLAGS) \ - $(TEST_LOG_FLAGS) +TEST_LOGS = $(am__test_logs2:.py.log=.log) +PY_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver +PY_LOG_COMPILE = $(PY_LOG_COMPILER) $(AM_PY_LOG_FLAGS) $(PY_LOG_FLAGS) am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/bound_test.sh.in \ $(srcdir)/codegen_test.sh.in $(srcdir)/flow_test.sh.in \ $(srcdir)/isl_config.h.in $(srcdir)/isl_srcdir.c.in \ $(srcdir)/pip_test.sh.in $(srcdir)/schedule_test.sh.in AUTHORS \ ChangeLog README compile config.guess config.sub depcomp \ - install-sh ltmain.sh missing test-driver + install-sh ltmain.sh missing py-compile test-driver DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -705,12 +779,14 @@ CLANG_CXXFLAGS = @CLANG_CXXFLAGS@ CLANG_LDFLAGS = @CLANG_LDFLAGS@ CLANG_LIBS = @CLANG_LIBS@ +CLANG_RFLAG = @CLANG_RFLAG@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ +CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ @@ -727,6 +803,7 @@ GIT_HEAD_ID = @GIT_HEAD_ID@ GIT_HEAD_VERSION = @GIT_HEAD_VERSION@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -745,6 +822,7 @@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MP_CFLAGS = @MP_CFLAGS@ MP_CPPFLAGS = @MP_CPPFLAGS@ MP_LDFLAGS = @MP_LDFLAGS@ MP_LIBS = @MP_LIBS@ @@ -752,6 +830,7 @@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_SRCDIR = @OS_SRCDIR@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ @@ -840,12 +919,21 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ versioninfo = @versioninfo@ -@HAVE_CLANG_TRUE@MAYBE_INTERFACE = interface +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@MAYBE_INTERFACE = interface SUBDIRS = . $(MAYBE_INTERFACE) doc DIST_SUBDIRS = $(MAYBE_INTERFACE) doc ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = nostdinc subdir-objects lib_LTLIBRARIES = libisl.la +@HAVE_CPP_ISL_H_TRUE@CPP_H = include/isl/cpp.h +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@@HAVE_PYTHON_TRUE@noinst_PYTHON = interface/isl.py +TEST_EXTENSIONS = .py +AM_TESTS_ENVIRONMENT = \ + export PYTHONPATH=interface; \ + export ISL_DYLD_LIBRARY_PATH=.libs; \ + export LD_LIBRARY_PATH=".libs:$(LD_LIBRARY_PATH)"; + +PY_LOG_COMPILER = $(PYTHON) @GMP_FOR_MP_TRUE@MP_SRC = \ @GMP_FOR_MP_TRUE@ $(GET_MEMORY_FUNCTIONS) \ @GMP_FOR_MP_TRUE@ isl_int_gmp.h \ @@ -856,16 +944,18 @@ @IMATH_FOR_MP_TRUE@ imath_wrap/gmp_compat.h imath_wrap/imath.h \ @IMATH_FOR_MP_TRUE@ imath_wrap/imrat.h imath_wrap/wrap.h \ @IMATH_FOR_MP_TRUE@ imath_wrap/gmp_compat.c imath_wrap/imath.c \ -@IMATH_FOR_MP_TRUE@ imath_wrap/imrat.c $(am__append_3) \ -@IMATH_FOR_MP_TRUE@ $(am__append_4) +@IMATH_FOR_MP_TRUE@ imath_wrap/imrat.c $(am__append_8) \ +@IMATH_FOR_MP_TRUE@ $(am__append_9) @GMP_FOR_MP_TRUE@MP_INCLUDE_H = include/isl/val_gmp.h @IMATH_FOR_MP_TRUE@MP_INCLUDE_H = @GMP_FOR_MP_TRUE@@NEED_GET_MEMORY_FUNCTIONS_TRUE@GET_MEMORY_FUNCTIONS = mp_get_memory_functions.c -AM_CPPFLAGS = -I. -I$(srcdir) -I$(srcdir)/include -Iinclude/ @MP_CPPFLAGS@ -AM_CFLAGS = @WARNING_FLAGS@ +includes = -I. -I$(srcdir) -I$(srcdir)/include -Iinclude/ +AM_CPPFLAGS = $(includes) @MP_CPPFLAGS@ +AM_CFLAGS = @WARNING_FLAGS@ @MP_CFLAGS@ libisl_la_SOURCES = \ $(MP_SRC) \ isl_aff.c \ + isl_aff_map.c \ isl_aff_private.h \ isl_affine_hull.c \ isl_arg.c \ @@ -886,6 +976,7 @@ isl_blk.h \ isl_bound.c \ isl_bound.h \ + isl_box.c \ isl_coalesce.c \ isl_constraint.c \ isl_constraint_private.h \ @@ -904,7 +995,6 @@ isl_flow.c \ isl_fold.c \ isl_hash.c \ - isl_hash_private.h \ isl_id_to_ast_expr.c \ isl_id_to_id.c \ isl_id_to_pw_aff.c \ @@ -912,6 +1002,7 @@ isl_ilp_private.h \ isl_input.c \ isl_int.h \ + isl_local_private.h \ isl_local.h \ isl_local.c \ isl_local_space_private.h \ @@ -971,6 +1062,8 @@ isl_stream_private.h \ isl_seq.c \ isl_seq.h \ + isl_set_to_ast_graft_list.c \ + isl_set_to_ast_graft_list.h \ isl_stride.c \ isl_tab.c \ isl_tab.h \ @@ -1060,10 +1153,34 @@ isl_closure_SOURCES = \ closure.c +isl_test_cpp_SOURCES = \ + isl_test_cpp.cc \ + include/isl/cpp.h + +isl_test_cpp_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_LDADD = libisl.la @MP_LIBS@ +isl_test_cpp_checked_SOURCES = \ + isl_test_cpp-checked.cc \ + include/isl/cpp-checked.h + +isl_test_cpp_checked_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_checked_LDADD = libisl.la @MP_LIBS@ +isl_test_cpp_checked_conversion_SOURCES = \ + isl_test_cpp-checked-conversion.cc \ + include/isl/cpp-checked-conversion.h + +isl_test_cpp_checked_conversion_LDFLAGS = @MP_LDFLAGS@ +isl_test_cpp_checked_conversion_LDADD = libisl.la @MP_LIBS@ + +# dummy library that captures the dependencies on all headers +# that are relevant for the bindings +noinst_LIBRARIES = libdep.a +libdep_a_SOURCES = dep.c nodist_pkginclude_HEADERS = \ include/isl/stdint.h pkginclude_HEADERS = \ + $(CPP_H) \ $(MP_INCLUDE_H) \ include/isl/aff.h \ include/isl/aff_type.h \ @@ -1073,8 +1190,10 @@ include/isl/ast_build.h \ include/isl/constraint.h \ include/isl/ctx.h \ + include/isl/fixed_box.h \ include/isl/flow.h \ include/isl/id.h \ + include/isl/id_type.h \ include/isl/id_to_ast_expr.h \ include/isl/id_to_id.h \ include/isl/id_to_pw_aff.h \ @@ -1109,19 +1228,31 @@ include/isl/set.h \ include/isl/set_type.h \ include/isl/space.h \ + include/isl/space_type.h \ include/isl/stream.h \ + include/isl/stride_info.h \ include/isl/union_map.h \ include/isl/union_map_type.h \ include/isl/union_set.h \ include/isl/union_set_type.h \ include/isl/val.h \ + include/isl/val_type.h \ include/isl/vec.h \ include/isl/version.h \ include/isl/vertices.h -BUILT_SOURCES = gitversion.h +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@CPP_INTERFACES = \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ include/isl/cpp.h \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ include/isl/cpp-checked.h \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ include/isl/cpp-checked-conversion.h + +BUILT_SOURCES = gitversion.h $(CPP_INTERFACES) CLEANFILES = \ - gitversion.h + gitversion.h \ + interface/isldlname.py \ + interface/isl.py \ + interface/isl.pyc \ + $(CPP_INTERFACES) DISTCLEANFILES = \ isl-uninstalled.sh \ @@ -1134,38 +1265,79 @@ LICENSE \ isl_config_post.h \ basis_reduction_templ.c \ + isl_bind_domain_templ.c \ bset_to_bmap.c \ bset_from_bmap.c \ + check_reparse_templ.c \ + check_reparse_test_templ.c \ + check_type_range_templ.c \ + isl_domain_factor_templ.c \ extract_key.c \ + has_single_reference_templ.c \ + isl_list_macro.h \ isl_list_templ.c \ isl_list_templ.h \ isl_map_lexopt_templ.c \ + isl_maybe_ast_graft_list.h \ isl_maybe_map.h \ isl_multi_macro.h \ + isl_multi_bind_templ.c \ + isl_multi_explicit_domain.c \ + isl_multi_pw_aff_explicit_domain.c \ + isl_multi_union_pw_aff_explicit_domain.c \ + isl_multi_no_explicit_domain.c \ + isl_multi_no_domain_templ.c \ isl_multi_templ.c \ isl_multi_templ.h \ + isl_multi_align_templ.c \ + isl_multi_align_set.c \ + isl_multi_align_union_set.c \ isl_multi_apply_templ.c \ isl_multi_apply_set.c \ isl_multi_apply_union_set.c \ + isl_multi_arith_templ.c \ + isl_multi_bind_domain_templ.c \ isl_multi_cmp.c \ isl_multi_coalesce.c \ + isl_multi_dim_id_templ.c \ isl_multi_dims.c \ + isl_multi_domain_templ.c \ isl_multi_floor.c \ + isl_multi_from_base_templ.c \ isl_multi_gist.c \ isl_multi_hash.c \ isl_multi_intersect.c \ + isl_multi_identity_templ.c \ + isl_multi_locals_templ.c \ + isl_multi_move_dims_templ.c \ + isl_multi_nan_templ.c \ + isl_multi_param_templ.c \ + isl_multi_product_templ.c \ + isl_multi_read_no_explicit_domain_templ.c \ + isl_multi_splice_templ.c \ + isl_multi_tuple_id_templ.c \ + isl_multi_zero_templ.c \ + opt_type.h \ print_templ.c \ print_templ_yaml.c \ + print_yaml_field_templ.c \ isl_power_templ.c \ + isl_project_out_all_params_templ.c \ isl_pw_macro.h \ isl_pw_templ.c \ + isl_pw_templ.h \ + isl_pw_bind_domain_templ.c \ + isl_pw_eval.c \ isl_pw_hash.c \ isl_pw_union_opt.c \ read_in_string_templ.c \ set_to_map.c \ set_from_map.c \ + set_list_from_map_list_inl.c \ isl_tab_lexopt_templ.c \ + isl_test_list_templ.c \ uset_to_umap.c \ + uset_from_umap.c \ isl_union_macro.h \ isl_union_templ.c \ isl_union_single.c \ @@ -1187,9 +1359,11 @@ imath/imath.h \ imath/imrat.c \ imath/imrat.h \ - interface/all.h \ - interface/isl.py.top \ - interface/isl_test_python.py \ + all.h \ + cpp \ + python \ + isl_test_cpp-generic.cc \ + isl_test_python.py \ test_inputs pkgconfigdir = $(pkgconfig_libdir) @@ -1198,7 +1372,7 @@ $(MAKE) $(AM_MAKEFLAGS) all-recursive .SUFFIXES: -.SUFFIXES: .c .lo .log .o .obj .test .test$(EXEEXT) .trs +.SUFFIXES: .c .cc .lo .log .o .obj .py .py$(EXEEXT) .trs am--refresh: Makefile @: $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @@ -1259,6 +1433,14 @@ cd $(top_builddir) && $(SHELL) ./config.status $@ schedule_test.sh: $(top_builddir)/config.status $(srcdir)/schedule_test.sh.in cd $(top_builddir) && $(SHELL) ./config.status $@ + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +libdep.a: $(libdep_a_OBJECTS) $(libdep_a_DEPENDENCIES) $(EXTRA_libdep_a_DEPENDENCIES) + $(AM_V_at)-rm -f libdep.a + $(AM_V_AR)$(libdep_a_AR) libdep.a $(libdep_a_OBJECTS) $(libdep_a_LIBADD) + $(AM_V_at)$(RANLIB) libdep.a install-libLTLIBRARIES: $(lib_LTLIBRARIES) @$(NORMAL_INSTALL) @@ -1374,6 +1556,18 @@ isl_test$(EXEEXT): $(isl_test_OBJECTS) $(isl_test_DEPENDENCIES) $(EXTRA_isl_test_DEPENDENCIES) @rm -f isl_test$(EXEEXT) $(AM_V_CCLD)$(isl_test_LINK) $(isl_test_OBJECTS) $(isl_test_LDADD) $(LIBS) + +isl_test_cpp$(EXEEXT): $(isl_test_cpp_OBJECTS) $(isl_test_cpp_DEPENDENCIES) $(EXTRA_isl_test_cpp_DEPENDENCIES) + @rm -f isl_test_cpp$(EXEEXT) + $(AM_V_CXXLD)$(isl_test_cpp_LINK) $(isl_test_cpp_OBJECTS) $(isl_test_cpp_LDADD) $(LIBS) + +isl_test_cpp-checked$(EXEEXT): $(isl_test_cpp_checked_OBJECTS) $(isl_test_cpp_checked_DEPENDENCIES) $(EXTRA_isl_test_cpp_checked_DEPENDENCIES) + @rm -f isl_test_cpp-checked$(EXEEXT) + $(AM_V_CXXLD)$(isl_test_cpp_checked_LINK) $(isl_test_cpp_checked_OBJECTS) $(isl_test_cpp_checked_LDADD) $(LIBS) + +isl_test_cpp-checked-conversion$(EXEEXT): $(isl_test_cpp_checked_conversion_OBJECTS) $(isl_test_cpp_checked_conversion_DEPENDENCIES) $(EXTRA_isl_test_cpp_checked_conversion_DEPENDENCIES) + @rm -f isl_test_cpp-checked-conversion$(EXEEXT) + $(AM_V_CXXLD)$(isl_test_cpp_checked_conversion_LINK) $(isl_test_cpp_checked_conversion_OBJECTS) $(isl_test_cpp_checked_conversion_LDADD) $(LIBS) isl_test_imath$(EXEEXT): $(isl_test_imath_OBJECTS) $(isl_test_imath_DEPENDENCIES) $(EXTRA_isl_test_imath_DEPENDENCIES) @rm -f isl_test_imath$(EXEEXT) @@ -1396,9 +1590,11 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/closure.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codegen.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dep.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flow.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/flow_cmp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_aff.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_aff_map.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_affine_hull.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_arg.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_ast.Plo@am__quote@ @@ -1409,6 +1605,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_bernstein.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_blk.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_bound.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_box.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_coalesce.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_constraint.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_convex_hull.Plo@am__quote@ @@ -1460,6 +1657,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_scheduler.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_seq.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_set_list.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_set_to_ast_graft_list.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_sort.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_space.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_stream.Plo@am__quote@ @@ -1468,6 +1666,9 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_tab_pip.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_tarjan.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test_cpp-checked-conversion.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test_cpp-checked.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test_cpp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test_imath.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_test_int.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/isl_transitive_closure.Plo@am__quote@ @@ -1516,6 +1717,30 @@ @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< +.cc.o: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ $< + +.cc.obj: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ +@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ +@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.cc.lo: +@am__fastdepCXX_TRUE@ $(AM_V_CXX)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ +@am__fastdepCXX_TRUE@ $(LTCXXCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ +@am__fastdepCXX_TRUE@ $(am__mv) $$depbase.Tpo $$depbase.Plo +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(LTCXXCOMPILE) -c -o $@ $< + mostlyclean-libtool: -rm -f *.lo @@ -1881,6 +2106,27 @@ schedule_test.sh.log: schedule_test.sh @p='schedule_test.sh'; \ b='schedule_test.sh'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +isl_test_cpp.log: isl_test_cpp$(EXEEXT) + @p='isl_test_cpp$(EXEEXT)'; \ + b='isl_test_cpp'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +isl_test_cpp-checked.log: isl_test_cpp-checked$(EXEEXT) + @p='isl_test_cpp-checked$(EXEEXT)'; \ + b='isl_test_cpp-checked'; \ + $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ + --log-file $$b.log --trs-file $$b.trs \ + $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ + "$$tst" $(AM_TESTS_FD_REDIRECT) +isl_test_cpp-checked-conversion.log: isl_test_cpp-checked-conversion$(EXEEXT) + @p='isl_test_cpp-checked-conversion$(EXEEXT)'; \ + b='isl_test_cpp-checked-conversion'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1892,19 +2138,19 @@ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -.test.log: +.py.log: @p='$<'; \ $(am__set_b); \ - $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ + $(am__check_pre) $(PY_LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ + $(am__common_driver_flags) $(AM_PY_LOG_DRIVER_FLAGS) $(PY_LOG_DRIVER_FLAGS) -- $(PY_LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -@am__EXEEXT_TRUE@.test$(EXEEXT).log: +@am__EXEEXT_TRUE@.py$(EXEEXT).log: @am__EXEEXT_TRUE@ @p='$<'; \ @am__EXEEXT_TRUE@ $(am__set_b); \ -@am__EXEEXT_TRUE@ $(am__check_pre) $(TEST_LOG_DRIVER) --test-name "$$f" \ +@am__EXEEXT_TRUE@ $(am__check_pre) $(PY_LOG_DRIVER) --test-name "$$f" \ @am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ -@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_TEST_LOG_DRIVER_FLAGS) $(TEST_LOG_DRIVER_FLAGS) -- $(TEST_LOG_COMPILE) \ +@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_PY_LOG_DRIVER_FLAGS) $(PY_LOG_DRIVER_FLAGS) -- $(PY_LOG_COMPILE) \ @am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) distdir: $(DISTFILES) @@ -1975,7 +2221,7 @@ ! -type d ! -perm -444 -exec $(install_sh) -c -m a+r {} {} \; \ || chmod -R a+r "$(distdir)" dist-gzip: distdir - tardir=$(distdir) && $(am__tar) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).tar.gz + tardir=$(distdir) && $(am__tar) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).tar.gz $(am__post_remove_distdir) dist-bzip2: distdir @@ -2001,7 +2247,7 @@ @echo WARNING: "Support for shar distribution archives is" \ "deprecated." >&2 @echo WARNING: "It will be removed altogether in Automake 2.0" >&2 - shar $(distdir) | GZIP=$(GZIP_ENV) gzip -c >$(distdir).shar.gz + shar $(distdir) | eval GZIP= gzip $(GZIP_ENV) -c >$(distdir).shar.gz $(am__post_remove_distdir) dist-zip: distdir @@ -2019,7 +2265,7 @@ distcheck: dist case '$(DIST_ARCHIVES)' in \ *.tar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).tar.gz | $(am__untar) ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).tar.gz | $(am__untar) ;;\ *.tar.bz2*) \ bzip2 -dc $(distdir).tar.bz2 | $(am__untar) ;;\ *.tar.lz*) \ @@ -2029,7 +2275,7 @@ *.tar.Z*) \ uncompress -c $(distdir).tar.Z | $(am__untar) ;;\ *.shar.gz*) \ - GZIP=$(GZIP_ENV) gzip -dc $(distdir).shar.gz | unshar ;;\ + eval GZIP= gzip $(GZIP_ENV) -dc $(distdir).shar.gz | unshar ;;\ *.zip*) \ unzip $(distdir).zip ;;\ esac @@ -2102,8 +2348,8 @@ $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: $(BUILT_SOURCES) $(MAKE) $(AM_MAKEFLAGS) check-recursive -all-am: Makefile $(LTLIBRARIES) $(PROGRAMS) $(DATA) $(HEADERS) \ - isl_config.h +all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) $(PROGRAMS) $(DATA) \ + $(HEADERS) isl_config.h installdirs: installdirs-recursive installdirs-am: for dir in "$(DESTDIR)$(libdir)" "$(DESTDIR)$(pkgconfigdir)" "$(DESTDIR)$(pkgincludedir)" "$(DESTDIR)$(pkgincludedir)"; do \ @@ -2151,7 +2397,7 @@ clean: clean-recursive clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \ - clean-noinstPROGRAMS mostlyclean-am + clean-noinstLIBRARIES clean-noinstPROGRAMS mostlyclean-am distclean: distclean-recursive -rm -f $(am__CONFIG_DISTCLEAN_FILES) @@ -2231,16 +2477,17 @@ .PHONY: $(am__recursive_targets) CTAGS GTAGS TAGS all all-am \ am--refresh check check-TESTS check-am clean clean-cscope \ clean-generic clean-libLTLIBRARIES clean-libtool \ - clean-noinstPROGRAMS cscope cscopelist-am ctags ctags-am dist \ - dist-all dist-bzip2 dist-gzip dist-hook dist-lzip dist-shar \ - dist-tarZ dist-xz dist-zip distcheck distclean \ - distclean-compile distclean-generic distclean-hdr \ - distclean-libtool distclean-tags distcleancheck distdir \ - distuninstallcheck dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am \ - install-data-local install-dvi install-dvi-am install-exec \ - install-exec-am install-html install-html-am install-info \ - install-info-am install-libLTLIBRARIES install-man \ + clean-noinstLIBRARIES clean-noinstPROGRAMS cscope \ + cscopelist-am ctags ctags-am dist dist-all dist-bzip2 \ + dist-gzip dist-hook dist-lzip dist-shar dist-tarZ dist-xz \ + dist-zip distcheck distclean distclean-compile \ + distclean-generic distclean-hdr distclean-libtool \ + distclean-tags distcleancheck distdir distuninstallcheck dvi \ + dvi-am html html-am info info-am install install-am \ + install-data install-data-am install-data-local install-dvi \ + install-dvi-am install-exec install-exec-am install-html \ + install-html-am install-info install-info-am \ + install-libLTLIBRARIES install-man \ install-nodist_pkgincludeHEADERS install-pdf install-pdf-am \ install-pkgconfigDATA install-pkgincludeHEADERS install-ps \ install-ps-am install-strip installcheck installcheck-am \ @@ -2254,6 +2501,50 @@ .PRECIOUS: Makefile +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@FORCE: +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@interface/extract_interface: FORCE +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(MAKE) $(AM_MAKEFLAGS) -C interface extract_interface +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@@HAVE_PYTHON_TRUE@ isl_test_python.py: interface/isl.py libisl.la + +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@interface/isldlname.py: libisl.la +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(AM_V_GEN) $(GREP) dlname $< | $(SED) -e 's/dlname/isl_dlname/' > $@ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@interface/isl.py: interface/extract_interface libdep.a python/isl.py.top \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ interface/isldlname.py +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ (cat interface/isldlname.py $(srcdir)/python/isl.py.top && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ interface/extract_interface$(EXEEXT) --language=python \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(includes) $(srcdir)/all.h) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ > $@ || (rm $@ && false) + +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@include/isl/cpp.h: interface/extract_interface libdep.a \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cpp/cpp.h.top cpp/cpp.h.pre cpp/cpp.h.bot +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(MKDIR_P) "include/isl/cpp" && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ (cat $(srcdir)/cpp/cpp.h.top $(srcdir)/all.h \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(srcdir)/cpp/cpp.h.pre && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ interface/extract_interface$(EXEEXT) --language=cpp \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(includes) $(srcdir)/all.h && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cat $(srcdir)/cpp/cpp.h.bot) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ > $@ || (rm $@ && false) + +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@include/isl/cpp-checked.h: interface/extract_interface libdep.a \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cpp/cpp-checked.h.top \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cpp/cpp-checked.h.pre cpp/cpp-checked.h.bot +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ (cat $(srcdir)/cpp/cpp-checked.h.top $(srcdir)/all.h \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(srcdir)/cpp/cpp-checked.h.pre && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ interface/extract_interface$(EXEEXT) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ --language=cpp-checked \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(includes) $(srcdir)/all.h && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cat $(srcdir)/cpp/cpp-checked.h.bot) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ > $@ || (rm $@ && false) + +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@include/isl/cpp-checked-conversion.h: interface/extract_interface libdep.a \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cpp/cpp-checked-conversion.h.top \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cpp/cpp-checked-conversion.h.bot +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ (cat $(srcdir)/cpp/cpp-checked-conversion.h.top && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ interface/extract_interface$(EXEEXT) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ --language=cpp-checked-conversion \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ $(includes) $(srcdir)/all.h && \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ cat $(srcdir)/cpp/cpp-checked-conversion.h.bot) \ +@HAVE_CLANG_TRUE@@HAVE_CXX11_TRUE@ > $@ || (rm $@ && false) dist-hook: echo @GIT_HEAD_VERSION@ > $(distdir)/GIT_HEAD_ID diff --git a/gcc/isl/README b/gcc/isl/README index 9f48a0a..e7a5f7d 100644 --- a/gcc/isl/README +++ a/gcc/isl/README @@ -21,10 +21,10 @@ For more information, see doc/user.pod or the generated documentation. -New releases are announced on http://freecode.com/projects/isl +New releases are announced on http://groups.google.com/group/isl-announce If you use isl, you can let me know by stacking -https://www.ohloh.net/p/isl on ohloh. +https://www.openhub.net/p/isl on Open Hub. For bug reports, feature requests and questions, contact http://groups.google.com/group/isl-development diff --git a/gcc/isl/aclocal.m4 b/gcc/isl/aclocal.m4 index b25d553..2a7bc35 100644 --- a/gcc/isl/aclocal.m4 +++ a/gcc/isl/aclocal.m4 @@ -1,6 +1,6 @@ -# generated automatically by aclocal 1.15 -*- Autoconf -*- +# generated automatically by aclocal 1.15.1 -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -20,7 +20,7 @@ If you have problems, you may need to regenerate the build system entirely. To do so, use the procedure documented by the package, typically 'autoreconf'.])]) -# Copyright (C) 2002-2014 Free Software Foundation, Inc. +# Copyright (C) 2002-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -35,7 +35,7 @@ [am__api_version='1.15' dnl Some users find AM_AUTOMAKE_VERSION and mistake it for a way to dnl require some minimum version. Point them to the right macro. -m4_if([$1], [1.15], [], +m4_if([$1], [1.15.1], [], [AC_FATAL([Do not call $0, use AM_INIT_AUTOMAKE([$1]).])])dnl ]) @@ -51,14 +51,14 @@ # Call AM_AUTOMAKE_VERSION and AM_AUTOMAKE_VERSION so they can be traced. # This function is AC_REQUIREd by AM_INIT_AUTOMAKE. AC_DEFUN([AM_SET_CURRENT_AUTOMAKE_VERSION], -[AM_AUTOMAKE_VERSION([1.15])dnl +[AM_AUTOMAKE_VERSION([1.15.1])dnl m4_ifndef([AC_AUTOCONF_VERSION], [m4_copy([m4_PACKAGE_VERSION], [AC_AUTOCONF_VERSION])])dnl _AM_AUTOCONF_VERSION(m4_defn([AC_AUTOCONF_VERSION]))]) # AM_AUX_DIR_EXPAND -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -110,7 +110,7 @@ # AM_CONDITIONAL -*- Autoconf -*- -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -141,7 +141,7 @@ Usually this means the macro was only invoked conditionally.]]) fi])]) -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -332,7 +332,7 @@ # Generate code to set up dependency tracking. -*- Autoconf -*- -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -408,7 +408,7 @@ # Do all the work for Automake. -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -605,7 +605,7 @@ done echo "timestamp for $_am_arg" >`AS_DIRNAME(["$_am_arg"])`/stamp-h[]$_am_stamp_count]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -626,7 +626,7 @@ fi AC_SUBST([install_sh])]) -# Copyright (C) 2003-2014 Free Software Foundation, Inc. +# Copyright (C) 2003-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -647,7 +647,7 @@ # Check to see how 'make' treats includes. -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -697,7 +697,7 @@ # Fake the existence of programs that GNU maintainers use. -*- Autoconf -*- -# Copyright (C) 1997-2014 Free Software Foundation, Inc. +# Copyright (C) 1997-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -736,7 +736,7 @@ # Helper functions for option handling. -*- Autoconf -*- -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -765,7 +765,7 @@ AC_DEFUN([_AM_IF_OPTION], [m4_ifset(_AM_MANGLE_OPTION([$1]), [$2], [$3])]) -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -812,7 +812,7 @@ # For backward compatibility. AC_DEFUN_ONCE([AM_PROG_CC_C_O], [AC_REQUIRE([AC_PROG_CC])]) -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -845,8 +845,9 @@ [ dnl Find a Python interpreter. Python versions prior to 2.0 are not dnl supported. (2.0 was released on October 16, 2000). + dnl FIXME: Remove the need to hard-code Python versions here. m4_define_default([_AM_PYTHON_INTERPRETER_LIST], -[python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 dnl +[python python2 python3 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python2.7 dnl python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0]) AC_ARG_VAR([PYTHON], [the Python interpreter]) @@ -1047,7 +1048,7 @@ sys.exit(sys.hexversion < minverhex)" AS_IF([AM_RUN_LOG([$1 -c "$prog"])], [$3], [$4])]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1066,7 +1067,7 @@ # Check to make sure that the build environment is sane. -*- Autoconf -*- -# Copyright (C) 1996-2014 Free Software Foundation, Inc. +# Copyright (C) 1996-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1147,7 +1148,7 @@ rm -f conftest.file ]) -# Copyright (C) 2009-2014 Free Software Foundation, Inc. +# Copyright (C) 2009-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1207,7 +1208,7 @@ _AM_SUBST_NOTMAKE([AM_BACKSLASH])dnl ]) -# Copyright (C) 2001-2014 Free Software Foundation, Inc. +# Copyright (C) 2001-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1235,7 +1236,7 @@ INSTALL_STRIP_PROGRAM="\$(install_sh) -c -s" AC_SUBST([INSTALL_STRIP_PROGRAM])]) -# Copyright (C) 2006-2014 Free Software Foundation, Inc. +# Copyright (C) 2006-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1254,7 +1255,7 @@ # Check how to create a tarball. -*- Autoconf -*- -# Copyright (C) 2004-2014 Free Software Foundation, Inc. +# Copyright (C) 2004-2017 Free Software Foundation, Inc. # # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -1391,6 +1392,8 @@ m4_include([m4/ax_compiler_vendor.m4]) m4_include([m4/ax_create_pkgconfig_info.m4]) m4_include([m4/ax_create_stdint_h.m4]) +m4_include([m4/ax_cxx_compile_stdcxx.m4]) +m4_include([m4/ax_cxx_compile_stdcxx_11.m4]) m4_include([m4/ax_detect_clang.m4]) m4_include([m4/ax_detect_git_head.m4]) m4_include([m4/ax_detect_gmp.m4]) diff --git a/gcc/isl/basis_reduction_templ.c b/gcc/isl/basis_reduction_templ.c index a5da1e6..5c03eab 100644 --- a/gcc/isl/basis_reduction_templ.c +++ a/gcc/isl/basis_reduction_templ.c @@ -319,16 +319,10 @@ struct isl_mat *basis; struct isl_tab *tab; - if (!bset) + if (isl_basic_set_check_no_locals(bset) < 0 || + isl_basic_set_check_no_params(bset) < 0) return NULL; - if (isl_basic_set_dim(bset, isl_dim_div) != 0) - isl_die(bset->ctx, isl_error_invalid, - "no integer division allowed", return NULL); - if (isl_basic_set_dim(bset, isl_dim_param) != 0) - isl_die(bset->ctx, isl_error_invalid, - "no parameters allowed", return NULL); - tab = isl_tab_from_basic_set(bset, 0); if (!tab) return NULL; @@ -337,7 +331,9 @@ tab->basis = isl_mat_identity(bset->ctx, 1 + tab->n_var); else { isl_mat *eq; - unsigned nvar = isl_basic_set_total_dim(bset); + isl_size nvar = isl_basic_set_dim(bset, isl_dim_all); + if (nvar < 0) + goto error; eq = isl_mat_sub_alloc6(bset->ctx, bset->eq, 0, bset->n_eq, 1, nvar); eq = isl_mat_left_hermite(eq, 0, NULL, &tab->basis); @@ -354,4 +350,7 @@ isl_tab_free(tab); return basis; +error: + isl_tab_free(tab); + return NULL; } diff --git a/gcc/isl/bound.c b/gcc/isl/bound.c index cfb2b61..ec79b3b 100644 --- a/gcc/isl/bound.c +++ a/gcc/isl/bound.c @@ -25,12 +25,14 @@ static __isl_give isl_set *set_bounds(__isl_take isl_set *set) { - unsigned nparam; + isl_size nparam; int i, r; isl_point *pt, *pt2; isl_set *box; nparam = isl_set_dim(set, isl_dim_param); + if (nparam < 0) + return isl_set_free(set); r = nparam >= 8 ? 5 : nparam >= 5 ? 15 : 50; pt = isl_set_sample_point(isl_set_copy(set)); @@ -60,7 +62,7 @@ static isl_stat verify_point(__isl_take isl_point *pnt, void *user) { int i; - unsigned nparam; + isl_size nparam; struct verify_point_bound *vpb = (struct verify_point_bound *) user; isl_val *v; isl_ctx *ctx; @@ -91,6 +93,8 @@ pwf = isl_pw_qpolynomial_fold_copy(vpb->pwf); nparam = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_param); + if (nparam < 0) + pwf = isl_pw_qpolynomial_fold_free(pwf); for (i = 0; i < nparam; ++i) { v = isl_point_get_coordinate_val(pnt, isl_dim_param, i); pwf = isl_pw_qpolynomial_fold_fix_val(pwf, isl_dim_param, i, v); @@ -239,7 +243,7 @@ isl_stream *s; struct isl_obj obj; struct bound_options *options; - int exact; + isl_bool exact; int r = 0; options = bound_options_new_with_defaults(); diff --git a/gcc/isl/cat.c b/gcc/isl/cat.c index 4f87133..c483383 100644 --- a/gcc/isl/cat.c +++ a/gcc/isl/cat.c @@ -10,6 +10,7 @@ {"polylib", ISL_FORMAT_POLYLIB}, {"ext-polylib", ISL_FORMAT_EXT_POLYLIB}, {"latex", ISL_FORMAT_LATEX}, + {"C", ISL_FORMAT_C}, {0} }; diff --git a/gcc/isl/closure.c b/gcc/isl/closure.c index c76fb29..22235b0 100644 --- a/gcc/isl/closure.c +++ a/gcc/isl/closure.c @@ -8,7 +8,7 @@ struct isl_map *map; struct isl_options *options; isl_printer *p; - int exact; + isl_bool exact; options = isl_options_new_with_defaults(); assert(options); diff --git a/gcc/isl/codegen.c b/gcc/isl/codegen.c index af2e18c..38dab49 100644 --- a/gcc/isl/codegen.c +++ a/gcc/isl/codegen.c @@ -142,12 +142,15 @@ __isl_take isl_schedule_node *node, void *user) { enum isl_ast_loop_type *type = user; - int i, n; + int i; + isl_size n; if (isl_schedule_node_get_type(node) != isl_schedule_node_band) return node; n = isl_schedule_node_band_n_member(node); + if (n < 0) + return isl_schedule_node_free(node); for (i = 0; i < n; ++i) node = isl_schedule_node_band_member_set_ast_loop_type(node, i, *type); diff --git a/gcc/isl/config.guess b/gcc/isl/config.guess index 2e9ad7f..1f5c50c 100755 --- a/gcc/isl/config.guess +++ a/gcc/isl/config.guess @@ -1,8 +1,8 @@ #! /bin/sh # Attempt to guess a canonical system name. -# Copyright 1992-2016 Free Software Foundation, Inc. +# Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2016-10-02' +timestamp='2014-03-23' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -24,12 +24,12 @@ # program. This Exception is an additional permission under section 7 # of the GNU General Public License, version 3 ("GPLv3"). # -# Originally written by Per Bothner; maintained since 2000 by Ben Elliston. +# Originally written by Per Bothner. # # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD # -# Please send patches to . +# Please send patches with a ChangeLog entry to config-patches@gnu.org. me=`echo "$0" | sed -e 's,.*/,,'` @@ -50,7 +50,7 @@ GNU config.guess ($timestamp) Originally written by Per Bothner. -Copyright 1992-2016 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -168,29 +168,19 @@ # Note: NetBSD doesn't particularly care about the vendor # portion of the name. We always set it to "unknown". sysctl="sysctl -n hw.machine_arch" - UNAME_MACHINE_ARCH=`(uname -p 2>/dev/null || \ - /sbin/$sysctl 2>/dev/null || \ - /usr/sbin/$sysctl 2>/dev/null || \ - echo unknown)` + UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ + /usr/sbin/$sysctl 2>/dev/null || echo unknown)` case "${UNAME_MACHINE_ARCH}" in armeb) machine=armeb-unknown ;; arm*) machine=arm-unknown ;; sh3el) machine=shl-unknown ;; sh3eb) machine=sh-unknown ;; sh5el) machine=sh5le-unknown ;; - earmv*) - arch=`echo ${UNAME_MACHINE_ARCH} | sed -e 's,^e\(armv[0-9]\).*$,\1,'` - endian=`echo ${UNAME_MACHINE_ARCH} | sed -ne 's,^.*\(eb\)$,\1,p'` - machine=${arch}${endian}-unknown - ;; *) machine=${UNAME_MACHINE_ARCH}-unknown ;; esac # The Operating System including object format, if it has switched - # to ELF recently (or will in the future) and ABI. + # to ELF recently, or will in the future. case "${UNAME_MACHINE_ARCH}" in - earm*) - os=netbsdelf - ;; arm*|i386|m68k|ns32k|sh3*|sparc|vax) eval $set_cc_for_build if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ @@ -205,13 +195,6 @@ ;; *) os=netbsd - ;; - esac - # Determine ABI tags. - case "${UNAME_MACHINE_ARCH}" in - earm*) - expr='s/^earmv[0-9]/-eabi/;s/eb$//' - abi=`echo ${UNAME_MACHINE_ARCH} | sed -e "$expr"` ;; esac # The OS release @@ -224,13 +207,13 @@ release='-gnu' ;; *) - release=`echo ${UNAME_RELEASE} | sed -e 's/[-_].*//' | cut -d. -f1,2` + release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` ;; esac # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: # contains redundant information, the shorter form: # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. - echo "${machine}-${os}${release}${abi}" + echo "${machine}-${os}${release}" exit ;; *:Bitrig:*:*) UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'` @@ -240,10 +223,6 @@ UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'` echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE} exit ;; - *:LibertyBSD:*:*) - UNAME_MACHINE_ARCH=`arch | sed 's/^.*BSD\.//'` - echo ${UNAME_MACHINE_ARCH}-unknown-libertybsd${UNAME_RELEASE} - exit ;; *:ekkoBSD:*:*) echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE} exit ;; @@ -255,9 +234,6 @@ exit ;; *:MirBSD:*:*) echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE} - exit ;; - *:Sortix:*:*) - echo ${UNAME_MACHINE}-unknown-sortix exit ;; alpha:OSF1:*:*) case $UNAME_RELEASE in @@ -275,42 +251,42 @@ ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1` case "$ALPHA_CPU_TYPE" in "EV4 (21064)") - UNAME_MACHINE=alpha ;; + UNAME_MACHINE="alpha" ;; "EV4.5 (21064)") - UNAME_MACHINE=alpha ;; + UNAME_MACHINE="alpha" ;; "LCA4 (21066/21068)") - UNAME_MACHINE=alpha ;; + UNAME_MACHINE="alpha" ;; "EV5 (21164)") - UNAME_MACHINE=alphaev5 ;; + UNAME_MACHINE="alphaev5" ;; "EV5.6 (21164A)") - UNAME_MACHINE=alphaev56 ;; + UNAME_MACHINE="alphaev56" ;; "EV5.6 (21164PC)") - UNAME_MACHINE=alphapca56 ;; + UNAME_MACHINE="alphapca56" ;; "EV5.7 (21164PC)") - UNAME_MACHINE=alphapca57 ;; + UNAME_MACHINE="alphapca57" ;; "EV6 (21264)") - UNAME_MACHINE=alphaev6 ;; + UNAME_MACHINE="alphaev6" ;; "EV6.7 (21264A)") - UNAME_MACHINE=alphaev67 ;; + UNAME_MACHINE="alphaev67" ;; "EV6.8CB (21264C)") - UNAME_MACHINE=alphaev68 ;; + UNAME_MACHINE="alphaev68" ;; "EV6.8AL (21264B)") - UNAME_MACHINE=alphaev68 ;; + UNAME_MACHINE="alphaev68" ;; "EV6.8CX (21264D)") - UNAME_MACHINE=alphaev68 ;; + UNAME_MACHINE="alphaev68" ;; "EV6.9A (21264/EV69A)") - UNAME_MACHINE=alphaev69 ;; + UNAME_MACHINE="alphaev69" ;; "EV7 (21364)") - UNAME_MACHINE=alphaev7 ;; + UNAME_MACHINE="alphaev7" ;; "EV7.9 (21364A)") - UNAME_MACHINE=alphaev79 ;; + UNAME_MACHINE="alphaev79" ;; esac # A Pn.n version is a patched version. # A Vn.n version is a released version. # A Tn.n version is a released field test version. # A Xn.n version is an unreleased experimental baselevel. # 1.2 uses "1.2" for uname -r. - echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` + echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` # Reset EXIT trap before exiting to avoid spurious non-zero exit code. exitcode=$? trap '' 0 @@ -383,16 +359,16 @@ exit ;; i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*) eval $set_cc_for_build - SUN_ARCH=i386 + SUN_ARCH="i386" # If there is a compiler, see if it is configured for 64-bit objects. # Note that the Sun cc does not turn __LP64__ into 1 like gcc does. # This test works for both compilers. - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then - SUN_ARCH=x86_64 + SUN_ARCH="x86_64" fi fi echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` @@ -417,7 +393,7 @@ exit ;; sun*:*:4.2BSD:*) UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` - test "x${UNAME_RELEASE}" = x && UNAME_RELEASE=3 + test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 case "`/bin/arch`" in sun3) echo m68k-sun-sunos${UNAME_RELEASE} @@ -603,9 +579,8 @@ else IBM_ARCH=powerpc fi - if [ -x /usr/bin/lslpp ] ; then - IBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc | - awk -F: '{ print $3 }' | sed s/[0-9]*$/0/` + if [ -x /usr/bin/oslevel ] ; then + IBM_REV=`/usr/bin/oslevel` else IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} fi @@ -642,13 +617,13 @@ sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` case "${sc_cpu_version}" in - 523) HP_ARCH=hppa1.0 ;; # CPU_PA_RISC1_0 - 528) HP_ARCH=hppa1.1 ;; # CPU_PA_RISC1_1 + 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 + 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 532) # CPU_PA_RISC2_0 case "${sc_kernel_bits}" in - 32) HP_ARCH=hppa2.0n ;; - 64) HP_ARCH=hppa2.0w ;; - '') HP_ARCH=hppa2.0 ;; # HP-UX 10.20 + 32) HP_ARCH="hppa2.0n" ;; + 64) HP_ARCH="hppa2.0w" ;; + '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 esac ;; esac fi @@ -687,11 +662,11 @@ exit (0); } EOF - (CCOPTS="" $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` + (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` test -z "$HP_ARCH" && HP_ARCH=hppa fi ;; esac - if [ ${HP_ARCH} = hppa2.0w ] + if [ ${HP_ARCH} = "hppa2.0w" ] then eval $set_cc_for_build @@ -704,12 +679,12 @@ # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess # => hppa64-hp-hpux11.23 - if echo __LP64__ | (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | + if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | grep -q __LP64__ then - HP_ARCH=hppa2.0w + HP_ARCH="hppa2.0w" else - HP_ARCH=hppa64 + HP_ARCH="hppa64" fi fi echo ${HP_ARCH}-hp-hpux${HPUX_REV} @@ -814,14 +789,14 @@ echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' exit ;; F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) - FUJITSU_PROC=`uname -m | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz` - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` + FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; 5000:UNIX_System_V:4.*:*) - FUJITSU_SYS=`uname -p | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/\///'` - FUJITSU_REL=`echo ${UNAME_RELEASE} | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz | sed -e 's/ /_/'` + FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` + FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'` echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" exit ;; i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) @@ -903,7 +878,7 @@ exit ;; *:GNU/*:*:*) # other systems with GNU libc and userland - echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr "[:upper:]" "[:lower:]"``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} + echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC} exit ;; i*86:Minix:*:*) echo ${UNAME_MACHINE}-pc-minix @@ -926,7 +901,7 @@ EV68*) UNAME_MACHINE=alphaev68 ;; esac objdump --private-headers /bin/sh | grep -q ld.so.1 - if test "$?" = 0 ; then LIBC=gnulibc1 ; fi + if test "$?" = 0 ; then LIBC="gnulibc1" ; fi echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; arc:Linux:*:* | arceb:Linux:*:*) @@ -956,9 +931,6 @@ exit ;; crisv32:Linux:*:*) echo ${UNAME_MACHINE}-axis-linux-${LIBC} - exit ;; - e2k:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; frv:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} @@ -970,9 +942,6 @@ echo ${UNAME_MACHINE}-pc-linux-${LIBC} exit ;; ia64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; - k1om:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; m32r*:Linux:*:*) @@ -1000,9 +969,6 @@ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'` test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; } ;; - mips64el:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; openrisc*:Linux:*:*) echo or1k-unknown-linux-${LIBC} exit ;; @@ -1035,9 +1001,6 @@ ppcle:Linux:*:*) echo powerpcle-unknown-linux-${LIBC} exit ;; - riscv32:Linux:*:* | riscv64:Linux:*:*) - echo ${UNAME_MACHINE}-unknown-linux-${LIBC} - exit ;; s390:Linux:*:* | s390x:Linux:*:*) echo ${UNAME_MACHINE}-ibm-linux-${LIBC} exit ;; @@ -1057,7 +1020,7 @@ echo ${UNAME_MACHINE}-dec-linux-${LIBC} exit ;; x86_64:Linux:*:*) - echo ${UNAME_MACHINE}-pc-linux-${LIBC} + echo ${UNAME_MACHINE}-unknown-linux-${LIBC} exit ;; xtensa*:Linux:*:*) echo ${UNAME_MACHINE}-unknown-linux-${LIBC} @@ -1136,7 +1099,7 @@ # uname -m prints for DJGPP always 'pc', but it prints nothing about # the processor, so we play safe by assuming i586. # Note: whatever this is, it MUST be the same as what config.sub - # prints for the "djgpp" host, or else GDB configure will decide that + # prints for the "djgpp" host, or else GDB configury will decide that # this is a cross-build. echo i586-pc-msdosdjgpp exit ;; @@ -1285,9 +1248,6 @@ SX-8R:SUPER-UX:*:*) echo sx8r-nec-superux${UNAME_RELEASE} exit ;; - SX-ACE:SUPER-UX:*:*) - echo sxace-nec-superux${UNAME_RELEASE} - exit ;; Power*:Rhapsody:*:*) echo powerpc-apple-rhapsody${UNAME_RELEASE} exit ;; @@ -1301,9 +1261,9 @@ UNAME_PROCESSOR=powerpc fi if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then - if [ "$CC_FOR_BUILD" != no_compiler_found ]; then + if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \ - (CCOPTS="" $CC_FOR_BUILD -E - 2>/dev/null) | \ + (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \ grep IS_64BIT_ARCH >/dev/null then case $UNAME_PROCESSOR in @@ -1325,7 +1285,7 @@ exit ;; *:procnto*:*:* | *:QNX:[0123456789]*:*) UNAME_PROCESSOR=`uname -p` - if test "$UNAME_PROCESSOR" = x86; then + if test "$UNAME_PROCESSOR" = "x86"; then UNAME_PROCESSOR=i386 UNAME_MACHINE=pc fi @@ -1356,7 +1316,7 @@ # "uname -m" is not consistent, so use $cputype instead. 386 # is converted to i386 for consistency with other x86 # operating systems. - if test "$cputype" = 386; then + if test "$cputype" = "386"; then UNAME_MACHINE=i386 else UNAME_MACHINE="$cputype" @@ -1398,7 +1358,7 @@ echo i386-pc-xenix exit ;; i*86:skyos:*:*) - echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE} | sed -e 's/ .*$//'` + echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//' exit ;; i*86:rdos:*:*) echo ${UNAME_MACHINE}-pc-rdos @@ -1408,26 +1368,24 @@ exit ;; x86_64:VMkernel:*:*) echo ${UNAME_MACHINE}-unknown-esx - exit ;; - amd64:Isilon\ OneFS:*:*) - echo x86_64-unknown-onefs exit ;; esac cat >&2 < in order to provide the needed +information to handle your system. config.guess timestamp = $timestamp diff --git a/gcc/isl/config.sub b/gcc/isl/config.sub index dd2ca93..bba4efb 100755 --- a/gcc/isl/config.sub +++ a/gcc/isl/config.sub @@ -1,8 +1,8 @@ #! /bin/sh # Configuration validation subroutine script. -# Copyright 1992-2016 Free Software Foundation, Inc. +# Copyright 1992-2014 Free Software Foundation, Inc. -timestamp='2016-11-04' +timestamp='2014-09-11' # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ # of the GNU General Public License, version 3 ("GPLv3"). -# Please send patches to . +# Please send patches with a ChangeLog entry to config-patches@gnu.org. # # Configuration subroutine to validate and canonicalize a configuration type. # Supply the specified configuration type as an argument. @@ -33,7 +33,7 @@ # Otherwise, we print the canonical config type on stdout and succeed. # You can get the latest version of this script from: -# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub +# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD # This file is supposed to be the same for all GNU packages # and recognize all the CPU types, system types and aliases @@ -53,7 +53,8 @@ me=`echo "$0" | sed -e 's,.*/,,'` usage="\ -Usage: $0 [OPTION] CPU-MFR-OPSYS or ALIAS +Usage: $0 [OPTION] CPU-MFR-OPSYS + $0 [OPTION] ALIAS Canonicalize a configuration name. @@ -67,7 +68,7 @@ version="\ GNU config.sub ($timestamp) -Copyright 1992-2016 Free Software Foundation, Inc. +Copyright 1992-2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." @@ -116,8 +117,8 @@ case $maybe_os in nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \ - knetbsd*-gnu* | netbsd*-gnu* | netbsd*-eabi* | \ - kopensolaris*-gnu* | cloudabi*-eabi* | \ + knetbsd*-gnu* | netbsd*-gnu* | \ + kopensolaris*-gnu* | \ storm-chaos* | os2-emx* | rtmk-nova*) os=-$maybe_os basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` @@ -254,13 +255,12 @@ | arc | arceb \ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \ | avr | avr32 \ - | ba \ | be32 | be64 \ | bfin \ | c4x | c8051 | clipper \ | d10v | d30v | dlx | dsp16xx \ - | e2k | epiphany \ - | fido | fr30 | frv | ft32 \ + | epiphany \ + | fido | fr30 | frv \ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ | hexagon \ | i370 | i860 | i960 | ia64 \ @@ -301,12 +301,11 @@ | open8 | or1k | or1knd | or32 \ | pdp10 | pdp11 | pj | pjl \ | powerpc | powerpc64 | powerpc64le | powerpcle \ - | pru \ | pyramid \ | riscv32 | riscv64 \ | rl78 | rx \ | score \ - | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[234]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ + | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \ | sh64 | sh64le \ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \ @@ -314,7 +313,6 @@ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \ | ubicom32 \ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \ - | visium \ | we32k \ | x86 | xc16x | xstormy16 | xtensa \ | z8k | z80) @@ -329,9 +327,6 @@ c6x) basic_machine=tic6x-unknown ;; - leon|leon[3-9]) - basic_machine=sparc-$basic_machine - ;; m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip) basic_machine=$basic_machine-unknown os=-none @@ -377,13 +372,12 @@ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ | avr-* | avr32-* \ - | ba-* \ | be32-* | be64-* \ | bfin-* | bs2000-* \ | c[123]* | c30-* | [cjt]90-* | c4x-* \ | c8051-* | clipper-* | craynv-* | cydra-* \ | d10v-* | d30v-* | dlx-* \ - | e2k-* | elxsi-* \ + | elxsi-* \ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \ | h8300-* | h8500-* \ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ @@ -429,15 +423,13 @@ | orion-* \ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \ - | pru-* \ | pyramid-* \ - | riscv32-* | riscv64-* \ | rl78-* | romp-* | rs6000-* | rx-* \ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \ | sparclite-* \ - | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx*-* \ + | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \ | tahoe-* \ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \ | tile*-* \ @@ -445,7 +437,6 @@ | ubicom32-* \ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \ | vax-* \ - | visium-* \ | we32k-* \ | x86-* | x86_64-* | xc16x-* | xps100-* \ | xstormy16-* | xtensa*-* \ @@ -521,9 +512,6 @@ aros) basic_machine=i386-pc os=-aros - ;; - asmjs) - basic_machine=asmjs-unknown ;; aux) basic_machine=m68k-apple @@ -644,15 +632,7 @@ dpx2* | dpx2*-bull) basic_machine=m68k-bull os=-sysv3 - ;; - e500v[12]) - basic_machine=powerpc-unknown - os=$os"spe" ;; - e500v[12]-*) - basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` - os=$os"spe" - ;; ebmon29k) basic_machine=a29k-amd os=-ebmon @@ -794,9 +774,6 @@ basic_machine=m68k-isi os=-sysv ;; - leon-*|leon[3-9]-*) - basic_machine=sparc-`echo $basic_machine | sed 's/-.*//'` - ;; m68knommu) basic_machine=m68k-unknown os=-linux @@ -1032,7 +1009,7 @@ ppc-* | ppcbe-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - ppcle | powerpclittle) + ppcle | powerpclittle | ppc-le | powerpc-little) basic_machine=powerpcle-unknown ;; ppcle-* | powerpclittle-*) @@ -1042,7 +1019,7 @@ ;; ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` ;; - ppc64le | powerpc64little) + ppc64le | powerpc64little | ppc64-le | powerpc64-little) basic_machine=powerpc64le-unknown ;; ppc64le-* | powerpc64little-*) @@ -1388,18 +1365,18 @@ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \ | -sym* | -kopensolaris* | -plan9* \ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ - | -aos* | -aros* | -cloudabi* | -sortix* \ + | -aos* | -aros* \ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ - | -bitrig* | -openbsd* | -solidbsd* | -libertybsd* \ + | -bitrig* | -openbsd* | -solidbsd* \ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ | -chorusos* | -chorusrdb* | -cegcc* \ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ - | -midipix* | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ + | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \ | -linux-newlib* | -linux-musl* | -linux-uclibc* \ | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \ @@ -1408,8 +1385,7 @@ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \ - | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* \ - | -onefs* | -tirtos* | -phoenix* | -fuchsia*) + | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*) # Remember, each alternative MUST END IN *, to match a version number. ;; -qnx*) @@ -1540,8 +1516,6 @@ os=-dicos ;; -nacl*) - ;; - -ios) ;; -none) ;; diff --git a/gcc/isl/configure b/gcc/isl/configure index a8a2c1b..aaf0d90 100755 --- a/gcc/isl/configure +++ a/gcc/isl/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for isl 0.19. +# Generated by GNU Autoconf 2.69 for isl 0.22.1. # # Report bugs to . # @@ -590,8 +590,8 @@ # Identity of this package. PACKAGE_NAME='isl' PACKAGE_TARNAME='isl' -PACKAGE_VERSION='0.19' -PACKAGE_STRING='isl 0.19' +PACKAGE_VERSION='0.22.1' +PACKAGE_STRING='isl 0.22.1' PACKAGE_BUGREPORT='isl-development@googlegroups.com' PACKAGE_URL='' @@ -641,15 +641,20 @@ pkgconfig_libfile pkgconfig_libdir WARNING_FLAGS +HAVE_CPP_ISL_H_FALSE +HAVE_CPP_ISL_H_TRUE HAVE_CLANG_FALSE HAVE_CLANG_TRUE LIB_CLANG_EDIT llvm_config_found CLANG_LIBS +CLANG_RFLAG CLANG_LDFLAGS CLANG_CXXFLAGS SMALL_INT_OPT_FALSE SMALL_INT_OPT_TRUE +HAVE_CXX11_FALSE +HAVE_CXX11_TRUE GMP_FOR_MP_FALSE GMP_FOR_MP_TRUE IMATH_FOR_MP_FALSE @@ -658,12 +663,15 @@ NEED_GET_MEMORY_FUNCTIONS_TRUE MP_LIBS MP_LDFLAGS +MP_CFLAGS MP_CPPFLAGS GENERATE_DOC_FALSE GENERATE_DOC_TRUE +OS_SRCDIR POD2HTML PDFLATEX PERL +CYGPATH HAVE_PYTHON_FALSE HAVE_PYTHON_TRUE pkgpyexecdir @@ -699,6 +707,7 @@ SED LIBTOOL GREP +HAVE_CXX11 PRTDIAG host_os host_vendor @@ -1387,7 +1396,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures isl 0.19 to adapt to many kinds of systems. +\`configure' configures isl 0.22.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1458,7 +1467,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of isl 0.19:";; + short | recursive ) echo "Configuration of isl 0.22.1:";; esac cat <<\_ACEOF @@ -1589,7 +1598,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -isl configure 0.19 +isl configure 0.22.1 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -2484,7 +2493,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by isl $as_me 0.19, which was +It was created by isl $as_me 0.22.1, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3348,7 +3357,7 @@ # Define the identity of the package. PACKAGE='isl' - VERSION='0.19' + VERSION='0.22.1' cat >>confdefs.h <<_ACEOF @@ -3481,7 +3490,7 @@ AM_BACKSLASH='\' -versioninfo=19:0:0 +versioninfo=22:1:0 if test "x$prefix" != "xNONE"; then prefix_wd=`cd $prefix && pwd` @@ -5934,6 +5943,673 @@ fi + + ax_cxx_compile_alternatives="11 0x" ax_cxx_compile_cxx11_required=false + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + ac_success=no + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features by default" >&5 +$as_echo_n "checking whether $CXX supports C++11 features by default... " >&6; } +if ${ax_cv_cxx_compile_cxx11+:} false; then : + $as_echo_n "(cached) " >&6 +else + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + + + +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ax_cv_cxx_compile_cxx11=yes +else + ax_cv_cxx_compile_cxx11=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_cxx_compile_cxx11" >&5 +$as_echo "$ax_cv_cxx_compile_cxx11" >&6; } + if test x$ax_cv_cxx_compile_cxx11 = xyes; then + ac_success=yes + fi + + + + if test x$ac_success = xno; then + for alternative in ${ax_cxx_compile_alternatives}; do + for switch in -std=c++${alternative} +std=c++${alternative} "-h std=c++${alternative}"; do + cachevar=`$as_echo "ax_cv_cxx_compile_cxx11_$switch" | $as_tr_sh` + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CXX supports C++11 features with $switch" >&5 +$as_echo_n "checking whether $CXX supports C++11 features with $switch... " >&6; } +if eval \${$cachevar+:} false; then : + $as_echo_n "(cached) " >&6 +else + ac_save_CXX="$CXX" + CXX="$CXX $switch" + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + +// If the compiler admits that it is not ready for C++11, why torture it? +// Hopefully, this will speed up the test. + +#ifndef __cplusplus + +#error "This is not a C++ compiler" + +#elif __cplusplus < 201103L + +#error "This is not a C++11 compiler" + +#else + +namespace cxx11 +{ + + namespace test_static_assert + { + + template + struct check + { + static_assert(sizeof(int) <= sizeof(T), "not big enough"); + }; + + } + + namespace test_final_override + { + + struct Base + { + virtual void f() {} + }; + + struct Derived : public Base + { + virtual void f() override {} + }; + + } + + namespace test_double_right_angle_brackets + { + + template < typename T > + struct check {}; + + typedef check single_type; + typedef check> double_type; + typedef check>> triple_type; + typedef check>>> quadruple_type; + + } + + namespace test_decltype + { + + int + f() + { + int a = 1; + decltype(a) b = 2; + return a + b; + } + + } + + namespace test_type_deduction + { + + template < typename T1, typename T2 > + struct is_same + { + static const bool value = false; + }; + + template < typename T > + struct is_same + { + static const bool value = true; + }; + + template < typename T1, typename T2 > + auto + add(T1 a1, T2 a2) -> decltype(a1 + a2) + { + return a1 + a2; + } + + int + test(const int c, volatile int v) + { + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == false, ""); + auto ac = c; + auto av = v; + auto sumi = ac + av + 'x'; + auto sumf = ac + av + 1.0; + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == true, ""); + static_assert(is_same::value == false, ""); + static_assert(is_same::value == true, ""); + return (sumf > 0.0) ? sumi : add(c, v); + } + + } + + namespace test_noexcept + { + + int f() { return 0; } + int g() noexcept { return 0; } + + static_assert(noexcept(f()) == false, ""); + static_assert(noexcept(g()) == true, ""); + + } + + namespace test_constexpr + { + + template < typename CharT > + unsigned long constexpr + strlen_c_r(const CharT *const s, const unsigned long acc) noexcept + { + return *s ? strlen_c_r(s + 1, acc + 1) : acc; + } + + template < typename CharT > + unsigned long constexpr + strlen_c(const CharT *const s) noexcept + { + return strlen_c_r(s, 0UL); + } + + static_assert(strlen_c("") == 0UL, ""); + static_assert(strlen_c("1") == 1UL, ""); + static_assert(strlen_c("example") == 7UL, ""); + static_assert(strlen_c("another\0example") == 7UL, ""); + + } + + namespace test_rvalue_references + { + + template < int N > + struct answer + { + static constexpr int value = N; + }; + + answer<1> f(int&) { return answer<1>(); } + answer<2> f(const int&) { return answer<2>(); } + answer<3> f(int&&) { return answer<3>(); } + + void + test() + { + int i = 0; + const int c = 0; + static_assert(decltype(f(i))::value == 1, ""); + static_assert(decltype(f(c))::value == 2, ""); + static_assert(decltype(f(0))::value == 3, ""); + } + + } + + namespace test_uniform_initialization + { + + struct test + { + static const int zero {}; + static const int one {1}; + }; + + static_assert(test::zero == 0, ""); + static_assert(test::one == 1, ""); + + } + + namespace test_lambdas + { + + void + test1() + { + auto lambda1 = [](){}; + auto lambda2 = lambda1; + lambda1(); + lambda2(); + } + + int + test2() + { + auto a = [](int i, int j){ return i + j; }(1, 2); + auto b = []() -> int { return '0'; }(); + auto c = [=](){ return a + b; }(); + auto d = [&](){ return c; }(); + auto e = [a, &b](int x) mutable { + const auto identity = [](int y){ return y; }; + for (auto i = 0; i < a; ++i) + a += b--; + return x + identity(a + b); + }(0); + return a + b + c + d + e; + } + + int + test3() + { + const auto nullary = [](){ return 0; }; + const auto unary = [](int x){ return x; }; + using nullary_t = decltype(nullary); + using unary_t = decltype(unary); + const auto higher1st = [](nullary_t f){ return f(); }; + const auto higher2nd = [unary](nullary_t f1){ + return [unary, f1](unary_t f2){ return f2(unary(f1())); }; + }; + return higher1st(nullary) + higher2nd(nullary)(unary); + } + + } + + namespace test_variadic_templates + { + + template + struct sum; + + template + struct sum + { + static constexpr auto value = N0 + sum::value; + }; + + template <> + struct sum<> + { + static constexpr auto value = 0; + }; + + static_assert(sum<>::value == 0, ""); + static_assert(sum<1>::value == 1, ""); + static_assert(sum<23>::value == 23, ""); + static_assert(sum<1, 2>::value == 3, ""); + static_assert(sum<5, 5, 11>::value == 21, ""); + static_assert(sum<2, 3, 5, 7, 11, 13>::value == 41, ""); + + } + + // http://stackoverflow.com/questions/13728184/template-aliases-and-sfinae + // Clang 3.1 fails with headers of libstd++ 4.8.3 when using std::function + // because of this. + namespace test_template_alias_sfinae + { + + struct foo {}; + + template + using member = typename T::member_type; + + template + void func(...) {} + + template + void func(member*) {} + + void test(); + + void test() { func(0); } + + } + +} // namespace cxx11 + +#endif // __cplusplus >= 201103L + + + +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + eval $cachevar=yes +else + eval $cachevar=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + CXX="$ac_save_CXX" +fi +eval ac_res=\$$cachevar + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 +$as_echo "$ac_res" >&6; } + if eval test x\$$cachevar = xyes; then + CXX="$CXX $switch" + if test -n "$CXXCPP" ; then + CXXCPP="$CXXCPP $switch" + fi + ac_success=yes + break + fi + done + if test x$ac_success = xyes; then + break + fi + done + fi + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + if test x$ax_cxx_compile_cxx11_required = xtrue; then + if test x$ac_success = xno; then + as_fn_error $? "*** A compiler with support for C++11 language features is required." "$LINENO" 5 + fi + fi + if test x$ac_success = xno; then + HAVE_CXX11=0 + { $as_echo "$as_me:${as_lineno-$LINENO}: No compiler with C++11 support was found" >&5 +$as_echo "$as_me: No compiler with C++11 support was found" >&6;} + else + HAVE_CXX11=1 + +$as_echo "#define HAVE_CXX11 1" >>confdefs.h + + fi + + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for grep that handles long lines and -e" >&5 $as_echo_n "checking for grep that handles long lines and -e... " >&6; } if ${ac_cv_path_GREP+:} false; then : @@ -9633,7 +10309,6 @@ - func_stripname_cnf () { case $2 in @@ -17387,7 +18062,7 @@ $as_echo_n "(cached) " >&6 else - for am_cv_pathless_PYTHON in python python2 python3 python3.3 python3.2 python3.1 python3.0 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 none; do + for am_cv_pathless_PYTHON in python python2 python3 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3 python3.2 python3.1 python3.0 python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1 python2.0 none; do test "$am_cv_pathless_PYTHON" = none && break prog="import sys # split strings by '.' and convert to numeric. Append some zeros @@ -17613,7 +18288,44 @@ else HAVE_PYTHON_TRUE='#' HAVE_PYTHON_FALSE= +fi + + +# Extract the first word of "cygpath", so it can be a program name with args. +set dummy cygpath; ac_word=$2 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if ${ac_cv_prog_CYGPATH+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test -n "$CYGPATH"; then + ac_cv_prog_CYGPATH="$CYGPATH" # Let the user override the test. +else +as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then + ac_cv_prog_CYGPATH="cygpath" + $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done + done +IFS=$as_save_IFS + fi +fi +CYGPATH=$ac_cv_prog_CYGPATH +if test -n "$CYGPATH"; then + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $CYGPATH" >&5 +$as_echo "$CYGPATH" >&6; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +fi # Extract the first word of "perl", so it can be a program name with args. @@ -17725,9 +18437,16 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } fi + +if test "$host_os" = "mingw32" -a -n "$CYGPATH"; then + OS_SRCDIR=`$CYGPATH -m "$srcdir"` +else + OS_SRCDIR="$srcdir" +fi + if test -n "$PERL" -a -n "$PDFLATEX" -a -n "$POD2HTML"; then GENERATE_DOC_TRUE= GENERATE_DOC_FALSE='#' @@ -18218,6 +18937,7 @@ + case "$with_int" in gmp) @@ -18487,7 +19207,7 @@ ;; esac if test "x$with_int" = "ximath-32" -a "x$GCC" = "xyes"; then - MP_CPPFLAGS="-std=gnu99 $MP_CPPFLAGS" + MP_CFLAGS="-std=gnu99 $MP_CFLAGS" fi if test x$with_int = ximath -o x$with_int = ximath-32; then @@ -18506,6 +19226,14 @@ GMP_FOR_MP_FALSE= fi + + if test "x$HAVE_CXX11" = "x1"; then + HAVE_CXX11_TRUE= + HAVE_CXX11_FALSE='#' +else + HAVE_CXX11_TRUE='#' + HAVE_CXX11_FALSE= +fi if test "x$with_int" == "ximath-32"; then SMALL_INT_OPT_TRUE= @@ -18730,6 +19458,7 @@ case "$with_clang" in system) + @@ -18917,6 +19646,9 @@ CLANG_CXXFLAGS=`$llvm_config --cxxflags | \ $SED -e 's/-Wcovered-switch-default//;s/-gsplit-dwarf//'` CLANG_LDFLAGS=`$llvm_config --ldflags` +# Construct a -R argument for libtool. +# This is needed in case some of the clang libraries are shared libraries. +CLANG_RFLAG=`echo "$CLANG_LDFLAGS" | $SED -e 's/-L/-R/g'` targets=`$llvm_config --targets-built` components="$targets asmparser bitreader support mc" $llvm_config --components | $GREP option > /dev/null 2> /dev/null @@ -18977,7 +19709,23 @@ else $as_echo "#define getExpansionLineNumber getInstantiationLineNumber" >>confdefs.h + +fi +rm -f conftest* + +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "getImmediateExpansionRange" >/dev/null 2>&1; then : + +else +$as_echo "#define getImmediateExpansionRange getImmediateInstantiationRange" >>confdefs.h + + fi rm -f conftest* @@ -19005,7 +19753,22 @@ $EGREP "ArrayRef" >/dev/null 2>&1; then : $as_echo "#define USE_ARRAYREF /**/" >>confdefs.h + + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include + +_ACEOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + $EGREP "ArrayRef.*CommandLineArgs" >/dev/null 2>&1; then : + +$as_echo "#define CREATE_FROM_ARGS_TAKES_ARRAYREF /**/" >>confdefs.h + +fi +rm -f conftest* + + fi rm -f conftest* @@ -19281,9 +20044,20 @@ if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | $EGREP "IK_C" >/dev/null 2>&1; then : +else + ac_fn_cxx_check_header_mongrel "$LINENO" "clang/Basic/LangStandard.h" "ac_cv_header_clang_Basic_LangStandard_h" "$ac_includes_default" +if test "x$ac_cv_header_clang_Basic_LangStandard_h" = xyes; then : + IK_C=Language::C else + IK_C=InputKind::C +fi + + + +cat >>confdefs.h <<_ACEOF +#define IK_C $IK_C +_ACEOF -$as_echo "#define IK_C InputKind::C" >>confdefs.h fi rm -f conftest* @@ -19342,6 +20116,14 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +ac_fn_cxx_check_header_mongrel "$LINENO" "llvm/Option/Arg.h" "ac_cv_header_llvm_Option_Arg_h" "$ac_includes_default" +if test "x$ac_cv_header_llvm_Option_Arg_h" = xyes; then : + +$as_echo "#define HAVE_LLVM_OPTION_ARG_H /**/" >>confdefs.h + +fi + + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -19397,6 +20179,15 @@ else HAVE_CLANG_TRUE='#' HAVE_CLANG_FALSE= +fi + + if (test $with_clang = system -a "x$HAVE_CXX11" = "x1") || \ + test -f $srcdir/include/isl/cpp.h; then + HAVE_CPP_ISL_H_TRUE= + HAVE_CPP_ISL_H_FALSE='#' +else + HAVE_CPP_ISL_H_TRUE='#' + HAVE_CPP_ISL_H_FALSE= fi @@ -19849,6 +20640,10 @@ fi if test -z "${GMP_FOR_MP_TRUE}" && test -z "${GMP_FOR_MP_FALSE}"; then as_fn_error $? "conditional \"GMP_FOR_MP\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${HAVE_CXX11_TRUE}" && test -z "${HAVE_CXX11_FALSE}"; then + as_fn_error $? "conditional \"HAVE_CXX11\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi if test -z "${SMALL_INT_OPT_TRUE}" && test -z "${SMALL_INT_OPT_FALSE}"; then @@ -19857,6 +20652,10 @@ fi if test -z "${HAVE_CLANG_TRUE}" && test -z "${HAVE_CLANG_FALSE}"; then as_fn_error $? "conditional \"HAVE_CLANG\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi +if test -z "${HAVE_CPP_ISL_H_TRUE}" && test -z "${HAVE_CPP_ISL_H_FALSE}"; then + as_fn_error $? "conditional \"HAVE_CPP_ISL_H\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi @@ -20256,7 +21055,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by isl $as_me 0.19, which was +This file was extended by isl $as_me 0.22.1, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -20322,7 +21121,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -isl config.status 0.19 +isl config.status 0.22.1 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff --git a/gcc/isl/configure.ac b/gcc/isl/configure.ac index df46c86..65d787d 100644 --- a/gcc/isl/configure.ac +++ a/gcc/isl/configure.ac @@ -1,10 +1,10 @@ -AC_INIT([isl], [0.19], [isl-development@googlegroups.com]) +AC_INIT([isl], [0.22.1], [isl-development@googlegroups.com]) AC_CONFIG_AUX_DIR([.]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) AC_SUBST(versioninfo) -versioninfo=19:0:0 +versioninfo=22:1:0 if test "x$prefix" != "xNONE"; then prefix_wd=`cd $prefix && pwd` @@ -25,15 +25,25 @@ AX_GCC_WARN_UNUSED_RESULT AX_C___ATTRIBUTE__ +AX_CXX_COMPILE_STDCXX_11([noext], [optional]) + AC_PROG_GREP AC_PROG_LIBTOOL AC_PROG_SED AM_PATH_PYTHON([2.5], [], [:]) AM_CONDITIONAL([HAVE_PYTHON], [test "$PYTHON" != :]) +AC_CHECK_PROG(CYGPATH, cygpath, cygpath, []) AC_CHECK_PROG(PERL, perl, perl, []) AC_CHECK_PROG(PDFLATEX, pdflatex, pdflatex, []) AC_CHECK_PROG(POD2HTML, pod2html, pod2html, []) + +AC_SUBST(OS_SRCDIR) +if test "$host_os" = "mingw32" -a -n "$CYGPATH"; then + OS_SRCDIR=`$CYGPATH -m "$srcdir"` +else + OS_SRCDIR="$srcdir" +fi AM_CONDITIONAL(GENERATE_DOC, test -n "$PERL" -a -n "$PDFLATEX" -a -n "$POD2HTML") @@ -53,6 +63,7 @@ esac AC_SUBST(MP_CPPFLAGS) +AC_SUBST(MP_CFLAGS) AC_SUBST(MP_LDFLAGS) AC_SUBST(MP_LIBS) case "$with_int" in @@ -64,12 +75,13 @@ ;; esac if test "x$with_int" = "ximath-32" -a "x$GCC" = "xyes"; then - MP_CPPFLAGS="-std=gnu99 $MP_CPPFLAGS" + MP_CFLAGS="-std=gnu99 $MP_CFLAGS" fi AM_CONDITIONAL(IMATH_FOR_MP, test x$with_int = ximath -o x$with_int = ximath-32) AM_CONDITIONAL(GMP_FOR_MP, test x$with_int = xgmp) +AM_CONDITIONAL(HAVE_CXX11, test "x$HAVE_CXX11" = "x1") AM_CONDITIONAL(SMALL_INT_OPT, test "x$with_int" == "ximath-32") AS_IF([test "x$with_int" == "ximath-32"], [ AC_DEFINE([USE_SMALL_INT_OPT], [], [Use small integer optimization]) @@ -106,6 +118,9 @@ ;; esac AM_CONDITIONAL(HAVE_CLANG, test $with_clang = system) +AM_CONDITIONAL(HAVE_CPP_ISL_H, + [(test $with_clang = system -a "x$HAVE_CXX11" = "x1") || \ + test -f $srcdir/include/isl/cpp.h]) AX_SET_WARNING_FLAGS diff --git a/gcc/isl/depcomp b/gcc/isl/depcomp index fc98710..b39f98f 100755 --- a/gcc/isl/depcomp +++ a/gcc/isl/depcomp @@ -1,9 +1,9 @@ #! /bin/sh # depcomp - compile a program generating dependencies as side-effects -scriptversion=2013-05-30.07; # UTC +scriptversion=2016-01-11.22; # UTC -# Copyright (C) 1999-2014 Free Software Foundation, Inc. +# Copyright (C) 1999-2017 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -786,6 +786,6 @@ # eval: (add-hook 'write-file-hooks 'time-stamp) # time-stamp-start: "scriptversion=" # time-stamp-format: "%:y-%02m-%02d.%02H" -# time-stamp-time-zone: "UTC" +# time-stamp-time-zone: "UTC0" # time-stamp-end: "; # UTC" # End: diff --git a/gcc/isl/install-sh b/gcc/isl/install-sh index 59990a1..0b0fdcb 100755 --- a/gcc/isl/install-sh +++ a/gcc/isl/install-sh @@ -1,7 +1,7 @@ #!/bin/sh # install - install a program, script, or datafile -scriptversion=2014-09-12.12; # UTC +scriptversion=2013-12-25.23; # UTC # This originates from X11R5 (mit/util/scripts/install.sh), which was # later released in X11R6 (xc/config/util/install.sh) with the @@ -324,41 +324,34 @@ # is incompatible with FreeBSD 'install' when (umask & 300) != 0. ;; *) - # $RANDOM is not portable (e.g. dash); use it when possible to - # lower collision chance tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ - trap 'ret=$?; rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" 2>/dev/null; exit $ret' 0 - - # As "mkdir -p" follows symlinks and we work in /tmp possibly; so - # create the $tmpdir first (and fail if unsuccessful) to make sure - # that nobody tries to guess the $tmpdir name. + trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 + if (umask $mkdir_umask && - $mkdirprog $mkdir_mode "$tmpdir" && - exec $mkdirprog $mkdir_mode -p -- "$tmpdir/a/b") >/dev/null 2>&1 + exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 then if test -z "$dir_arg" || { # Check for POSIX incompatibilities with -m. # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or # other-writable bit of parent directory when it shouldn't. # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. - test_tmpdir="$tmpdir/a" - ls_ld_tmpdir=`ls -ld "$test_tmpdir"` + ls_ld_tmpdir=`ls -ld "$tmpdir"` case $ls_ld_tmpdir in d????-?r-*) different_mode=700;; d????-?--*) different_mode=755;; *) false;; esac && - $mkdirprog -m$different_mode -p -- "$test_tmpdir" && { - ls_ld_tmpdir_1=`ls -ld "$test_tmpdir"` + $mkdirprog -m$different_mode -p -- "$tmpdir" && { + ls_ld_tmpdir_1=`ls -ld "$tmpdir"` test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" } } then posix_mkdir=: fi - rmdir "$tmpdir/a/b" "$tmpdir/a" "$tmpdir" + rmdir "$tmpdir/d" "$tmpdir" else # Remove any dirs left behind by ancient mkdir implementations. - rmdir ./$mkdir_mode ./-p ./-- "$tmpdir" 2>/dev/null + rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null fi trap '' 0;; esac;; diff --git a/gcc/isl/isl_aff.c b/gcc/isl/isl_aff.c index bec3796..71426fa 100644 --- a/gcc/isl/isl_aff.c +++ a/gcc/isl/isl_aff.c @@ -1,8 +1,9 @@ /* * Copyright 2011 INRIA Saclay * Copyright 2011 Sven Verdoolaege * Copyright 2012-2014 Ecole Normale Superieure * Copyright 2014 INRIA Rocquencourt + * Copyright 2018 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -12,10 +13,10 @@ * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt, * B.P. 105 - 78153 Le Chesnay, France + * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA */ #include -#define ISL_DIM_H #include #include #include @@ -23,29 +24,36 @@ #include #include #include +#include #include #include #include #include +#include #include -#undef BASE -#define BASE aff +#undef EL_BASE +#define EL_BASE aff #include -#undef BASE -#define BASE pw_aff +#undef EL_BASE +#define EL_BASE pw_aff #include -#undef BASE -#define BASE union_pw_aff +#undef EL_BASE +#define EL_BASE pw_multi_aff #include -#undef BASE -#define BASE union_pw_multi_aff +#undef EL_BASE +#define EL_BASE union_pw_aff + +#include + +#undef EL_BASE +#define EL_BASE union_pw_multi_aff #include @@ -76,7 +84,7 @@ { isl_ctx *ctx; isl_vec *v; - unsigned total; + isl_size total; if (!ls) return NULL; @@ -91,6 +99,8 @@ goto error); total = isl_local_space_dim(ls, isl_dim_all); + if (total < 0) + goto error; v = isl_vec_alloc(ctx, 1 + 1 + total); return isl_aff_alloc_vec(ls, v); error: @@ -173,6 +183,14 @@ isl_local_space_free(ls); isl_val_free(val); return NULL; +} + +/* Return an affine expression that is equal to "val" on domain space "space". + */ +__isl_give isl_aff *isl_aff_val_on_domain_space(__isl_take isl_space *space, + __isl_take isl_val *val) +{ + return isl_aff_val_on_domain(isl_local_space_from_space(space), val); } /* Return an affine expression that is equal to the specified dimension @@ -193,9 +211,8 @@ if (isl_space_is_map(space)) isl_die(isl_space_get_ctx(space), isl_error_invalid, "expecting (parameter) set space", goto error); - if (pos >= isl_local_space_dim(ls, type)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "position out of bounds", goto error); + if (isl_local_space_check_range(ls, type, pos, 1) < 0) + goto error; isl_space_free(space); aff = isl_aff_alloc(ls); @@ -314,20 +331,49 @@ isl_hash_hash(hash, v_hash); return hash; +} + +/* Return the domain local space of "aff". + */ +static __isl_keep isl_local_space *isl_aff_peek_domain_local_space( + __isl_keep isl_aff *aff) +{ + return aff ? aff->ls : NULL; +} + +/* Return the number of variables of the given type in the domain of "aff". + */ +isl_size isl_aff_domain_dim(__isl_keep isl_aff *aff, enum isl_dim_type type) +{ + isl_local_space *ls; + + ls = isl_aff_peek_domain_local_space(aff); + return isl_local_space_dim(ls, type); } /* Externally, an isl_aff has a map space, but internally, the * ls field corresponds to the domain of that space. */ -int isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type) +isl_size isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type) { if (!aff) - return 0; + return isl_size_error; if (type == isl_dim_out) return 1; if (type == isl_dim_in) type = isl_dim_set; - return isl_local_space_dim(aff->ls, type); + return isl_aff_domain_dim(aff, type); +} + +/* Return the offset of the first coefficient of type "type" in + * the domain of "aff". + */ +isl_size isl_aff_domain_offset(__isl_keep isl_aff *aff, enum isl_dim_type type) +{ + isl_local_space *ls; + + ls = isl_aff_peek_domain_local_space(aff); + return isl_local_space_offset(ls, type); } /* Return the position of the dimension of the given type and name @@ -344,11 +390,18 @@ if (type == isl_dim_in) type = isl_dim_set; return isl_local_space_find_dim_by_name(aff->ls, type, name); +} + +/* Return the domain space of "aff". + */ +static __isl_keep isl_space *isl_aff_peek_domain_space(__isl_keep isl_aff *aff) +{ + return aff ? isl_local_space_peek_space(aff->ls) : NULL; } __isl_give isl_space *isl_aff_get_domain_space(__isl_keep isl_aff *aff) { - return aff ? isl_local_space_get_space(aff->ls) : NULL; + return isl_space_copy(isl_aff_peek_domain_space(aff)); } __isl_give isl_space *isl_aff_get_space(__isl_keep isl_aff *aff) @@ -362,10 +415,12 @@ return space; } +/* Return a copy of the domain space of "aff". + */ __isl_give isl_local_space *isl_aff_get_domain_local_space( __isl_keep isl_aff *aff) { - return aff ? isl_local_space_copy(aff->ls) : NULL; + return isl_local_space_copy(isl_aff_peek_domain_local_space(aff)); } __isl_give isl_local_space *isl_aff_get_local_space(__isl_keep isl_aff *aff) @@ -484,14 +539,19 @@ static __isl_give isl_vec *vec_reorder(__isl_take isl_vec *vec, __isl_take isl_reordering *r, int n_div) { + isl_space *space; isl_vec *res; + isl_size dim; int i; if (!vec || !r) goto error; - res = isl_vec_alloc(vec->ctx, - 2 + isl_space_dim(r->dim, isl_dim_all) + n_div); + space = isl_reordering_peek_space(r); + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + goto error; + res = isl_vec_alloc(vec->ctx, 2 + dim + n_div); if (!res) goto error; isl_seq_cpy(res->el, vec->el, 2); @@ -547,10 +607,6 @@ if (!equal_params) { isl_reordering *exp; - model = isl_space_drop_dims(model, isl_dim_in, - 0, isl_space_dim(model, isl_dim_in)); - model = isl_space_drop_dims(model, isl_dim_out, - 0, isl_space_dim(model, isl_dim_out)); exp = isl_parameter_alignment_reordering(aff->ls->dim, model); exp = isl_reordering_extend_space(exp, isl_aff_get_domain_space(aff)); @@ -563,6 +619,33 @@ isl_space_free(model); isl_aff_free(aff); return NULL; +} + +/* Given an affine function "aff" defined over a parameter domain, + * convert it to a function defined over a domain corresponding + * to "domain". + * Any parameters with identifiers in "domain" are reinterpreted + * as the corresponding domain dimensions. + */ +__isl_give isl_aff *isl_aff_unbind_params_insert_domain( + __isl_take isl_aff *aff, __isl_take isl_multi_id *domain) +{ + isl_bool is_params; + isl_space *space; + isl_reordering *r; + + space = isl_aff_peek_domain_space(aff); + is_params = isl_space_is_params(space); + if (is_params < 0) + domain = isl_multi_id_free(domain); + else if (!is_params) + isl_die(isl_aff_get_ctx(aff), isl_error_invalid, + "expecting function with parameter domain", + domain = isl_multi_id_free(domain)); + r = isl_reordering_unbind_params_insert_domain(space, domain); + isl_multi_id_free(domain); + + return isl_aff_realign_domain(aff, r); } /* Is "aff" obviously equal to zero? @@ -571,12 +654,15 @@ */ isl_bool isl_aff_plain_is_zero(__isl_keep isl_aff *aff) { + int pos; + if (!aff) return isl_bool_error; if (isl_int_is_zero(aff->v->el[0])) return isl_bool_false; - return isl_seq_first_non_zero(aff->v->el + 1, aff->v->size - 1) < 0; + pos = isl_seq_first_non_zero(aff->v->el + 1, aff->v->size - 1); + return isl_bool_ok(pos < 0); } /* Does "aff" represent NaN? @@ -586,7 +672,7 @@ if (!aff) return isl_bool_error; - return isl_seq_first_non_zero(aff->v->el, 2) < 0; + return isl_bool_ok(isl_seq_first_non_zero(aff->v->el, 2) < 0); } /* Are "aff1" and "aff2" obviously equal? @@ -678,9 +764,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(ctx, isl_error_invalid, - "position out of bounds", return NULL); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return NULL; if (isl_aff_is_nan(aff)) return isl_val_nan(ctx); @@ -708,9 +793,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(ctx, isl_error_invalid, - "position out of bounds", return 0); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return 0; pos += isl_local_space_offset(aff->ls, type); return isl_int_sgn(aff->v->el[1 + pos]); @@ -969,9 +1053,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(aff->v->ctx, isl_error_invalid, - "position out of bounds", return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return isl_aff_free(aff); if (isl_aff_is_nan(aff)) return aff; @@ -1007,9 +1090,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos < 0 || pos >= isl_local_space_dim(aff->ls, type)) - isl_die(aff->v->ctx, isl_error_invalid, - "position out of bounds", return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return isl_aff_free(aff); if (isl_aff_is_nan(aff)) return aff; @@ -1048,9 +1130,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(aff->v->ctx, isl_error_invalid, - "position out of bounds", goto error); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return isl_aff_free(aff); if (isl_aff_is_nan(aff)) { isl_val_free(v); @@ -1114,9 +1195,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(aff->v->ctx, isl_error_invalid, - "position out of bounds", return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + return isl_aff_free(aff); if (isl_aff_is_nan(aff)) return aff; @@ -1157,9 +1237,8 @@ if (type == isl_dim_in) type = isl_dim_set; - if (pos >= isl_local_space_dim(aff->ls, type)) - isl_die(aff->v->ctx, isl_error_invalid, - "position out of bounds", goto error); + if (isl_local_space_check_range(aff->ls, type, pos, 1) < 0) + goto error; if (isl_aff_is_nan(aff)) { isl_val_free(v); @@ -1256,14 +1335,13 @@ __isl_give isl_aff *isl_aff_remove_unused_divs(__isl_take isl_aff *aff) { int pos; - int off; - int n; - - if (!aff) - return NULL; - - n = isl_local_space_dim(aff->ls, isl_dim_div); - off = isl_local_space_offset(aff->ls, isl_dim_div); + isl_size off; + isl_size n; + + n = isl_aff_domain_dim(aff, isl_dim_div); + off = isl_aff_domain_offset(aff, isl_dim_div); + if (n < 0 || off < 0) + return isl_aff_free(aff); pos = isl_seq_last_non_zero(aff->v->el + 1 + off, n) + 1; if (pos == n) @@ -1287,17 +1365,18 @@ */ static __isl_give isl_aff *plug_in_integral_divs(__isl_take isl_aff *aff) { - int i, n; + int i; + isl_size n; int len; isl_int v; isl_vec *vec; isl_local_space *ls; - unsigned pos; - - if (!aff) - return NULL; - - n = isl_local_space_dim(aff->ls, isl_dim_div); + isl_size off; + + n = isl_aff_domain_dim(aff, isl_dim_div); + off = isl_aff_domain_offset(aff, isl_dim_div); + if (n < 0 || off < 0) + return isl_aff_free(aff); len = aff->v->size; for (i = 0; i < n; ++i) { if (!isl_int_is_one(aff->ls->div->row[i][0])) @@ -1312,8 +1391,7 @@ isl_int_init(v); - pos = isl_local_space_offset(aff->ls, isl_dim_div) + i; - isl_seq_substitute(vec->el, pos, aff->ls->div->row[i], + isl_seq_substitute(vec->el, off + i, aff->ls->div->row[i], len, len, v); isl_int_clear(v); @@ -1352,14 +1430,14 @@ */ static __isl_give isl_aff *plug_in_unit_divs(__isl_take isl_aff *aff) { - int i, j, n; - int off; - - if (!aff) - return NULL; - - n = isl_local_space_dim(aff->ls, isl_dim_div); - off = isl_local_space_offset(aff->ls, isl_dim_div); + int i, j; + isl_size n; + isl_size off; + + n = isl_aff_domain_dim(aff, isl_dim_div); + off = isl_aff_domain_offset(aff, isl_dim_div); + if (n < 0 || off < 0) + return isl_aff_free(aff); for (i = 1; i < n; ++i) { for (j = 0; j < i; ++j) { if (!isl_int_is_one(aff->ls->div->row[i][1 + off + j])) @@ -1382,9 +1460,12 @@ */ static __isl_give isl_aff *swap_div(__isl_take isl_aff *aff, int a, int b) { - unsigned off = isl_local_space_offset(aff->ls, isl_dim_div); + isl_size off = isl_aff_domain_offset(aff, isl_dim_div); isl_local_space *ls; isl_vec *v; + + if (off < 0) + return isl_aff_free(aff); ls = isl_local_space_copy(aff->ls); ls = isl_local_space_swap_div(ls, a, b); @@ -1413,7 +1494,10 @@ */ static __isl_give isl_aff *merge_divs(__isl_take isl_aff *aff, int a, int b) { - unsigned off = isl_local_space_offset(aff->ls, isl_dim_div); + isl_size off = isl_aff_domain_offset(aff, isl_dim_div); + + if (off < 0) + return isl_aff_free(aff); if (isl_int_is_zero(aff->v->el[1 + off + b])) return aff; @@ -1440,12 +1524,12 @@ */ static __isl_give isl_aff *sort_divs(__isl_take isl_aff *aff) { - int i, j, n; - - if (!aff) - return NULL; + isl_size n; + int i, j; n = isl_aff_dim(aff, isl_dim_div); + if (n < 0) + return isl_aff_free(aff); for (i = 1; i < n; ++i) { for (j = i - 1; j >= 0; --j) { int cmp = isl_mat_cmp_div(aff->ls->div, j, j + 1); @@ -1669,19 +1753,19 @@ __isl_give isl_aff *isl_aff_expand_divs(__isl_take isl_aff *aff, __isl_take isl_mat *div, int *exp) { - int old_n_div; - int new_n_div; - int offset; + isl_size old_n_div; + isl_size new_n_div; + isl_size offset; aff = isl_aff_cow(aff); - if (!aff || !div) - goto error; - old_n_div = isl_local_space_dim(aff->ls, isl_dim_div); + offset = isl_aff_domain_offset(aff, isl_dim_div); + old_n_div = isl_aff_domain_dim(aff, isl_dim_div); new_n_div = isl_mat_rows(div); - offset = 1 + isl_local_space_offset(aff->ls, isl_dim_div); + if (offset < 0 || old_n_div < 0 || new_n_div < 0) + goto error; - aff->v = isl_vec_expand(aff->v, offset, old_n_div, exp, new_n_div); + aff->v = isl_vec_expand(aff->v, 1 + offset, old_n_div, exp, new_n_div); aff->ls = isl_local_space_replace_divs(aff->ls, div); if (!aff->v || !aff->ls) return isl_aff_free(aff); @@ -1738,7 +1822,7 @@ int *exp1 = NULL; int *exp2 = NULL; isl_mat *div; - int n_div1, n_div2; + isl_size n_div1, n_div2; if (!aff1 || !aff2) goto error; @@ -1759,6 +1843,8 @@ n_div1 = isl_aff_dim(aff1, isl_dim_div); n_div2 = isl_aff_dim(aff2, isl_dim_div); + if (n_div1 < 0 || n_div2 < 0) + goto error; if (n_div1 == 0 && n_div2 == 0) return add_expanded(aff1, aff2); @@ -1990,7 +2076,7 @@ aff = isl_aff_cow(aff); if (!aff) goto error; - if (type != isl_dim_out) + if (type != isl_dim_in) isl_die(aff->v->ctx, isl_error_invalid, "cannot only set id of input tuple", goto error); aff->ls = isl_local_space_set_tuple_id(aff->ls, isl_dim_set, id); @@ -2013,7 +2099,7 @@ __isl_take isl_aff *aff, __isl_take isl_basic_set *eq) { int i, j; - unsigned total; + unsigned o_div; unsigned n_div; if (!eq) @@ -2033,14 +2119,14 @@ if (!aff->ls || !aff->v) goto error; - total = 1 + isl_space_dim(eq->dim, isl_dim_all); + o_div = isl_basic_set_offset(eq, isl_dim_div); n_div = eq->n_div; for (i = 0; i < eq->n_eq; ++i) { - j = isl_seq_last_non_zero(eq->eq[i], total + n_div); - if (j < 0 || j == 0 || j >= total) + j = isl_seq_last_non_zero(eq->eq[i], o_div + n_div); + if (j < 0 || j == 0 || j >= o_div) continue; - isl_seq_elim(aff->v->el + 1, eq->eq[i], j, total, + isl_seq_elim(aff->v->el + 1, eq->eq[i], j, o_div, &aff->v->el[0]); } @@ -2059,11 +2145,11 @@ __isl_give isl_aff *isl_aff_substitute_equalities(__isl_take isl_aff *aff, __isl_take isl_basic_set *eq) { - int n_div; + isl_size n_div; - if (!aff || !eq) + n_div = isl_aff_domain_dim(aff, isl_dim_div); + if (n_div < 0) goto error; - n_div = isl_local_space_dim(aff->ls, isl_dim_div); if (n_div > 0) eq = isl_basic_set_add_dims(eq, isl_dim_set, n_div); return isl_aff_substitute_equalities_lifted(aff, eq); @@ -2081,30 +2167,14 @@ __isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff, __isl_take isl_set *context) { + isl_local_space *ls; isl_basic_set *hull; - int n_div; - if (!aff) - goto error; - n_div = isl_local_space_dim(aff->ls, isl_dim_div); - if (n_div > 0) { - isl_basic_set *bset; - isl_local_space *ls; - context = isl_set_add_dims(context, isl_dim_set, n_div); - ls = isl_aff_get_domain_local_space(aff); - bset = isl_basic_set_from_local_space(ls); - bset = isl_basic_set_lift(bset); - bset = isl_basic_set_flatten(bset); - context = isl_set_intersect(context, - isl_set_from_basic_set(bset)); - } + ls = isl_aff_get_domain_local_space(aff); + context = isl_local_space_lift_set(ls, context); hull = isl_set_affine_hull(context); return isl_aff_substitute_equalities_lifted(aff, hull); -error: - isl_aff_free(aff); - isl_set_free(context); - return NULL; } __isl_give isl_aff *isl_aff_gist_params(__isl_take isl_aff *aff, @@ -2121,7 +2191,7 @@ * If "aff" is NaN, then it is not positive. */ static __isl_give isl_basic_set *aff_pos_basic_set(__isl_take isl_aff *aff, - int rational) + int rational, void *user) { isl_constraint *ineq; isl_basic_set *bset; @@ -2158,7 +2228,7 @@ * If "aff" is NaN, then it is not non-negative (it's not negative either). */ static __isl_give isl_basic_set *aff_nonneg_basic_set( - __isl_take isl_aff *aff, int rational) + __isl_take isl_aff *aff, int rational, void *user) { isl_constraint *ineq; isl_basic_set *bset; @@ -2185,7 +2255,7 @@ */ __isl_give isl_basic_set *isl_aff_nonneg_basic_set(__isl_take isl_aff *aff) { - return aff_nonneg_basic_set(aff, 0); + return aff_nonneg_basic_set(aff, 0, NULL); } /* Return a basic set containing those elements in the domain space @@ -2213,7 +2283,7 @@ * If "aff" is NaN, then it is not zero. */ static __isl_give isl_basic_set *aff_zero_basic_set(__isl_take isl_aff *aff, - int rational) + int rational, void *user) { isl_constraint *ineq; isl_basic_set *bset; @@ -2240,7 +2310,7 @@ */ __isl_give isl_basic_set *isl_aff_zero_basic_set(__isl_take isl_aff *aff) { - return aff_zero_basic_set(aff, 0); + return aff_zero_basic_set(aff, 0, NULL); } /* Return a basic set containing those elements in the shared space @@ -2367,14 +2437,19 @@ return aff1; } -int isl_aff_is_empty(__isl_keep isl_aff *aff) +isl_bool isl_aff_is_empty(__isl_keep isl_aff *aff) { if (!aff) - return -1; + return isl_bool_error; - return 0; + return isl_bool_false; } +#undef TYPE +#define TYPE isl_aff +static +#include "check_type_range_templ.c" + /* Check whether the given affine expression has non-zero coefficient * for any dimension in the given range or if any of these dimensions * appear with non-zero coefficients in any of the integer divisions @@ -2384,7 +2459,6 @@ enum isl_dim_type type, unsigned first, unsigned n) { int i; - isl_ctx *ctx; int *active = NULL; isl_bool involves = isl_bool_false; @@ -2392,11 +2466,8 @@ return isl_bool_error; if (n == 0) return isl_bool_false; - - ctx = isl_aff_get_ctx(aff); - if (first + n > isl_aff_dim(aff, type)) - isl_die(ctx, isl_error_invalid, - "range out of bounds", return isl_bool_error); + if (isl_aff_check_range(aff, type, first, n) < 0) + return isl_bool_error; active = isl_local_space_get_active(aff->ls, aff->v->el + 2); if (!active) @@ -2415,6 +2486,18 @@ error: free(active); return isl_bool_error; +} + +/* Does "aff" involve any local variables, i.e., integer divisions? + */ +isl_bool isl_aff_involves_locals(__isl_keep isl_aff *aff) +{ + isl_size n; + + n = isl_aff_dim(aff, isl_dim_div); + if (n < 0) + return isl_bool_error; + return isl_aff_involves_dims(aff, isl_dim_div, 0, n); } __isl_give isl_aff *isl_aff_drop_dims(__isl_take isl_aff *aff, @@ -2434,9 +2517,8 @@ return aff; ctx = isl_aff_get_ctx(aff); - if (first + n > isl_local_space_dim(aff->ls, type)) - isl_die(ctx, isl_error_invalid, "range out of bounds", - return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, type, first, n) < 0) + return isl_aff_free(aff); aff = isl_aff_cow(aff); if (!aff) @@ -2452,7 +2534,18 @@ return isl_aff_free(aff); return aff; +} + +/* Is the domain of "aff" a product? + */ +static isl_bool isl_aff_domain_is_product(__isl_keep isl_aff *aff) +{ + return isl_space_is_product(isl_aff_peek_domain_space(aff)); } + +#undef TYPE +#define TYPE isl_aff +#include /* Project the domain of the affine expression onto its parameter space. * The affine expression may not involve any of the domain dimensions. @@ -2460,18 +2553,12 @@ __isl_give isl_aff *isl_aff_project_domain_on_params(__isl_take isl_aff *aff) { isl_space *space; - unsigned n; - int involves; + isl_size n; n = isl_aff_dim(aff, isl_dim_in); - involves = isl_aff_involves_dims(aff, isl_dim_in, 0, n); - if (involves < 0) + if (n < 0) return isl_aff_free(aff); - if (involves) - isl_die(isl_aff_get_ctx(aff), isl_error_invalid, - "affine expression involves some of the domain dimensions", - return isl_aff_free(aff)); - aff = isl_aff_drop_dims(aff, isl_dim_in, 0, n); + aff = isl_aff_drop_domain(aff, 0, n); space = isl_aff_get_domain_space(aff); space = isl_space_params(space); aff = isl_aff_reset_domain_space(aff, space); @@ -2509,9 +2596,8 @@ return aff; ctx = isl_aff_get_ctx(aff); - if (first > isl_local_space_dim(aff->ls, type)) - isl_die(ctx, isl_error_invalid, "position out of bounds", - return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, type, first, 0) < 0) + return isl_aff_free(aff); aff = isl_aff_cow(aff); if (!aff) @@ -2532,9 +2618,11 @@ __isl_give isl_aff *isl_aff_add_dims(__isl_take isl_aff *aff, enum isl_dim_type type, unsigned n) { - unsigned pos; + isl_size pos; pos = isl_aff_dim(aff, type); + if (pos < 0) + return isl_aff_free(aff); return isl_aff_insert_dims(aff, type, pos, n); } @@ -2542,9 +2630,11 @@ __isl_give isl_pw_aff *isl_pw_aff_add_dims(__isl_take isl_pw_aff *pwaff, enum isl_dim_type type, unsigned n) { - unsigned pos; + isl_size pos; pos = isl_pw_aff_dim(pwaff, type); + if (pos < 0) + return isl_pw_aff_free(pwaff); return isl_pw_aff_insert_dims(pwaff, type, pos, n); } @@ -2560,6 +2650,7 @@ { unsigned g_dst_pos; unsigned g_src_pos; + isl_size src_off, dst_off; if (!aff) return NULL; @@ -2580,20 +2671,21 @@ if (src_type == isl_dim_in) src_type = isl_dim_set; - if (src_pos + n > isl_local_space_dim(aff->ls, src_type)) - isl_die(isl_aff_get_ctx(aff), isl_error_invalid, - "range out of bounds", return isl_aff_free(aff)); + if (isl_local_space_check_range(aff->ls, src_type, src_pos, n) < 0) + return isl_aff_free(aff); if (dst_type == src_type) isl_die(isl_aff_get_ctx(aff), isl_error_unsupported, "moving dims within the same type not supported", return isl_aff_free(aff)); aff = isl_aff_cow(aff); - if (!aff) - return NULL; + src_off = isl_aff_domain_offset(aff, src_type); + dst_off = isl_aff_domain_offset(aff, dst_type); + if (src_off < 0 || dst_off < 0) + return isl_aff_free(aff); - g_src_pos = 1 + isl_local_space_offset(aff->ls, src_type) + src_pos; - g_dst_pos = 1 + isl_local_space_offset(aff->ls, dst_type) + dst_pos; + g_src_pos = 1 + src_off + src_pos; + g_dst_pos = 1 + dst_off + dst_pos; if (dst_type > src_type) g_dst_pos -= n; @@ -2608,18 +2700,25 @@ return aff; } -__isl_give isl_pw_aff *isl_pw_aff_from_aff(__isl_take isl_aff *aff) +/* Return a zero isl_aff in the given space. + * + * This is a helper function for isl_pw_*_as_* that ensures a uniform + * interface over all piecewise types. + */ +static __isl_give isl_aff *isl_aff_zero_in_space(__isl_take isl_space *space) { - isl_set *dom = isl_set_universe(isl_aff_get_domain_space(aff)); - return isl_pw_aff_alloc(dom, aff); + isl_local_space *ls; + + ls = isl_local_space_from_space(isl_space_domain(space)); + return isl_aff_zero_on_domain(ls); } #define isl_aff_involves_nan isl_aff_is_nan #undef PW #define PW isl_pw_aff -#undef EL -#define EL isl_aff +#undef BASE +#define BASE aff #undef EL_IS_ZERO #define EL_IS_ZERO is_empty #undef ZERO @@ -2631,21 +2730,18 @@ #undef DEFAULT_IS_ZERO #define DEFAULT_IS_ZERO 0 -#define NO_EVAL #define NO_OPT #define NO_LIFT #define NO_MORPH #include +#include +#include #include #include -#undef UNION -#define UNION isl_union_pw_aff -#undef PART -#define PART isl_pw_aff -#undef PARTS -#define PARTS pw_aff +#undef BASE +#define BASE pw_aff #include #include @@ -2664,10 +2760,9 @@ goto error; if (equal_params) return fn(pwaff1, pwaff2); - if (!isl_space_has_named_params(pwaff1->dim) || - !isl_space_has_named_params(pwaff2->dim)) - isl_die(isl_pw_aff_get_ctx(pwaff1), isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (isl_pw_aff_check_named_params(pwaff1) < 0 || + isl_pw_aff_check_named_params(pwaff2) < 0) + goto error; pwaff1 = isl_pw_aff_align_params(pwaff1, isl_pw_aff_get_space(pwaff2)); pwaff2 = isl_pw_aff_align_params(pwaff2, isl_pw_aff_get_space(pwaff1)); return fn(pwaff1, pwaff2); @@ -2677,7 +2772,7 @@ return NULL; } -/* Align the parameters of the to isl_pw_aff arguments and +/* Align the parameters of the two isl_pw_aff arguments and * then apply a function "fn" on them that returns an isl_map. */ static __isl_give isl_map *align_params_pw_pw_map_and( @@ -2694,10 +2789,9 @@ goto error; if (equal_params) return fn(pa1, pa2); - if (!isl_space_has_named_params(pa1->dim) || - !isl_space_has_named_params(pa2->dim)) - isl_die(isl_pw_aff_get_ctx(pa1), isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (isl_pw_aff_check_named_params(pa1) < 0 || + isl_pw_aff_check_named_params(pa2) < 0) + goto error; pa1 = isl_pw_aff_align_params(pa1, isl_pw_aff_get_space(pa2)); pa2 = isl_pw_aff_align_params(pa2, isl_pw_aff_get_space(pa1)); return fn(pa1, pa2); @@ -2752,71 +2846,18 @@ return isl_pw_aff_union_max(pwaff1, pwaff2); else return isl_pw_aff_union_min(pwaff1, pwaff2); -} - -/* Construct a map with as domain the domain of pwaff and - * one-dimensional range corresponding to the affine expressions. - */ -static __isl_give isl_map *map_from_pw_aff(__isl_take isl_pw_aff *pwaff) -{ - int i; - isl_space *dim; - isl_map *map; - - if (!pwaff) - return NULL; - - dim = isl_pw_aff_get_space(pwaff); - map = isl_map_empty(dim); - - for (i = 0; i < pwaff->n; ++i) { - isl_basic_map *bmap; - isl_map *map_i; - - bmap = isl_basic_map_from_aff(isl_aff_copy(pwaff->p[i].aff)); - map_i = isl_map_from_basic_map(bmap); - map_i = isl_map_intersect_domain(map_i, - isl_set_copy(pwaff->p[i].set)); - map = isl_map_union_disjoint(map, map_i); - } - - isl_pw_aff_free(pwaff); - - return map; } -/* Construct a map with as domain the domain of pwaff and - * one-dimensional range corresponding to the affine expressions. +/* Is the domain of "pa" a product? */ -__isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff) +static isl_bool isl_pw_aff_domain_is_product(__isl_keep isl_pw_aff *pa) { - if (!pwaff) - return NULL; - if (isl_space_is_set(pwaff->dim)) - isl_die(isl_pw_aff_get_ctx(pwaff), isl_error_invalid, - "space of input is not a map", goto error); - return map_from_pw_aff(pwaff); -error: - isl_pw_aff_free(pwaff); - return NULL; + return isl_space_domain_is_wrapping(isl_pw_aff_peek_space(pa)); } -/* Construct a one-dimensional set with as parameter domain - * the domain of pwaff and the single set dimension - * corresponding to the affine expressions. - */ -__isl_give isl_set *isl_set_from_pw_aff(__isl_take isl_pw_aff *pwaff) -{ - if (!pwaff) - return NULL; - if (!isl_space_is_set(pwaff->dim)) - isl_die(isl_pw_aff_get_ctx(pwaff), isl_error_invalid, - "space of input is not a set", goto error); - return map_from_pw_aff(pwaff); -error: - isl_pw_aff_free(pwaff); - return NULL; -} +#undef TYPE +#define TYPE isl_pw_aff +#include /* Return a set containing those elements in the domain * of "pwaff" where it satisfies "fn" (if complement is 0) or @@ -2826,8 +2867,9 @@ * NaN does not satisfy any property. */ static __isl_give isl_set *pw_aff_locus(__isl_take isl_pw_aff *pwaff, - __isl_give isl_basic_set *(*fn)(__isl_take isl_aff *aff, int rational), - int complement) + __isl_give isl_basic_set *(*fn)(__isl_take isl_aff *aff, int rational, + void *user), + int complement, void *user) { int i; isl_set *set; @@ -2846,7 +2888,7 @@ continue; rational = isl_set_has_rational(pwaff->p[i].set); - bset = fn(isl_aff_copy(pwaff->p[i].aff), rational); + bset = fn(isl_aff_copy(pwaff->p[i].aff), rational, user); locus = isl_set_from_basic_set(bset); set_i = isl_set_copy(pwaff->p[i].set); if (complement) @@ -2866,7 +2908,7 @@ */ __isl_give isl_set *isl_pw_aff_pos_set(__isl_take isl_pw_aff *pa) { - return pw_aff_locus(pa, &aff_pos_basic_set, 0); + return pw_aff_locus(pa, &aff_pos_basic_set, 0, NULL); } /* Return a set containing those elements in the domain @@ -2874,7 +2916,7 @@ */ __isl_give isl_set *isl_pw_aff_nonneg_set(__isl_take isl_pw_aff *pwaff) { - return pw_aff_locus(pwaff, &aff_nonneg_basic_set, 0); + return pw_aff_locus(pwaff, &aff_nonneg_basic_set, 0, NULL); } /* Return a set containing those elements in the domain @@ -2882,15 +2924,68 @@ */ __isl_give isl_set *isl_pw_aff_zero_set(__isl_take isl_pw_aff *pwaff) { - return pw_aff_locus(pwaff, &aff_zero_basic_set, 0); + return pw_aff_locus(pwaff, &aff_zero_basic_set, 0, NULL); } /* Return a set containing those elements in the domain * of pwaff where it is not zero. */ __isl_give isl_set *isl_pw_aff_non_zero_set(__isl_take isl_pw_aff *pwaff) +{ + return pw_aff_locus(pwaff, &aff_zero_basic_set, 1, NULL); +} + +/* Bind the affine function "aff" to the parameter "id", + * returning the elements in the domain where the affine expression + * is equal to the parameter. + */ +__isl_give isl_basic_set *isl_aff_bind_id(__isl_take isl_aff *aff, + __isl_take isl_id *id) +{ + isl_space *space; + isl_aff *aff_id; + + space = isl_aff_get_domain_space(aff); + space = isl_space_add_param_id(space, isl_id_copy(id)); + + aff = isl_aff_align_params(aff, isl_space_copy(space)); + aff_id = isl_aff_param_on_domain_space_id(space, id); + + return isl_aff_eq_basic_set(aff, aff_id); +} + +/* Wrapper around isl_aff_bind_id for use as pw_aff_locus callback. + * "rational" should not be set. + */ +static __isl_give isl_basic_set *aff_bind_id(__isl_take isl_aff *aff, + int rational, void *user) +{ + isl_id *id = user; + + if (!aff) + return NULL; + if (rational) + isl_die(isl_aff_get_ctx(aff), isl_error_unsupported, + "rational binding not supported", goto error); + return isl_aff_bind_id(aff, isl_id_copy(id)); +error: + isl_aff_free(aff); + return NULL; +} + +/* Bind the piecewise affine function "pa" to the parameter "id", + * returning the elements in the domain where the expression + * is equal to the parameter. + */ +__isl_give isl_set *isl_pw_aff_bind_id(__isl_take isl_pw_aff *pa, + __isl_take isl_id *id) { - return pw_aff_locus(pwaff, &aff_zero_basic_set, 1); + isl_set *bound; + + bound = pw_aff_locus(pa, &aff_bind_id, 0, id); + isl_id_free(id); + + return bound; } /* Return a set containing those elements in the shared domain @@ -2915,9 +3010,9 @@ pwaff1 = isl_pw_aff_add(pwaff1, isl_pw_aff_neg(pwaff2)); if (strict) { - isl_space *dim = isl_set_get_space(set1); + isl_space *space = isl_set_get_space(set1); isl_aff *aff; - aff = isl_aff_zero_on_domain(isl_local_space_from_space(dim)); + aff = isl_aff_zero_on_domain(isl_local_space_from_space(space)); aff = isl_aff_add_constant_si(aff, -1); pwaff1 = isl_pw_aff_add(pwaff1, isl_pw_aff_alloc(set1, aff)); } else @@ -3316,10 +3411,13 @@ isl_bool isl_aff_is_cst(__isl_keep isl_aff *aff) { + int pos; + if (!aff) return isl_bool_error; - return isl_seq_first_non_zero(aff->v->el + 2, aff->v->size - 2) == -1; + pos = isl_seq_first_non_zero(aff->v->el + 2, aff->v->size - 2); + return isl_bool_ok(pos == -1); } /* Check whether pwaff is a piecewise constant. @@ -3350,7 +3448,7 @@ return isl_bool_error; for (i = 0; i < mpa->n; ++i) { - isl_bool is_cst = isl_pw_aff_is_cst(mpa->p[i]); + isl_bool is_cst = isl_pw_aff_is_cst(mpa->u.p[i]); if (is_cst < 0 || !is_cst) return is_cst; } @@ -3822,22 +3920,54 @@ error: isl_space_free(aff_space); return isl_stat_error; +} + +/* Return the shared (universe) domain of the elements of "ma". + * + * Since an isl_multi_aff (and an isl_aff) is always total, + * the domain is always the universe set in its domain space. + * This is a helper function for use in the generic isl_multi_*_bind. + */ +static __isl_give isl_basic_set *isl_multi_aff_domain( + __isl_take isl_multi_aff *ma) +{ + isl_space *space; + + space = isl_multi_aff_get_space(ma); + isl_multi_aff_free(ma); + + return isl_basic_set_universe(isl_space_domain(space)); } #undef BASE #define BASE aff -#undef DOMBASE -#define DOMBASE set -#define NO_DOMAIN +#include #include #include +#include +#include #include +#include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef DOMBASE +#define DOMBASE set #include -#undef NO_DOMAIN +#undef DOMBASE +#define DOMBASE basic_set +#include /* Construct an isl_multi_aff living in "space" that corresponds * to the affine transformation matrix "mat". @@ -3848,7 +3978,7 @@ isl_ctx *ctx; isl_local_space *ls = NULL; isl_multi_aff *ma = NULL; - int n_row, n_col, n_out, total; + isl_size n_row, n_col, n_out, total; int i; if (!space || !mat) @@ -3858,14 +3988,16 @@ n_row = isl_mat_rows(mat); n_col = isl_mat_cols(mat); + n_out = isl_space_dim(space, isl_dim_out); + total = isl_space_dim(space, isl_dim_all); + if (n_row < 0 || n_col < 0 || n_out < 0 || total < 0) + goto error; if (n_row < 1) isl_die(ctx, isl_error_invalid, "insufficient number of rows", goto error); if (n_col < 1) isl_die(ctx, isl_error_invalid, "insufficient number of columns", goto error); - n_out = isl_space_dim(space, isl_dim_out); - total = isl_space_dim(space, isl_dim_all); if (1 + n_out != n_row || 2 + total != n_row + n_col) isl_die(ctx, isl_error_invalid, "dimension mismatch", goto error); @@ -3924,7 +4056,8 @@ */ __isl_give isl_multi_aff *isl_multi_aff_domain_map(__isl_take isl_space *space) { - int i, n_in; + int i; + isl_size n_in; isl_local_space *ls; isl_multi_aff *ma; @@ -3935,6 +4068,8 @@ "not a map space", goto error); n_in = isl_space_dim(space, isl_dim_in); + if (n_in < 0) + goto error; space = isl_space_domain_map(space); ma = isl_multi_aff_alloc(isl_space_copy(space)); @@ -3964,7 +4099,8 @@ */ __isl_give isl_multi_aff *isl_multi_aff_range_map(__isl_take isl_space *space) { - int i, n_in, n_out; + int i; + isl_size n_in, n_out; isl_local_space *ls; isl_multi_aff *ma; @@ -3976,6 +4112,8 @@ n_in = isl_space_dim(space, isl_dim_in); n_out = isl_space_dim(space, isl_dim_out); + if (n_in < 0 || n_out < 0) + goto error; space = isl_space_range_map(space); ma = isl_multi_aff_alloc(isl_space_copy(space)); @@ -4016,7 +4154,8 @@ __isl_take isl_space *space, enum isl_dim_type type, unsigned first, unsigned n) { - int i, dim; + int i; + isl_size dim; isl_local_space *ls; isl_multi_aff *ma; @@ -4028,11 +4167,12 @@ if (type != isl_dim_set) isl_die(isl_space_get_ctx(space), isl_error_invalid, "only set dimensions can be projected out", goto error); + if (isl_space_check_range(space, type, first, n) < 0) + goto error; dim = isl_space_dim(space, isl_dim_set); - if (first + n > dim) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "range out of bounds", goto error); + if (dim < 0) + goto error; space = isl_space_from_domain(space); space = isl_space_add_dims(space, isl_dim_out, dim - n); @@ -4078,16 +4218,6 @@ ma = isl_multi_aff_project_out_map(space, type, first, n); return isl_pw_multi_aff_from_multi_aff(ma); -} - -/* Create an isl_pw_multi_aff with the given isl_multi_aff on a universe - * domain. - */ -__isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_multi_aff( - __isl_take isl_multi_aff *ma) -{ - isl_set *dom = isl_set_universe(isl_multi_aff_get_domain_space(ma)); - return isl_pw_multi_aff_alloc(dom, ma); } /* Create a piecewise multi-affine expression in the given space that maps each @@ -4111,9 +4241,9 @@ goto error; for (i = 0; i < maff->n; ++i) { - maff->p[i] = isl_aff_substitute_equalities(maff->p[i], + maff->u.p[i] = isl_aff_substitute_equalities(maff->u.p[i], isl_basic_set_copy(eq)); - if (!maff->p[i]) + if (!maff->u.p[i]) goto error; } @@ -4135,8 +4265,8 @@ return NULL; for (i = 0; i < maff->n; ++i) { - maff->p[i] = isl_aff_scale(maff->p[i], f); - if (!maff->p[i]) + maff->u.p[i] = isl_aff_scale(maff->u.p[i], f); + if (!maff->u.p[i]) return isl_multi_aff_free(maff); } @@ -4151,12 +4281,12 @@ return maff1; } -int isl_multi_aff_is_empty(__isl_keep isl_multi_aff *maff) +isl_bool isl_multi_aff_is_empty(__isl_keep isl_multi_aff *maff) { if (!maff) - return -1; + return isl_bool_error; - return 0; + return isl_bool_false; } /* Return the set of domain elements where "ma1" is lexicographically @@ -4188,8 +4318,8 @@ isl_map *map1, *map2; isl_map *map, *ge; - map1 = isl_map_from_multi_aff(ma1); - map2 = isl_map_from_multi_aff(ma2); + map1 = isl_map_from_multi_aff_internal(ma1); + map2 = isl_map_from_multi_aff_internal(ma2); map = isl_map_range_product(map1, map2); space = isl_space_range(isl_map_get_space(map)); space = isl_space_domain(isl_space_unwrap(space)); @@ -4216,11 +4346,13 @@ { return isl_multi_aff_order_set(ma1, ma2, &isl_map_lex_gt); } + +#define isl_multi_aff_zero_in_space isl_multi_aff_zero #undef PW #define PW isl_pw_multi_aff -#undef EL -#define EL isl_multi_aff +#undef BASE +#define BASE multi_aff #undef EL_IS_ZERO #define EL_IS_ZERO is_empty #undef ZERO @@ -4233,27 +4365,100 @@ #define DEFAULT_IS_ZERO 0 #define NO_SUB -#define NO_EVAL #define NO_OPT -#define NO_INVOLVES_DIMS #define NO_INSERT_DIMS #define NO_LIFT #define NO_MORPH #include +#include #include #undef NO_SUB -#undef UNION -#define UNION isl_union_pw_multi_aff -#undef PART -#define PART isl_pw_multi_aff -#undef PARTS -#define PARTS pw_multi_aff +#undef BASE +#define BASE pw_multi_aff #include #include + +/* Generic function for extracting a factor from a product "pma". + * "check_space" checks that the space is that of the right kind of product. + * "space_factor" extracts the factor from the space. + * "multi_aff_factor" extracts the factor from the constituent functions. + */ +static __isl_give isl_pw_multi_aff *pw_multi_aff_factor( + __isl_take isl_pw_multi_aff *pma, + isl_stat (*check_space)(__isl_keep isl_pw_multi_aff *pma), + __isl_give isl_space *(*space_factor)(__isl_take isl_space *space), + __isl_give isl_multi_aff *(*multi_aff_factor)( + __isl_take isl_multi_aff *ma)) +{ + int i; + isl_space *space; + + if (check_space(pma) < 0) + return isl_pw_multi_aff_free(pma); + + space = isl_pw_multi_aff_take_space(pma); + space = space_factor(space); + + for (i = 0; pma && i < pma->n; ++i) { + isl_multi_aff *ma; + + ma = isl_pw_multi_aff_take_base_at(pma, i); + ma = multi_aff_factor(ma); + pma = isl_pw_multi_aff_restore_base_at(pma, i, ma); + } + + pma = isl_pw_multi_aff_restore_space(pma, space); + + return pma; +} + +/* Is the range of "pma" a wrapped relation? + */ +static isl_bool isl_pw_multi_aff_range_is_wrapping( + __isl_keep isl_pw_multi_aff *pma) +{ + return isl_space_range_is_wrapping(isl_pw_multi_aff_peek_space(pma)); +} + +/* Check that the range of "pma" is a product. + */ +static isl_stat pw_multi_aff_check_range_product( + __isl_keep isl_pw_multi_aff *pma) +{ + isl_bool wraps; + + wraps = isl_pw_multi_aff_range_is_wrapping(pma); + if (wraps < 0) + return isl_stat_error; + if (!wraps) + isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, + "range is not a product", return isl_stat_error); + return isl_stat_ok; +} + +/* Given a function A -> [B -> C], extract the function A -> B. + */ +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_range_factor_domain( + __isl_take isl_pw_multi_aff *pma) +{ + return pw_multi_aff_factor(pma, &pw_multi_aff_check_range_product, + &isl_space_range_factor_domain, + &isl_multi_aff_range_factor_domain); +} + +/* Given a function A -> [B -> C], extract the function A -> C. + */ +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_range_factor_range( + __isl_take isl_pw_multi_aff *pma) +{ + return pw_multi_aff_factor(pma, &pw_multi_aff_check_range_product, + &isl_space_range_factor_range, + &isl_multi_aff_range_factor_range); +} static __isl_give isl_pw_multi_aff *pw_multi_aff_union_lexmax( __isl_take isl_pw_multi_aff *pma1, @@ -4402,59 +4607,6 @@ { return isl_pw_multi_aff_align_params_pw_pw_and(pma1, pma2, &pw_multi_aff_product); -} - -/* Construct a map mapping the domain of the piecewise multi-affine expression - * to its range, with each dimension in the range equated to the - * corresponding affine expression on its cell. - * - * If the domain of "pma" is rational, then so is the constructed "map". - */ -__isl_give isl_map *isl_map_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma) -{ - int i; - isl_map *map; - - if (!pma) - return NULL; - - map = isl_map_empty(isl_pw_multi_aff_get_space(pma)); - - for (i = 0; i < pma->n; ++i) { - isl_bool rational; - isl_multi_aff *maff; - isl_basic_map *bmap; - isl_map *map_i; - - rational = isl_set_is_rational(pma->p[i].set); - if (rational < 0) - map = isl_map_free(map); - maff = isl_multi_aff_copy(pma->p[i].maff); - bmap = isl_basic_map_from_multi_aff2(maff, rational); - map_i = isl_map_from_basic_map(bmap); - map_i = isl_map_intersect_domain(map_i, - isl_set_copy(pma->p[i].set)); - map = isl_map_union_disjoint(map, map_i); - } - - isl_pw_multi_aff_free(pma); - return map; -} - -__isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma) -{ - if (!pma) - return NULL; - - if (!isl_space_is_set(pma->dim)) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, - "isl_pw_multi_aff cannot be converted into an isl_set", - goto error); - - return isl_map_from_pw_multi_aff(pma); -error: - isl_pw_multi_aff_free(pma); - return NULL; } /* Subtract the initial "n" elements in "ma" with coefficients in "c" and @@ -4566,7 +4718,7 @@ __isl_keep isl_multi_aff *ma) { unsigned o_out; - unsigned n_div, n_out; + isl_size n_div, n_out; isl_ctx *ctx; isl_local_space *ls; isl_aff *aff, *shift; @@ -4581,6 +4733,8 @@ o_out = isl_basic_map_offset(bmap, isl_dim_out); n_out = isl_basic_map_dim(bmap, isl_dim_out); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_out < 0 || n_div < 0) + goto error; if (isl_int_is_neg(bmap->eq[eq][o_out + pos])) { isl_seq_cpy(aff->v->el + 1, bmap->eq[eq], o_out); isl_seq_cpy(aff->v->el + 1 + o_out, @@ -4660,7 +4814,7 @@ __isl_take isl_basic_map *bmap) { int i; - unsigned n_out; + isl_size n_out; isl_multi_aff *ma; if (!bmap) @@ -4668,6 +4822,8 @@ ma = isl_multi_aff_alloc(isl_basic_map_get_space(bmap)); n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (n_out < 0) + ma = isl_multi_aff_free(ma); for (i = 0; i < n_out; ++i) { isl_aff *aff; @@ -4793,15 +4949,15 @@ __isl_take isl_map *map, __isl_take isl_basic_map *hull, int d, int i) { isl_ctx *ctx; - isl_space *space; + isl_space *space = NULL; isl_local_space *ls; isl_multi_aff *ma; isl_aff *aff; isl_vec *v; isl_map *insert; int offset; - int n; - int n_in; + isl_size n; + isl_size n_in; isl_pw_multi_aff *pma; isl_bool is_set; @@ -4814,6 +4970,8 @@ space = isl_space_domain(isl_map_get_space(map)); n_in = isl_space_dim(space, isl_dim_set); n = isl_space_dim(space, isl_dim_all); + if (n_in < 0 || n < 0) + goto error; v = isl_vec_alloc(ctx, 1 + 1 + n); if (v) { @@ -4834,7 +4992,7 @@ isl_multi_aff_from_aff(aff)); } - insert = isl_map_from_multi_aff(isl_multi_aff_copy(ma)); + insert = isl_map_from_multi_aff_internal(isl_multi_aff_copy(ma)); map = isl_map_apply_domain(map, insert); map = isl_map_equate(map, isl_dim_in, n_in, isl_dim_out, d); pma = isl_pw_multi_aff_from_map(map); @@ -4842,6 +5000,7 @@ return pma; error: + isl_space_free(space); isl_map_free(map); isl_basic_map_free(hull); return NULL; @@ -4912,29 +5071,31 @@ static __isl_give isl_pw_multi_aff *pw_multi_aff_from_map_check_div( __isl_take isl_map *map) { - int d, dim; + int d; + isl_size dim; int i, j, n; - int offset, total; + int offset; + isl_size total; isl_int sum; isl_basic_map *hull; hull = isl_map_unshifted_simple_hull(isl_map_copy(map)); - if (!hull) + dim = isl_map_dim(map, isl_dim_out); + total = isl_basic_map_dim(hull, isl_dim_all); + if (dim < 0 || total < 0) goto error; isl_int_init(sum); - dim = isl_map_dim(map, isl_dim_out); offset = isl_basic_map_offset(hull, isl_dim_out); - total = 1 + isl_basic_map_total_dim(hull); n = hull->n_ineq; for (d = 0; d < dim; ++d) { for (i = 0; i < n; ++i) { if (!is_potential_div_constraint(hull->ineq[i], - offset, d, total)) + offset, d, 1 + total)) continue; for (j = i + 1; j < n; ++j) { if (!isl_seq_is_neg(hull->ineq[i] + 1, - hull->ineq[j] + 1, total - 1)) + hull->ineq[j] + 1, total)) continue; isl_int_add(sum, hull->ineq[i][0], hull->ineq[j][0]); @@ -5077,9 +5238,9 @@ isl_aff *aff; isl_multi_aff *ma; isl_pw_multi_aff *pma, *id; - unsigned n_in; + isl_size n_in; unsigned o_out; - unsigned n_out; + isl_size n_out; isl_bool is_set; is_set = isl_map_is_set(map); @@ -5088,6 +5249,8 @@ n_in = isl_basic_map_dim(hull, isl_dim_in); n_out = isl_basic_map_dim(hull, isl_dim_out); + if (n_in < 0 || n_out < 0) + goto error; o_out = isl_basic_map_offset(hull, isl_dim_out); if (is_set) @@ -5155,14 +5318,16 @@ __isl_take isl_map *map, __isl_take isl_basic_map *hull) { int i, j; - unsigned n_out; + isl_size n_out; unsigned o_out; - unsigned n_div; + isl_size n_div; unsigned o_div; isl_int gcd; n_div = isl_basic_map_dim(hull, isl_dim_div); - o_div = isl_basic_map_offset(hull, isl_dim_div); + n_out = isl_basic_map_dim(hull, isl_dim_out); + if (n_div < 0 || n_out < 0) + goto error; if (n_div == 0) { isl_basic_map_free(hull); @@ -5171,7 +5336,7 @@ isl_int_init(gcd); - n_out = isl_basic_map_dim(hull, isl_dim_out); + o_div = isl_basic_map_offset(hull, isl_dim_div); o_out = isl_basic_map_offset(hull, isl_dim_out); for (i = 0; i < n_out; ++i) { @@ -5203,6 +5368,10 @@ isl_int_clear(gcd); isl_basic_map_free(hull); return pw_multi_aff_from_map_check_div(map); +error: + isl_map_free(map); + isl_basic_map_free(hull); + return NULL; } /* Try and create an isl_pw_multi_aff that is equivalent to the given isl_map. @@ -5218,12 +5387,14 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map) { isl_bool sv; + isl_size n; isl_basic_map *hull; - if (!map) - return NULL; + n = isl_map_n_basic_map(map); + if (n < 0) + goto error; - if (isl_map_n_basic_map(map) == 1) { + if (n == 1) { hull = isl_map_unshifted_simple_hull(isl_map_copy(map)); hull = isl_basic_map_plain_affine_hull(hull); sv = isl_basic_map_plain_is_single_valued(hull); @@ -5240,6 +5411,7 @@ if (sv >= 0) return pw_multi_aff_from_map_check_strides(map, hull); isl_basic_map_free(hull); +error: isl_map_free(map); return NULL; } @@ -5348,6 +5520,7 @@ { isl_ctx *ctx; isl_int v; + isl_size n_div; aff = isl_aff_cow(aff); if (!aff || !subs) @@ -5357,7 +5530,10 @@ if (!isl_space_is_equal(aff->ls->dim, subs->ls->dim)) isl_die(ctx, isl_error_invalid, "spaces don't match", return isl_aff_free(aff)); - if (isl_local_space_dim(subs->ls, isl_dim_div) != 0) + n_div = isl_aff_domain_dim(subs, isl_dim_div); + if (n_div < 0) + return isl_aff_free(aff); + if (n_div != 0) isl_die(ctx, isl_error_unsupported, "cannot handle divs yet", return isl_aff_free(aff)); @@ -5396,8 +5572,9 @@ type = isl_dim_set; for (i = 0; i < maff->n; ++i) { - maff->p[i] = isl_aff_substitute(maff->p[i], type, pos, subs); - if (!maff->p[i]) + maff->u.p[i] = isl_aff_substitute(maff->u.p[i], + type, pos, subs); + if (!maff->u.p[i]) return isl_multi_aff_free(maff); } @@ -5506,18 +5683,20 @@ * The multiplication factor f also needs to be multiplied by c_1 * for the next x_j, j > i. */ -void isl_seq_preimage(isl_int *dst, isl_int *src, +isl_stat isl_seq_preimage(isl_int *dst, isl_int *src, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div_ma, int n_div_bmap, isl_int f, isl_int c1, isl_int c2, isl_int g, int has_denom) { int i; - int n_param, n_in, n_out; + isl_size n_param, n_in, n_out; int o_dst, o_src; n_param = isl_multi_aff_dim(ma, isl_dim_param); n_in = isl_multi_aff_dim(ma, isl_dim_in); n_out = isl_multi_aff_dim(ma, isl_dim_out); + if (n_param < 0 || n_in < 0 || n_out < 0) + return isl_stat_error; isl_seq_cpy(dst, src, has_denom + 1 + n_param + n_before); o_dst = o_src = has_denom + 1 + n_param + n_before; @@ -5538,7 +5717,7 @@ if (isl_int_is_zero(src[offset])) continue; - isl_int_set(c1, ma->p[i]->v->el[0]); + isl_int_set(c1, ma->u.p[i]->v->el[0]); isl_int_mul(c2, f, src[offset]); isl_int_gcd(g, c1, c2); isl_int_divexact(c1, c1, g); @@ -5548,25 +5727,27 @@ o_dst = has_denom; o_src = 1; isl_seq_combine(dst + o_dst, c1, dst + o_dst, - c2, ma->p[i]->v->el + o_src, 1 + n_param); + c2, ma->u.p[i]->v->el + o_src, 1 + n_param); o_dst += 1 + n_param; o_src += 1 + n_param; isl_seq_scale(dst + o_dst, dst + o_dst, c1, n_before); o_dst += n_before; isl_seq_combine(dst + o_dst, c1, dst + o_dst, - c2, ma->p[i]->v->el + o_src, n_in); + c2, ma->u.p[i]->v->el + o_src, n_in); o_dst += n_in; o_src += n_in; isl_seq_scale(dst + o_dst, dst + o_dst, c1, n_after); o_dst += n_after; isl_seq_combine(dst + o_dst, c1, dst + o_dst, - c2, ma->p[i]->v->el + o_src, n_div_ma); + c2, ma->u.p[i]->v->el + o_src, n_div_ma); o_dst += n_div_ma; o_src += n_div_ma; isl_seq_scale(dst + o_dst, dst + o_dst, c1, n_div_bmap); if (has_denom) isl_int_mul(dst[0], dst[0], c1); } + + return isl_stat_ok; } /* Compute the pullback of "aff" by the function represented by "ma". @@ -5593,7 +5774,7 @@ { isl_aff *res = NULL; isl_local_space *ls; - int n_div_aff, n_div_ma; + isl_size n_div_aff, n_div_ma; isl_int f, c1, c2, g; ma = isl_multi_aff_align_divs(ma); @@ -5601,7 +5782,9 @@ goto error; n_div_aff = isl_aff_dim(aff, isl_dim_div); - n_div_ma = ma->n ? isl_aff_dim(ma->p[0], isl_dim_div) : 0; + n_div_ma = ma->n ? isl_aff_dim(ma->u.p[0], isl_dim_div) : 0; + if (n_div_aff < 0 || n_div_ma < 0) + goto error; ls = isl_aff_get_domain_local_space(aff); ls = isl_local_space_preimage_multi_aff(ls, isl_multi_aff_copy(ma)); @@ -5614,8 +5797,9 @@ isl_int_init(c2); isl_int_init(g); - isl_seq_preimage(res->v->el, aff->v->el, ma, 0, 0, n_div_ma, n_div_aff, - f, c1, c2, g, 1); + if (isl_seq_preimage(res->v->el, aff->v->el, ma, 0, 0, + n_div_ma, n_div_aff, f, c1, c2, g, 1) < 0) + res = isl_aff_free(res); isl_int_clear(f); isl_int_clear(c1); @@ -5669,9 +5853,9 @@ isl_multi_aff_get_space(ma1)); for (i = 0; i < ma1->n; ++i) { - ma1->p[i] = isl_aff_pullback_multi_aff(ma1->p[i], + ma1->u.p[i] = isl_aff_pullback_multi_aff(ma1->u.p[i], isl_multi_aff_copy(ma2)); - if (!ma1->p[i]) + if (!ma1->u.p[i]) goto error; } @@ -5705,7 +5889,7 @@ __isl_keep isl_aff *src) { isl_ctx *ctx; - int src_n_div, dst_n_div; + isl_size src_n_div, dst_n_div; int *exp1 = NULL; int *exp2 = NULL; isl_bool equal; @@ -5722,16 +5906,16 @@ isl_die(ctx, isl_error_invalid, "spaces don't match", goto error); - src_n_div = isl_local_space_dim(src->ls, isl_dim_div); + src_n_div = isl_aff_domain_dim(src, isl_dim_div); + dst_n_div = isl_aff_domain_dim(dst, isl_dim_div); if (src_n_div == 0) return dst; equal = isl_local_space_is_equal(src->ls, dst->ls); - if (equal < 0) + if (equal < 0 || src_n_div < 0 || dst_n_div < 0) return isl_aff_free(dst); if (equal) return dst; - dst_n_div = isl_local_space_dim(dst->ls, isl_dim_div); exp1 = isl_alloc_array(ctx, int, src_n_div); exp2 = isl_alloc_array(ctx, int, dst_n_div); if (!exp1 || (dst_n_div && !exp2)) @@ -5766,10 +5950,10 @@ return NULL; for (i = 1; i < maff->n; ++i) - maff->p[0] = isl_aff_align_divs(maff->p[0], maff->p[i]); + maff->u.p[0] = isl_aff_align_divs(maff->u.p[0], maff->u.p[i]); for (i = 1; i < maff->n; ++i) { - maff->p[i] = isl_aff_align_divs(maff->p[i], maff->p[0]); - if (!maff->p[i]) + maff->u.p[i] = isl_aff_align_divs(maff->u.p[i], maff->u.p[0]); + if (!maff->u.p[i]) return isl_multi_aff_free(maff); } @@ -5799,7 +5983,7 @@ { int i; isl_space *space; - unsigned n_div; + isl_size n_div; if (ls) *ls = NULL; @@ -5822,7 +6006,9 @@ if (!maff) return NULL; - n_div = isl_aff_dim(maff->p[0], isl_dim_div); + n_div = isl_aff_dim(maff->u.p[0], isl_dim_div); + if (n_div < 0) + return isl_multi_aff_free(maff); space = isl_multi_aff_get_space(maff); space = isl_space_lift(isl_space_domain(space), n_div); space = isl_space_extend_domain_with_range(space, @@ -5833,14 +6019,14 @@ maff->space = space; if (ls) { - *ls = isl_aff_get_domain_local_space(maff->p[0]); + *ls = isl_aff_get_domain_local_space(maff->u.p[0]); if (!*ls) return isl_multi_aff_free(maff); } for (i = 0; i < maff->n; ++i) { - maff->p[i] = isl_aff_lift(maff->p[i]); - if (!maff->p[i]) + maff->u.p[i] = isl_aff_lift(maff->u.p[i]); + if (!maff->u.p[i]) goto error; } @@ -5851,6 +6037,10 @@ return isl_multi_aff_free(maff); } +#undef TYPE +#define TYPE isl_pw_multi_aff +static +#include "check_type_range_templ.c" /* Extract an isl_pw_aff corresponding to output dimension "pos" of "pma". */ @@ -5858,17 +6048,16 @@ __isl_keep isl_pw_multi_aff *pma, int pos) { int i; - int n_out; + isl_size n_out; isl_space *space; isl_pw_aff *pa; - if (!pma) + if (isl_pw_multi_aff_check_range(pma, isl_dim_out, pos, 1) < 0) return NULL; n_out = isl_pw_multi_aff_dim(pma, isl_dim_out); - if (pos < 0 || pos >= n_out) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, - "index out of bounds", return NULL); + if (n_out < 0) + return NULL; space = isl_pw_multi_aff_get_space(pma); space = isl_space_drop_dims(space, isl_dim_out, @@ -5938,49 +6127,7 @@ return upma; error: isl_union_set_free(uset); - isl_union_pw_multi_aff_free(upma); - return NULL; -} - -/* Convert "pma" to an isl_map and add it to *umap. - */ -static isl_stat map_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma, - void *user) -{ - isl_union_map **umap = user; - isl_map *map; - - map = isl_map_from_pw_multi_aff(pma); - *umap = isl_union_map_add_map(*umap, map); - - return isl_stat_ok; -} - -/* Construct a union map mapping the domain of the union - * piecewise multi-affine expression to its range, with each dimension - * in the range equated to the corresponding affine expression on its cell. - */ -__isl_give isl_union_map *isl_union_map_from_union_pw_multi_aff( - __isl_take isl_union_pw_multi_aff *upma) -{ - isl_space *space; - isl_union_map *umap; - - if (!upma) - return NULL; - - space = isl_union_pw_multi_aff_get_space(upma); - umap = isl_union_map_empty(space); - - if (isl_union_pw_multi_aff_foreach_pw_multi_aff(upma, - &map_from_pw_multi_aff, &umap) < 0) - goto error; - isl_union_pw_multi_aff_free(upma); - return umap; -error: - isl_union_pw_multi_aff_free(upma); - isl_union_map_free(umap); return NULL; } @@ -6147,9 +6294,8 @@ pa->dim, isl_dim_in)) isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, "domains don't match", goto error); - if (pos >= isl_pw_multi_aff_dim(pma, isl_dim_out)) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, - "index out of bounds", goto error); + if (isl_pw_multi_aff_check_range(pma, isl_dim_out, pos, 1) < 0) + goto error; n = pma->n * pa->n; res = isl_pw_multi_aff_alloc_size(isl_pw_multi_aff_get_space(pma), n); @@ -6204,10 +6350,9 @@ goto error; if (equal_params) return pw_multi_aff_set_pw_aff(pma, pos, pa); - if (!isl_space_has_named_params(pma->dim) || - !isl_space_has_named_params(pa->dim)) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (isl_pw_multi_aff_check_named_params(pma) < 0 || + isl_pw_aff_check_named_params(pa) < 0) + goto error; pma = isl_pw_multi_aff_align_params(pma, isl_pw_aff_get_space(pa)); pa = isl_pw_aff_align_params(pa, isl_pw_multi_aff_get_space(pma)); return pw_multi_aff_set_pw_aff(pma, pos, pa); @@ -6274,13 +6419,45 @@ #undef DOMBASE #define DOMBASE set +#include +#include #include #include +#include +#include +#include #include +#include +#include #include +#include #include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include + +/* Does "mpa" have a non-trivial explicit domain? + * + * The explicit domain, if present, is trivial if it represents + * an (obviously) universe set. + */ +isl_bool isl_multi_pw_aff_has_non_trivial_domain( + __isl_keep isl_multi_pw_aff *mpa) +{ + if (!mpa) + return isl_bool_error; + if (!isl_multi_pw_aff_has_explicit_domain(mpa)) + return isl_bool_false; + return isl_bool_not(isl_set_plain_is_universe(mpa->u.dom)); +} /* Scale the elements of "pma" by the corresponding elements of "mv". */ @@ -6352,6 +6529,11 @@ __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_scale_multi_val( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_multi_val *mv) { + struct isl_union_pw_multi_aff_transform_control control = { + .fn = &union_pw_multi_aff_scale_multi_val_entry, + .fn_user = mv, + }; + upma = isl_union_pw_multi_aff_align_params(upma, isl_multi_val_get_space(mv)); mv = isl_multi_val_align_params(mv, @@ -6359,8 +6541,7 @@ if (!upma || !mv) goto error; - return isl_union_pw_multi_aff_transform(upma, - &union_pw_multi_aff_scale_multi_val_entry, mv); + return isl_union_pw_multi_aff_transform(upma, &control); isl_multi_val_free(mv); return upma; @@ -6408,83 +6589,27 @@ return pma; } -/* Construct a set or map mapping the shared (parameter) domain - * of the piecewise affine expressions to the range of "mpa" - * with each dimension in the range equated to the - * corresponding piecewise affine expression. +/* Construct and return a piecewise multi affine expression + * that is equal to the given multi piecewise affine expression + * on the shared domain of the piecewise affine expressions, + * in the special case of a 0D multi piecewise affine expression. + * + * Create a piecewise multi affine expression with the explicit domain of + * the 0D multi piecewise affine expression as domain. */ -static __isl_give isl_map *map_from_multi_pw_aff( +static __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_multi_pw_aff_0D( __isl_take isl_multi_pw_aff *mpa) { - int i; isl_space *space; - isl_map *map; - - if (!mpa) - return NULL; - - if (isl_space_dim(mpa->space, isl_dim_out) != mpa->n) - isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal, - "invalid space", goto error); - - space = isl_multi_pw_aff_get_domain_space(mpa); - map = isl_map_universe(isl_space_from_domain(space)); - - for (i = 0; i < mpa->n; ++i) { - isl_pw_aff *pa; - isl_map *map_i; - - pa = isl_pw_aff_copy(mpa->p[i]); - map_i = map_from_pw_aff(pa); - - map = isl_map_flat_range_product(map, map_i); - } - - map = isl_map_reset_space(map, isl_multi_pw_aff_get_space(mpa)); - - isl_multi_pw_aff_free(mpa); - return map; -error: - isl_multi_pw_aff_free(mpa); - return NULL; -} + isl_set *dom; + isl_multi_aff *ma; -/* Construct a map mapping the shared domain - * of the piecewise affine expressions to the range of "mpa" - * with each dimension in the range equated to the - * corresponding piecewise affine expression. - */ -__isl_give isl_map *isl_map_from_multi_pw_aff(__isl_take isl_multi_pw_aff *mpa) -{ - if (!mpa) - return NULL; - if (isl_space_is_set(mpa->space)) - isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal, - "space of input is not a map", goto error); - - return map_from_multi_pw_aff(mpa); -error: + space = isl_multi_pw_aff_get_space(mpa); + dom = isl_multi_pw_aff_get_explicit_domain(mpa); isl_multi_pw_aff_free(mpa); - return NULL; -} -/* Construct a set mapping the shared parameter domain - * of the piecewise affine expressions to the space of "mpa" - * with each dimension in the range equated to the - * corresponding piecewise affine expression. - */ -__isl_give isl_set *isl_set_from_multi_pw_aff(__isl_take isl_multi_pw_aff *mpa) -{ - if (!mpa) - return NULL; - if (!isl_space_is_set(mpa->space)) - isl_die(isl_multi_pw_aff_get_ctx(mpa), isl_error_internal, - "space of input is not a set", goto error); - - return map_from_multi_pw_aff(mpa); -error: - isl_multi_pw_aff_free(mpa); - return NULL; + ma = isl_multi_aff_zero(space); + return isl_pw_multi_aff_alloc(dom, ma); } /* Construct and return a piecewise multi affine expression @@ -6501,14 +6626,11 @@ if (!mpa) return NULL; - - space = isl_multi_pw_aff_get_space(mpa); - if (mpa->n == 0) { - isl_multi_pw_aff_free(mpa); - return isl_pw_multi_aff_zero(space); - } + if (mpa->n == 0) + return isl_pw_multi_aff_from_multi_pw_aff_0D(mpa); + space = isl_multi_pw_aff_get_space(mpa); pa = isl_multi_pw_aff_get_pw_aff(mpa, 0); pma = isl_pw_multi_aff_from_pw_aff(pa); @@ -6532,13 +6654,16 @@ __isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_multi_aff( __isl_take isl_multi_aff *ma) { - int i, n; + int i; + isl_size n; isl_multi_pw_aff *mpa; + n = isl_multi_aff_dim(ma, isl_dim_out); + if (n < 0) + ma = isl_multi_aff_free(ma); if (!ma) return NULL; - n = isl_multi_aff_dim(ma, isl_dim_out); mpa = isl_multi_pw_aff_alloc(isl_multi_aff_get_space(ma)); for (i = 0; i < n; ++i) { @@ -6554,18 +6679,22 @@ /* Construct and return a multi piecewise affine expression * that is equal to the given piecewise multi affine expression. + * + * If the resulting multi piecewise affine expression has + * an explicit domain, then assign it the domain of the input. + * In other cases, the domain is stored in the individual elements. */ __isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_pw_multi_aff( __isl_take isl_pw_multi_aff *pma) { - int i, n; + int i; + isl_size n; isl_space *space; isl_multi_pw_aff *mpa; - if (!pma) - return NULL; - n = isl_pw_multi_aff_dim(pma, isl_dim_out); + if (n < 0) + pma = isl_pw_multi_aff_free(pma); space = isl_pw_multi_aff_get_space(pma); mpa = isl_multi_pw_aff_alloc(space); @@ -6574,6 +6703,12 @@ pa = isl_pw_multi_aff_get_pw_aff(pma, i); mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, pa); + } + if (isl_multi_pw_aff_has_explicit_domain(mpa)) { + isl_set *dom; + + dom = isl_pw_multi_aff_domain(isl_pw_multi_aff_copy(pma)); + mpa = isl_multi_pw_aff_intersect_domain(mpa, dom); } isl_pw_multi_aff_free(pma); @@ -6608,8 +6743,8 @@ if (has_nan) return isl_bool_false; - map1 = map_from_pw_aff(isl_pw_aff_copy(pa1)); - map2 = map_from_pw_aff(isl_pw_aff_copy(pa2)); + map1 = isl_map_from_pw_aff_internal(isl_pw_aff_copy(pa1)); + map2 = isl_map_from_pw_aff_internal(isl_pw_aff_copy(pa2)); equal = isl_map_is_equal(map1, map2); isl_map_free(map1); isl_map_free(map2); @@ -6657,7 +6792,7 @@ return equal; for (i = 0; i < mpa1->n; ++i) { - equal = isl_pw_aff_is_equal(mpa1->p[i], mpa2->p[i]); + equal = isl_pw_aff_is_equal(mpa1->u.p[i], mpa2->u.p[i]); if (equal < 0 || !equal) return equal; } @@ -6706,6 +6841,9 @@ * In other words, plug in "ma" in "mpa". * * The parameters of "mpa" and "ma" are assumed to have been aligned. + * + * If "mpa" has an explicit domain, then it is this domain + * that needs to undergo a pullback, i.e., a preimage. */ static __isl_give isl_multi_pw_aff *isl_multi_pw_aff_pullback_multi_aff_aligned( __isl_take isl_multi_pw_aff *mpa, __isl_take isl_multi_aff *ma) @@ -6723,9 +6861,15 @@ goto error; for (i = 0; i < mpa->n; ++i) { - mpa->p[i] = isl_pw_aff_pullback_multi_aff(mpa->p[i], + mpa->u.p[i] = isl_pw_aff_pullback_multi_aff(mpa->u.p[i], isl_multi_aff_copy(ma)); - if (!mpa->p[i]) + if (!mpa->u.p[i]) + goto error; + } + if (isl_multi_pw_aff_has_explicit_domain(mpa)) { + mpa->u.dom = isl_set_preimage_multi_aff(mpa->u.dom, + isl_multi_aff_copy(ma)); + if (!mpa->u.dom) goto error; } @@ -6768,6 +6912,9 @@ * In other words, plug in "pma" in "mpa". * * The parameters of "mpa" and "mpa" are assumed to have been aligned. + * + * If "mpa" has an explicit domain, then it is this domain + * that needs to undergo a pullback, i.e., a preimage. */ static __isl_give isl_multi_pw_aff * isl_multi_pw_aff_pullback_pw_multi_aff_aligned( @@ -6784,9 +6931,15 @@ isl_multi_pw_aff_get_space(mpa)); for (i = 0; i < mpa->n; ++i) { - mpa->p[i] = isl_pw_aff_pullback_pw_multi_aff_aligned(mpa->p[i], + mpa->u.p[i] = isl_pw_aff_pullback_pw_multi_aff_aligned( + mpa->u.p[i], isl_pw_multi_aff_copy(pma)); + if (!mpa->u.p[i]) + goto error; + } + if (isl_multi_pw_aff_has_explicit_domain(mpa)) { + mpa->u.dom = isl_set_preimage_pw_multi_aff(mpa->u.dom, isl_pw_multi_aff_copy(pma)); - if (!mpa->p[i]) + if (!mpa->u.dom) goto error; } @@ -6840,7 +6993,8 @@ static __isl_give isl_pw_aff *isl_multi_pw_aff_apply_aff_aligned( __isl_take isl_multi_pw_aff *mpa, __isl_take isl_aff *aff) { - int i, n_in, n_div; + int i; + isl_size n_in, n_div, n_mpa_in; isl_space *space; isl_val *v; isl_pw_aff *pa; @@ -6848,13 +7002,15 @@ n_in = isl_aff_dim(aff, isl_dim_in); n_div = isl_aff_dim(aff, isl_dim_div); + n_mpa_in = isl_multi_pw_aff_dim(mpa, isl_dim_in); + if (n_in < 0 || n_div < 0 || n_mpa_in < 0) + goto error; space = isl_space_domain(isl_multi_pw_aff_get_space(mpa)); tmp = isl_aff_copy(aff); tmp = isl_aff_drop_dims(tmp, isl_dim_div, 0, n_div); tmp = isl_aff_drop_dims(tmp, isl_dim_in, 0, n_in); - tmp = isl_aff_add_dims(tmp, isl_dim_in, - isl_space_dim(space, isl_dim_set)); + tmp = isl_aff_add_dims(tmp, isl_dim_in, n_mpa_in); tmp = isl_aff_reset_domain_space(tmp, space); pa = isl_pw_aff_from_aff(tmp); @@ -6888,6 +7044,10 @@ isl_aff_free(aff); return pa; +error: + isl_multi_pw_aff_free(mpa); + isl_aff_free(aff); + return NULL; } /* Apply "aff" to "mpa". The range of "mpa" needs to be compatible @@ -7019,6 +7179,9 @@ * The parameters of "mpa1" and "mpa2" are assumed to have been aligned. * * We pullback each member of "mpa1" in turn. + * + * If "mpa1" has an explicit domain, then it is this domain + * that needs to undergo a pullback instead, i.e., a preimage. */ static __isl_give isl_multi_pw_aff * isl_multi_pw_aff_pullback_multi_pw_aff_aligned( @@ -7035,12 +7198,18 @@ isl_multi_pw_aff_get_space(mpa1)); for (i = 0; i < mpa1->n; ++i) { - mpa1->p[i] = isl_pw_aff_pullback_multi_pw_aff_aligned( - mpa1->p[i], isl_multi_pw_aff_copy(mpa2)); - if (!mpa1->p[i]) + mpa1->u.p[i] = isl_pw_aff_pullback_multi_pw_aff_aligned( + mpa1->u.p[i], isl_multi_pw_aff_copy(mpa2)); + if (!mpa1->u.p[i]) goto error; } + if (isl_multi_pw_aff_has_explicit_domain(mpa1)) { + mpa1->u.dom = isl_set_preimage_multi_pw_aff(mpa1->u.dom, + isl_multi_pw_aff_copy(mpa2)); + if (!mpa1->u.dom) + goto error; + } mpa1 = isl_multi_pw_aff_reset_space(mpa1, space); isl_multi_pw_aff_free(mpa2); @@ -7114,12 +7283,15 @@ __isl_keep isl_multi_pw_aff *mpa1, __isl_keep isl_multi_pw_aff *mpa2, __isl_take isl_space *space) { - int i, n; + int i; + isl_size n; isl_map *res; + n = isl_multi_pw_aff_dim(mpa1, isl_dim_out); + if (n < 0) + space = isl_space_free(space); res = isl_map_universe(space); - n = isl_multi_pw_aff_dim(mpa1, isl_dim_out); for (i = 0; i < n; ++i) { isl_pw_aff *pa1, *pa2; isl_map *map; @@ -7144,7 +7316,7 @@ } /* Return a map containing pairs of elements in the domains of "mpa1" and "mpa2" - * where the function values of "mpa1" is lexicographically satisfies "base" + * where the function values of "mpa1" lexicographically satisfies "base" * compared to that of "mpa2". "space" is the space of the result. * The parameters of "mpa1" and "mpa2" are assumed to have been aligned. * @@ -7159,13 +7331,16 @@ __isl_take isl_pw_aff *pa2), __isl_take isl_space *space) { - int i, n; + int i; + isl_size n; isl_map *res, *rest; + n = isl_multi_pw_aff_dim(mpa1, isl_dim_out); + if (n < 0) + space = isl_space_free(space); res = isl_map_empty(isl_space_copy(space)); rest = isl_map_universe(space); - n = isl_multi_pw_aff_dim(mpa1, isl_dim_out); for (i = 0; i < n; ++i) { isl_pw_aff *pa1, *pa2; isl_map *map; @@ -7331,6 +7506,23 @@ space = isl_set_get_space(domain); ls = isl_local_space_from_space(space); aff = isl_aff_val_on_domain(ls, v); + + return isl_pw_aff_alloc(domain, aff); +} + +/* Return a piecewise affine expression that is equal to the parameter + * with identifier "id" on "domain". + */ +__isl_give isl_pw_aff *isl_pw_aff_param_on_domain_id( + __isl_take isl_set *domain, __isl_take isl_id *id) +{ + isl_space *space; + isl_aff *aff; + + space = isl_set_get_space(domain); + space = isl_space_add_param_id(space, isl_id_copy(id)); + domain = isl_set_align_params(domain, isl_space_copy(space)); + aff = isl_aff_param_on_domain_space_id(space, id); return isl_pw_aff_alloc(domain, aff); } @@ -7341,15 +7533,16 @@ __isl_give isl_multi_aff *isl_multi_aff_multi_val_on_space( __isl_take isl_space *space, __isl_take isl_multi_val *mv) { - int i, n; + int i; + isl_size n; isl_space *space2; isl_local_space *ls; isl_multi_aff *ma; - if (!space || !mv) + n = isl_multi_val_dim(mv, isl_dim_set); + if (!space || n < 0) goto error; - n = isl_multi_val_dim(mv, isl_dim_set); space2 = isl_multi_val_get_space(mv); space2 = isl_space_align_params(space2, isl_space_copy(space)); space = isl_space_align_params(space, isl_space_copy(space2)); @@ -7492,7 +7685,7 @@ return isl_stat_error; if (!match) isl_die(isl_space_get_ctx(space), isl_error_invalid, - "expecting set space", return -1); + "expecting set space", return isl_stat_error); upa_space = isl_union_pw_aff_get_space(upa); match = isl_space_has_equal_params(space, upa_space); @@ -7647,13 +7840,12 @@ static isl_stat get_union_pw_aff(__isl_take isl_pw_multi_aff *pma, void *user) { struct isl_union_pw_multi_aff_get_union_pw_aff_data *data = user; - int n_out; + isl_size n_out; isl_pw_aff *pa; - - if (!pma) - return isl_stat_error; n_out = isl_pw_multi_aff_dim(pma, isl_dim_out); + if (n_out < 0) + return isl_stat_error; if (data->pos >= n_out) { isl_pw_multi_aff_free(pma); return isl_stat_ok; @@ -7740,10 +7932,12 @@ { struct isl_union_pw_aff_pw_aff_on_domain_data *data = user; isl_pw_aff *pa; - int dim; + isl_size dim; pa = isl_pw_aff_copy(data->pa); dim = isl_set_dim(domain, isl_dim_set); + if (dim < 0) + pa = isl_pw_aff_free(pa); pa = isl_pw_aff_from_range(pa); pa = isl_pw_aff_add_dims(pa, isl_dim_in, dim); pa = isl_pw_aff_reset_domain_space(pa, isl_set_get_space(domain)); @@ -7933,42 +8127,47 @@ isl_union_pw_aff_free(upa); return zero; } + +/* Internal data structure for isl_union_pw_aff_bind_id, + * storing the parameter that needs to be bound and + * the accumulated results. + */ +struct isl_bind_id_data { + isl_id *id; + isl_union_set *bound; +}; -/* Convert "pa" to an isl_map and add it to *umap. +/* Bind the piecewise affine function "pa" to the parameter data->id, + * adding the resulting elements in the domain where the expression + * is equal to the parameter to data->bound. */ -static isl_stat map_from_pw_aff_entry(__isl_take isl_pw_aff *pa, void *user) +static isl_stat bind_id(__isl_take isl_pw_aff *pa, void *user) { - isl_union_map **umap = user; - isl_map *map; + struct isl_bind_id_data *data = user; + isl_set *bound; - map = isl_map_from_pw_aff(pa); - *umap = isl_union_map_add_map(*umap, map); + bound = isl_pw_aff_bind_id(pa, isl_id_copy(data->id)); + data->bound = isl_union_set_add_set(data->bound, bound); - return *umap ? isl_stat_ok : isl_stat_error; + return data->bound ? isl_stat_ok : isl_stat_error; } -/* Construct a union map mapping the domain of the union - * piecewise affine expression to its range, with the single output dimension - * equated to the corresponding affine expressions on their cells. +/* Bind the union piecewise affine function "upa" to the parameter "id", + * returning the elements in the domain where the expression + * is equal to the parameter. */ -__isl_give isl_union_map *isl_union_map_from_union_pw_aff( - __isl_take isl_union_pw_aff *upa) +__isl_give isl_union_set *isl_union_pw_aff_bind_id( + __isl_take isl_union_pw_aff *upa, __isl_take isl_id *id) { - isl_space *space; - isl_union_map *umap; + struct isl_bind_id_data data = { id }; - if (!upa) - return NULL; + data.bound = isl_union_set_empty(isl_union_pw_aff_get_space(upa)); + if (isl_union_pw_aff_foreach_pw_aff(upa, &bind_id, &data) < 0) + data.bound = isl_union_set_free(data.bound); - space = isl_union_pw_aff_get_space(upa); - umap = isl_union_map_empty(space); - - if (isl_union_pw_aff_foreach_pw_aff(upa, &map_from_pw_aff_entry, - &umap) < 0) - umap = isl_union_map_free(umap); - isl_union_pw_aff_free(upa); - return umap; + isl_id_free(id); + return data.bound; } /* Internal data structure for isl_union_pw_aff_pullback_union_pw_multi_aff. @@ -8063,22 +8262,48 @@ #define BASE union_pw_aff #undef DOMBASE #define DOMBASE union_set - -#define NO_MOVE_DIMS -#define NO_DOMAIN -#define NO_PRODUCT -#define NO_SPLICE -#define NO_ZERO -#define NO_IDENTITY -#define NO_GIST +#include +#include #include #include #include +#include +#include #include +#include #include +#include #include +#include +#include #include +#include +#include + +/* Does "mupa" have a non-trivial explicit domain? + * + * The explicit domain, if present, is trivial if it represents + * an (obviously) universe parameter set. + */ +isl_bool isl_multi_union_pw_aff_has_non_trivial_domain( + __isl_keep isl_multi_union_pw_aff *mupa) +{ + isl_bool is_params, trivial; + isl_set *set; + + if (!mupa) + return isl_bool_error; + if (!isl_multi_union_pw_aff_has_explicit_domain(mupa)) + return isl_bool_false; + is_params = isl_union_set_is_params(mupa->u.dom); + if (is_params < 0 || !is_params) + return isl_bool_not(is_params); + set = isl_set_from_union_set(isl_union_set_copy(mupa->u.dom)); + trivial = isl_set_plain_is_universe(set); + isl_set_free(set); + return isl_bool_not(trivial); +} /* Construct a multiple union piecewise affine expression * in the given space with value zero in each of the output dimensions. @@ -8091,6 +8316,7 @@ __isl_take isl_space *space) { isl_bool params; + isl_size dim; if (!space) return NULL; @@ -8104,7 +8330,10 @@ if (!isl_space_is_set(space)) isl_die(isl_space_get_ctx(space), isl_error_invalid, "expecting set space", goto error); - if (isl_space_dim(space , isl_dim_out) != 0) + dim = isl_space_dim(space, isl_dim_out); + if (dim < 0) + goto error; + if (dim != 0) isl_die(isl_space_get_ctx(space), isl_error_invalid, "expecting 0D space", goto error); @@ -8119,15 +8348,70 @@ * the defined expression on the symmetric difference of the domains. * * We simply iterate over the elements in both arguments and - * call isl_union_pw_aff_union_add on each of them. + * call isl_union_pw_aff_union_add on each of them, if there is + * at least one element. + * + * Otherwise, the two expressions have an explicit domain and + * the union of these explicit domains is computed. + * This assumes that the explicit domains are either both in terms + * of specific domains elements or both in terms of parameters. + * However, if one of the expressions does not have any constraints + * on its explicit domain, then this is allowed as well and the result + * is the expression with no constraints on its explicit domain. */ static __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_union_add_aligned( __isl_take isl_multi_union_pw_aff *mupa1, __isl_take isl_multi_union_pw_aff *mupa2) { - return isl_multi_union_pw_aff_bin_op(mupa1, mupa2, + isl_bool has_domain, is_params1, is_params2; + + if (isl_multi_union_pw_aff_check_equal_space(mupa1, mupa2) < 0) + goto error; + if (mupa1->n > 0) + return isl_multi_union_pw_aff_bin_op(mupa1, mupa2, &isl_union_pw_aff_union_add); + if (isl_multi_union_pw_aff_check_has_explicit_domain(mupa1) < 0 || + isl_multi_union_pw_aff_check_has_explicit_domain(mupa2) < 0) + goto error; + + has_domain = isl_multi_union_pw_aff_has_non_trivial_domain(mupa1); + if (has_domain < 0) + goto error; + if (!has_domain) { + isl_multi_union_pw_aff_free(mupa2); + return mupa1; + } + has_domain = isl_multi_union_pw_aff_has_non_trivial_domain(mupa2); + if (has_domain < 0) + goto error; + if (!has_domain) { + isl_multi_union_pw_aff_free(mupa1); + return mupa2; + } + + is_params1 = isl_union_set_is_params(mupa1->u.dom); + is_params2 = isl_union_set_is_params(mupa2->u.dom); + if (is_params1 < 0 || is_params2 < 0) + goto error; + if (is_params1 != is_params2) + isl_die(isl_multi_union_pw_aff_get_ctx(mupa1), + isl_error_invalid, + "cannot compute union of concrete domain and " + "parameter constraints", goto error); + mupa1 = isl_multi_union_pw_aff_cow(mupa1); + if (!mupa1) + goto error; + mupa1->u.dom = isl_union_set_union(mupa1->u.dom, + isl_union_set_copy(mupa2->u.dom)); + if (!mupa1->u.dom) + goto error; + isl_multi_union_pw_aff_free(mupa2); + return mupa1; +error: + isl_multi_union_pw_aff_free(mupa1); + isl_multi_union_pw_aff_free(mupa2); + return NULL; } /* Compute the sum of "mupa1" and "mupa2" on the union of their domains, @@ -8160,10 +8444,14 @@ __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_from_multi_pw_aff( __isl_take isl_multi_pw_aff *mpa) { - int i, n; + int i; + isl_size n; isl_space *space; isl_multi_union_pw_aff *mupa; + n = isl_multi_pw_aff_dim(mpa, isl_dim_out); + if (n < 0) + mpa = isl_multi_pw_aff_free(mpa); if (!mpa) return NULL; @@ -8171,7 +8459,6 @@ space = isl_space_range(space); mupa = isl_multi_union_pw_aff_alloc(space); - n = isl_multi_pw_aff_dim(mpa, isl_dim_out); for (i = 0; i < n; ++i) { isl_pw_aff *pa; isl_union_pw_aff *upa; @@ -8222,6 +8509,10 @@ * * In order to be able to perform the conversion, the input * needs to be non-empty and may only involve a single range space. + * + * If the resulting multi union piecewise affine expression has + * an explicit domain, then assign it the domain of the input. + * In other cases, the domain is stored in the individual elements. */ __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_from_union_pw_multi_aff( @@ -8229,11 +8520,13 @@ { isl_space *space = NULL; isl_multi_union_pw_aff *mupa; - int i, n; + int i; + isl_size n; - if (!upma) - return NULL; - if (isl_union_pw_multi_aff_n_pw_multi_aff(upma) == 0) + n = isl_union_pw_multi_aff_n_pw_multi_aff(upma); + if (n < 0) + goto error; + if (n == 0) isl_die(isl_union_pw_multi_aff_get_ctx(upma), isl_error_invalid, "cannot extract range space from empty input", goto error); @@ -8245,6 +8538,8 @@ goto error; n = isl_space_dim(space, isl_dim_set); + if (n < 0) + space = isl_space_free(space); mupa = isl_multi_union_pw_aff_alloc(space); for (i = 0; i < n; ++i) { @@ -8253,6 +8548,14 @@ upa = isl_union_pw_multi_aff_get_union_pw_aff(upma, i); mupa = isl_multi_union_pw_aff_set_union_pw_aff(mupa, i, upa); } + if (isl_multi_union_pw_aff_has_explicit_domain(mupa)) { + isl_union_set *dom; + isl_union_pw_multi_aff *copy; + + copy = isl_union_pw_multi_aff_copy(upma); + dom = isl_union_pw_multi_aff_domain(copy); + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, dom); + } isl_union_pw_multi_aff_free(upma); return mupa; @@ -8280,19 +8583,24 @@ /* Return a multiple union piecewise affine expression * that is equal to "mv" on "domain", assuming "domain" and "mv" * have been aligned. + * + * If the resulting multi union piecewise affine expression has + * an explicit domain, then assign it the input domain. + * In other cases, the domain is stored in the individual elements. */ static __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_multi_val_on_domain_aligned( __isl_take isl_union_set *domain, __isl_take isl_multi_val *mv) { - int i, n; + int i; + isl_size n; isl_space *space; isl_multi_union_pw_aff *mupa; - if (!domain || !mv) + n = isl_multi_val_dim(mv, isl_dim_set); + if (!domain || n < 0) goto error; - n = isl_multi_val_dim(mv, isl_dim_set); space = isl_multi_val_get_space(mv); mupa = isl_multi_union_pw_aff_alloc(space); for (i = 0; i < n; ++i) { @@ -8304,6 +8612,9 @@ v); mupa = isl_multi_union_pw_aff_set_union_pw_aff(mupa, i, upa); } + if (isl_multi_union_pw_aff_has_explicit_domain(mupa)) + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, + isl_union_set_copy(domain)); isl_union_set_free(domain); isl_multi_val_free(mv); @@ -8355,19 +8666,23 @@ /* Return a multiple union piecewise affine expression * that is equal to "pma" on "domain", assuming "domain" and "pma" * have been aligned. + * + * If the resulting multi union piecewise affine expression has + * an explicit domain, then assign it the input domain. + * In other cases, the domain is stored in the individual elements. */ static __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_pw_multi_aff_on_domain_aligned( __isl_take isl_union_set *domain, __isl_take isl_pw_multi_aff *pma) { - int i, n; + int i; + isl_size n; isl_space *space; isl_multi_union_pw_aff *mupa; - - if (!domain || !pma) - goto error; n = isl_pw_multi_aff_dim(pma, isl_dim_set); + if (!domain || n < 0) + goto error; space = isl_pw_multi_aff_get_space(pma); mupa = isl_multi_union_pw_aff_alloc(space); for (i = 0; i < n; ++i) { @@ -8379,6 +8694,9 @@ isl_union_set_copy(domain), pa); mupa = isl_multi_union_pw_aff_set_union_pw_aff(mupa, i, upa); } + if (isl_multi_union_pw_aff_has_explicit_domain(mupa)) + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, + isl_union_set_copy(domain)); isl_union_set_free(domain); isl_pw_multi_aff_free(pma); @@ -8420,22 +8738,25 @@ /* Return a union set containing those elements in the domains * of the elements of "mupa" where they are all zero. + * + * If there are no elements, then simply return the entire domain. */ __isl_give isl_union_set *isl_multi_union_pw_aff_zero_union_set( __isl_take isl_multi_union_pw_aff *mupa) { - int i, n; + int i; + isl_size n; isl_union_pw_aff *upa; isl_union_set *zero; + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0) + mupa = isl_multi_union_pw_aff_free(mupa); if (!mupa) return NULL; - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); if (n == 0) - isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, - "cannot determine zero set " - "of zero-dimensional function", goto error); + return isl_multi_union_pw_aff_domain(mupa); upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, 0); zero = isl_union_pw_aff_zero_union_set(upa); @@ -8451,9 +8772,37 @@ isl_multi_union_pw_aff_free(mupa); return zero; -error: - isl_multi_union_pw_aff_free(mupa); - return NULL; +} + +/* Construct a union map mapping the shared domain + * of the union piecewise affine expressions to the range of "mupa" + * in the special case of a 0D multi union piecewise affine expression. + * + * Construct a map between the explicit domain of "mupa" and + * the range space. + * Note that this assumes that the domain consists of explicit elements. + */ +static __isl_give isl_union_map *isl_union_map_from_multi_union_pw_aff_0D( + __isl_take isl_multi_union_pw_aff *mupa) +{ + isl_bool is_params; + isl_space *space; + isl_union_set *dom, *ran; + + space = isl_multi_union_pw_aff_get_space(mupa); + dom = isl_multi_union_pw_aff_domain(mupa); + ran = isl_union_set_from_set(isl_set_universe(space)); + + is_params = isl_union_set_is_params(dom); + if (is_params < 0) + dom = isl_union_set_free(dom); + else if (is_params) + isl_die(isl_union_set_get_ctx(dom), isl_error_invalid, + "cannot create union map from expression without " + "explicit domain elements", + dom = isl_union_set_free(dom)); + + return isl_union_map_from_domain_and_range(dom, ran); } /* Construct a union map mapping the shared domain @@ -8461,25 +8810,26 @@ * with each dimension in the range equated to the * corresponding union piecewise affine expression. * - * The input cannot be zero-dimensional as there is - * no way to extract a domain from a zero-dimensional isl_multi_union_pw_aff. + * If the input is zero-dimensional, then construct a mapping + * from its explicit domain. */ __isl_give isl_union_map *isl_union_map_from_multi_union_pw_aff( __isl_take isl_multi_union_pw_aff *mupa) { - int i, n; + int i; + isl_size n; isl_space *space; isl_union_map *umap; isl_union_pw_aff *upa; + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0) + mupa = isl_multi_union_pw_aff_free(mupa); if (!mupa) return NULL; - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); if (n == 0) - isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, - "cannot determine domain of zero-dimensional " - "isl_multi_union_pw_aff", goto error); + return isl_union_map_from_multi_union_pw_aff_0D(mupa); upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, 0); umap = isl_union_map_from_union_pw_aff(upa); @@ -8497,9 +8847,6 @@ isl_multi_union_pw_aff_free(mupa); return umap; -error: - isl_multi_union_pw_aff_free(mupa); - return NULL; } /* Internal data structure for isl_union_pw_multi_aff_reset_range_space. @@ -8556,31 +8903,54 @@ isl_space_free(space); isl_union_pw_multi_aff_free(upma); return data.res; +} + +/* Construct and return a union piecewise multi affine expression + * that is equal to the given multi union piecewise affine expression, + * in the special case of a 0D multi union piecewise affine expression. + * + * Construct a union piecewise multi affine expression + * on top of the explicit domain of the input. + */ +__isl_give isl_union_pw_multi_aff * +isl_union_pw_multi_aff_from_multi_union_pw_aff_0D( + __isl_take isl_multi_union_pw_aff *mupa) +{ + isl_space *space; + isl_multi_val *mv; + isl_union_set *domain; + + space = isl_multi_union_pw_aff_get_space(mupa); + mv = isl_multi_val_zero(space); + domain = isl_multi_union_pw_aff_domain(mupa); + return isl_union_pw_multi_aff_multi_val_on_domain(domain, mv); } /* Construct and return a union piecewise multi affine expression * that is equal to the given multi union piecewise affine expression. * - * In order to be able to perform the conversion, the input - * needs to have a least one output dimension. + * If the input is zero-dimensional, then + * construct a union piecewise multi affine expression + * on top of the explicit domain of the input. */ __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_from_multi_union_pw_aff( __isl_take isl_multi_union_pw_aff *mupa) { - int i, n; + int i; + isl_size n; isl_space *space; isl_union_pw_multi_aff *upma; isl_union_pw_aff *upa; + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0) + mupa = isl_multi_union_pw_aff_free(mupa); if (!mupa) return NULL; - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); if (n == 0) - isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, - "cannot determine domain of zero-dimensional " - "isl_multi_union_pw_aff", goto error); + return isl_union_pw_multi_aff_from_multi_union_pw_aff_0D(mupa); space = isl_multi_union_pw_aff_get_space(mupa); upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, 0); @@ -8598,9 +8968,20 @@ isl_multi_union_pw_aff_free(mupa); return upma; -error: - isl_multi_union_pw_aff_free(mupa); - return NULL; +} + +/* Intersect the range of "mupa" with "range", + * in the special case where "mupa" is 0D. + * + * Intersect the domain of "mupa" with the constraints on the parameters + * of "range". + */ +static __isl_give isl_multi_union_pw_aff *mupa_intersect_range_0D( + __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_set *range) +{ + range = isl_set_params(range); + mupa = isl_multi_union_pw_aff_intersect_params(mupa, range); + return mupa; } /* Intersect the range of "mupa" with "range". @@ -8613,10 +8994,11 @@ isl_union_pw_multi_aff *upma; isl_union_set *domain; isl_space *space; - int n; + isl_size n; int match; - if (!mupa || !range) + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0 || !range) goto error; space = isl_set_get_space(range); @@ -8628,11 +9010,8 @@ if (!match) isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, "space don't match", goto error); - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); if (n == 0) - isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, - "cannot intersect range of zero-dimensional " - "isl_multi_union_pw_aff", goto error); + return mupa_intersect_range_0D(mupa, range); upma = isl_union_pw_multi_aff_from_multi_union_pw_aff( isl_multi_union_pw_aff_copy(mupa)); @@ -8645,24 +9024,47 @@ isl_multi_union_pw_aff_free(mupa); isl_set_free(range); return NULL; +} + +/* Return the shared domain of the elements of "mupa", + * in the special case where "mupa" is zero-dimensional. + * + * Return the explicit domain of "mupa". + * Note that this domain may be a parameter set, either + * because "mupa" is meant to live in a set space or + * because no explicit domain has been set. + */ +__isl_give isl_union_set *isl_multi_union_pw_aff_domain_0D( + __isl_take isl_multi_union_pw_aff *mupa) +{ + isl_union_set *dom; + + dom = isl_multi_union_pw_aff_get_explicit_domain(mupa); + isl_multi_union_pw_aff_free(mupa); + + return dom; } /* Return the shared domain of the elements of "mupa". + * + * If "mupa" is zero-dimensional, then return its explicit domain. */ __isl_give isl_union_set *isl_multi_union_pw_aff_domain( __isl_take isl_multi_union_pw_aff *mupa) { - int i, n; + int i; + isl_size n; isl_union_pw_aff *upa; isl_union_set *dom; + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0) + mupa = isl_multi_union_pw_aff_free(mupa); if (!mupa) return NULL; - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); if (n == 0) - isl_die(isl_multi_union_pw_aff_get_ctx(mupa), isl_error_invalid, - "cannot determine domain", goto error); + return isl_multi_union_pw_aff_domain_0D(mupa); upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, 0); dom = isl_union_pw_aff_domain(upa); @@ -8676,9 +9078,6 @@ isl_multi_union_pw_aff_free(mupa); return dom; -error: - isl_multi_union_pw_aff_free(mupa); - return NULL; } /* Apply "aff" to "mupa". The space of "mupa" is equal to the domain of "aff". @@ -8696,7 +9095,8 @@ static __isl_give isl_union_pw_aff *multi_union_pw_aff_apply_aff( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_aff *aff) { - int i, n_in, n_div; + int i; + isl_size n_in, n_div; isl_union_pw_aff *upa; isl_union_set *uset; isl_val *v; @@ -8704,6 +9104,8 @@ n_in = isl_aff_dim(aff, isl_dim_in); n_div = isl_aff_dim(aff, isl_dim_div); + if (n_in < 0 || n_div < 0) + goto error; uset = isl_multi_union_pw_aff_domain(isl_multi_union_pw_aff_copy(mupa)); cst = isl_aff_copy(aff); @@ -8742,6 +9144,10 @@ isl_aff_free(aff); return upa; +error: + isl_multi_union_pw_aff_free(mupa); + isl_aff_free(aff); + return NULL; } /* Apply "aff" to "mupa". The space of "mupa" needs to be compatible @@ -8755,8 +9161,9 @@ __isl_give isl_union_pw_aff *isl_multi_union_pw_aff_apply_aff( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_aff *aff) { + isl_size dim; isl_space *space1, *space2; - int equal; + isl_bool equal; mupa = isl_multi_union_pw_aff_align_params(mupa, isl_aff_get_space(aff)); @@ -8774,7 +9181,10 @@ if (!equal) isl_die(isl_aff_get_ctx(aff), isl_error_invalid, "spaces don't match", goto error); - if (isl_aff_dim(aff, isl_dim_in) == 0) + dim = isl_aff_dim(aff, isl_dim_in); + if (dim < 0) + goto error; + if (dim == 0) isl_die(isl_aff_get_ctx(aff), isl_error_invalid, "cannot determine domains", goto error); @@ -8783,12 +9193,27 @@ isl_multi_union_pw_aff_free(mupa); isl_aff_free(aff); return NULL; +} + +/* Apply "ma" to "mupa", in the special case where "mupa" is 0D. + * The space of "mupa" is known to be compatible with the domain of "ma". + * + * Construct an isl_multi_union_pw_aff that is equal to "ma" + * on the domain of "mupa". + */ +static __isl_give isl_multi_union_pw_aff *mupa_apply_multi_aff_0D( + __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_multi_aff *ma) +{ + isl_union_set *dom; + + dom = isl_multi_union_pw_aff_domain(mupa); + ma = isl_multi_aff_project_domain_on_params(ma); + + return isl_multi_union_pw_aff_multi_aff_on_domain(dom, ma); } /* Apply "ma" to "mupa". The space of "mupa" needs to be compatible * with the domain of "ma". - * Furthermore, the dimension of this space needs to be greater than zero, - * unless the dimension of the target space of "ma" is also zero. * The result is defined over the shared domain of the elements of "mupa" */ __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_apply_multi_aff( @@ -8796,14 +9221,17 @@ { isl_space *space1, *space2; isl_multi_union_pw_aff *res; - int equal; - int i, n_out; + isl_bool equal; + int i; + isl_size n_in, n_out; mupa = isl_multi_union_pw_aff_align_params(mupa, isl_multi_aff_get_space(ma)); ma = isl_multi_aff_align_params(ma, isl_multi_union_pw_aff_get_space(mupa)); - if (!mupa || !ma) + n_in = isl_multi_aff_dim(ma, isl_dim_in); + n_out = isl_multi_aff_dim(ma, isl_dim_out); + if (!mupa || n_in < 0 || n_out < 0) goto error; space1 = isl_multi_union_pw_aff_get_space(mupa); @@ -8816,10 +9244,8 @@ if (!equal) isl_die(isl_multi_aff_get_ctx(ma), isl_error_invalid, "spaces don't match", goto error); - n_out = isl_multi_aff_dim(ma, isl_dim_out); - if (isl_multi_aff_dim(ma, isl_dim_in) == 0 && n_out != 0) - isl_die(isl_multi_aff_get_ctx(ma), isl_error_invalid, - "cannot determine domains", goto error); + if (n_in == 0) + return mupa_apply_multi_aff_0D(mupa, ma); space1 = isl_space_range(isl_multi_aff_get_space(ma)); res = isl_multi_union_pw_aff_alloc(space1); @@ -8841,6 +9267,23 @@ isl_multi_union_pw_aff_free(mupa); isl_multi_aff_free(ma); return NULL; +} + +/* Apply "pa" to "mupa", in the special case where "mupa" is 0D. + * The space of "mupa" is known to be compatible with the domain of "pa". + * + * Construct an isl_multi_union_pw_aff that is equal to "pa" + * on the domain of "mupa". + */ +static __isl_give isl_union_pw_aff *isl_multi_union_pw_aff_apply_pw_aff_0D( + __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_pw_aff *pa) +{ + isl_union_set *dom; + + dom = isl_multi_union_pw_aff_domain(mupa); + pa = isl_pw_aff_project_domain_on_params(pa); + + return isl_union_pw_aff_pw_aff_on_domain(dom, pa); } /* Apply "pa" to "mupa". The space of "mupa" needs to be compatible @@ -8852,7 +9295,8 @@ __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_pw_aff *pa) { int i; - int equal; + isl_bool equal; + isl_size n_in; isl_space *space, *space2; isl_union_pw_aff *upa; @@ -8873,9 +9317,11 @@ if (!equal) isl_die(isl_pw_aff_get_ctx(pa), isl_error_invalid, "spaces don't match", goto error); - if (isl_pw_aff_dim(pa, isl_dim_in) == 0) - isl_die(isl_pw_aff_get_ctx(pa), isl_error_invalid, - "cannot determine domains", goto error); + n_in = isl_pw_aff_dim(pa, isl_dim_in); + if (n_in < 0) + goto error; + if (n_in == 0) + return isl_multi_union_pw_aff_apply_pw_aff_0D(mupa, pa); space = isl_space_params(isl_multi_union_pw_aff_get_space(mupa)); upa = isl_union_pw_aff_empty(space); @@ -8901,12 +9347,28 @@ isl_multi_union_pw_aff_free(mupa); isl_pw_aff_free(pa); return NULL; +} + +/* Apply "pma" to "mupa", in the special case where "mupa" is 0D. + * The space of "mupa" is known to be compatible with the domain of "pma". + * + * Construct an isl_multi_union_pw_aff that is equal to "pma" + * on the domain of "mupa". + */ +static __isl_give isl_multi_union_pw_aff *mupa_apply_pw_multi_aff_0D( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_pw_multi_aff *pma) +{ + isl_union_set *dom; + + dom = isl_multi_union_pw_aff_domain(mupa); + pma = isl_pw_multi_aff_project_domain_on_params(pma); + + return isl_multi_union_pw_aff_pw_multi_aff_on_domain(dom, pma); } /* Apply "pma" to "mupa". The space of "mupa" needs to be compatible * with the domain of "pma". - * Furthermore, the dimension of this space needs to be greater than zero, - * unless the dimension of the target space of "pma" is also zero. * The result is defined over the shared domain of the elements of "mupa" */ __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_apply_pw_multi_aff( @@ -8915,8 +9377,9 @@ { isl_space *space1, *space2; isl_multi_union_pw_aff *res; - int equal; - int i, n_out; + isl_bool equal; + int i; + isl_size n_in, n_out; mupa = isl_multi_union_pw_aff_align_params(mupa, isl_pw_multi_aff_get_space(pma)); @@ -8935,10 +9398,12 @@ if (!equal) isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, "spaces don't match", goto error); + n_in = isl_pw_multi_aff_dim(pma, isl_dim_in); n_out = isl_pw_multi_aff_dim(pma, isl_dim_out); - if (isl_pw_multi_aff_dim(pma, isl_dim_in) == 0 && n_out != 0) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_invalid, - "cannot determine domains", goto error); + if (n_in < 0 || n_out < 0) + goto error; + if (n_in == 0) + return mupa_apply_pw_multi_aff_0D(mupa, pma); space1 = isl_space_range(isl_pw_multi_aff_get_space(pma)); res = isl_multi_union_pw_aff_alloc(space1); @@ -8960,6 +9425,39 @@ isl_multi_union_pw_aff_free(mupa); isl_pw_multi_aff_free(pma); return NULL; +} + +/* Replace the explicit domain of "mupa" by its preimage under "upma". + * If the explicit domain only keeps track of constraints on the parameters, + * then only update those constraints. + */ +static __isl_give isl_multi_union_pw_aff *preimage_explicit_domain( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_keep isl_union_pw_multi_aff *upma) +{ + isl_bool is_params; + + if (isl_multi_union_pw_aff_check_has_explicit_domain(mupa) < 0) + return isl_multi_union_pw_aff_free(mupa); + + mupa = isl_multi_union_pw_aff_cow(mupa); + if (!mupa) + return NULL; + + is_params = isl_union_set_is_params(mupa->u.dom); + if (is_params < 0) + return isl_multi_union_pw_aff_free(mupa); + + upma = isl_union_pw_multi_aff_copy(upma); + if (is_params) + mupa->u.dom = isl_union_set_intersect_params(mupa->u.dom, + isl_union_set_params(isl_union_pw_multi_aff_domain(upma))); + else + mupa->u.dom = isl_union_set_preimage_union_pw_multi_aff( + mupa->u.dom, upma); + if (!mupa->u.dom) + return isl_multi_union_pw_aff_free(mupa); + return mupa; } /* Compute the pullback of "mupa" by the function represented by "upma". @@ -8967,22 +9465,27 @@ * expressions defined over the domain space of "upma". * * Run over all elements of "mupa" and plug in "upma" in each of them. + * + * If "mupa" has an explicit domain, then it is this domain + * that needs to undergo a pullback instead, i.e., a preimage. */ __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_pullback_union_pw_multi_aff( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_union_pw_multi_aff *upma) { - int i, n; + int i; + isl_size n; mupa = isl_multi_union_pw_aff_align_params(mupa, isl_union_pw_multi_aff_get_space(upma)); upma = isl_union_pw_multi_aff_align_params(upma, isl_multi_union_pw_aff_get_space(mupa)); - if (!mupa || !upma) + mupa = isl_multi_union_pw_aff_cow(mupa); + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0 || !upma) goto error; - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); for (i = 0; i < n; ++i) { isl_union_pw_aff *upa; @@ -8991,6 +9494,9 @@ isl_union_pw_multi_aff_copy(upma)); mupa = isl_multi_union_pw_aff_set_union_pw_aff(mupa, i, upa); } + + if (isl_multi_union_pw_aff_has_explicit_domain(mupa)) + mupa = preimage_explicit_domain(mupa, upma); isl_union_pw_multi_aff_free(upma); return mupa; @@ -9009,33 +9515,23 @@ __isl_give isl_multi_pw_aff *isl_multi_union_pw_aff_extract_multi_pw_aff( __isl_keep isl_multi_union_pw_aff *mupa, __isl_take isl_space *space) { - int i, n; - isl_bool equal_params; - isl_space *space_mpa = NULL; + int i; + isl_size n; + isl_space *space_mpa; isl_multi_pw_aff *mpa; - if (!mupa || !space) + n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + if (n < 0 || !space) goto error; space_mpa = isl_multi_union_pw_aff_get_space(mupa); - equal_params = isl_space_has_equal_params(space_mpa, space); - if (equal_params < 0) - goto error; - if (!equal_params) { - space = isl_space_drop_dims(space, isl_dim_param, - 0, isl_space_dim(space, isl_dim_param)); - space = isl_space_align_params(space, - isl_space_copy(space_mpa)); - if (!space) - goto error; - } + space = isl_space_replace_params(space, space_mpa); space_mpa = isl_space_map_from_domain_and_range(isl_space_copy(space), space_mpa); mpa = isl_multi_pw_aff_alloc(space_mpa); space = isl_space_from_domain(space); space = isl_space_add_dims(space, isl_dim_out, 1); - n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); for (i = 0; i < n; ++i) { isl_union_pw_aff *upa; isl_pw_aff *pa; @@ -9050,7 +9546,167 @@ isl_space_free(space); return mpa; error: - isl_space_free(space_mpa); isl_space_free(space); + return NULL; +} + +/* Data structure that specifies how isl_union_pw_multi_aff_un_op + * should modify the base expressions in the input. + * + * If "filter" is not NULL, then only the base expressions that satisfy "filter" + * are taken into account. + * "fn" is applied to each entry in the input. + */ +struct isl_union_pw_multi_aff_un_op_control { + isl_bool (*filter)(__isl_keep isl_pw_multi_aff *part); + __isl_give isl_pw_multi_aff *(*fn)(__isl_take isl_pw_multi_aff *pma); +}; + +/* Wrapper for isl_union_pw_multi_aff_un_op base functions (which do not take + * a second argument) for use as an isl_union_pw_multi_aff_transform + * base function (which does take a second argument). + * Simply call control->fn without the second argument. + */ +static __isl_give isl_pw_multi_aff *isl_union_pw_multi_aff_un_op_drop_user( + __isl_take isl_pw_multi_aff *pma, void *user) +{ + struct isl_union_pw_multi_aff_un_op_control *control = user; + + return control->fn(pma); +} + +/* Construct an isl_union_pw_multi_aff that is obtained by + * modifying "upma" according to "control". + * + * isl_union_pw_multi_aff_transform performs essentially + * the same operation, but takes a callback function + * of a different form (with an extra argument). + * Call isl_union_pw_multi_aff_transform with a wrapper + * that removes this extra argument. + */ +static __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_un_op( + __isl_take isl_union_pw_multi_aff *upma, + struct isl_union_pw_multi_aff_un_op_control *control) +{ + struct isl_union_pw_multi_aff_transform_control t_control = { + .filter = control->filter, + .fn = &isl_union_pw_multi_aff_un_op_drop_user, + .fn_user = control, + }; + + return isl_union_pw_multi_aff_transform(upma, &t_control); +} + +/* For each function in "upma" of the form A -> [B -> C], + * extract the function A -> B and collect the results. + */ +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_range_factor_domain( + __isl_take isl_union_pw_multi_aff *upma) +{ + struct isl_union_pw_multi_aff_un_op_control control = { + .filter = &isl_pw_multi_aff_range_is_wrapping, + .fn = &isl_pw_multi_aff_range_factor_domain, + }; + return isl_union_pw_multi_aff_un_op(upma, &control); +} + +/* For each function in "upma" of the form A -> [B -> C], + * extract the function A -> C and collect the results. + */ +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_range_factor_range( + __isl_take isl_union_pw_multi_aff *upma) +{ + struct isl_union_pw_multi_aff_un_op_control control = { + .filter = &isl_pw_multi_aff_range_is_wrapping, + .fn = &isl_pw_multi_aff_range_factor_range, + }; + return isl_union_pw_multi_aff_un_op(upma, &control); +} + +/* Evaluate the affine function "aff" in the void point "pnt". + * In particular, return the value NaN. + */ +static __isl_give isl_val *eval_void(__isl_take isl_aff *aff, + __isl_take isl_point *pnt) +{ + isl_ctx *ctx; + + ctx = isl_point_get_ctx(pnt); + isl_aff_free(aff); + isl_point_free(pnt); + return isl_val_nan(ctx); +} + +/* Evaluate the affine expression "aff" + * in the coordinates (with denominator) "pnt". + */ +static __isl_give isl_val *eval(__isl_keep isl_vec *aff, + __isl_keep isl_vec *pnt) +{ + isl_int n, d; + isl_ctx *ctx; + isl_val *v; + + if (!aff || !pnt) + return NULL; + + ctx = isl_vec_get_ctx(aff); + isl_int_init(n); + isl_int_init(d); + isl_seq_inner_product(aff->el + 1, pnt->el, pnt->size, &n); + isl_int_mul(d, aff->el[0], pnt->el[0]); + v = isl_val_rat_from_isl_int(ctx, n, d); + v = isl_val_normalize(v); + isl_int_clear(n); + isl_int_clear(d); + + return v; +} + +/* Check that the domain space of "aff" is equal to "space". + */ +static isl_stat isl_aff_check_has_domain_space(__isl_keep isl_aff *aff, + __isl_keep isl_space *space) +{ + isl_bool ok; + + ok = isl_space_is_equal(isl_aff_peek_domain_space(aff), space); + if (ok < 0) + return isl_stat_error; + if (!ok) + isl_die(isl_aff_get_ctx(aff), isl_error_invalid, + "incompatible spaces", return isl_stat_error); + return isl_stat_ok; +} + +/* Evaluate the affine function "aff" in "pnt". + */ +__isl_give isl_val *isl_aff_eval(__isl_take isl_aff *aff, + __isl_take isl_point *pnt) +{ + isl_bool is_void; + isl_val *v; + isl_local_space *ls; + + if (isl_aff_check_has_domain_space(aff, isl_point_peek_space(pnt)) < 0) + goto error; + is_void = isl_point_is_void(pnt); + if (is_void < 0) + goto error; + if (is_void) + return eval_void(aff, pnt); + + ls = isl_aff_get_domain_local_space(aff); + pnt = isl_local_space_lift_point(ls, pnt); + + v = eval(aff->v, isl_point_peek_vec(pnt)); + + isl_aff_free(aff); + isl_point_free(pnt); + + return v; +error: + isl_aff_free(aff); + isl_point_free(pnt); return NULL; } diff --git a/gcc/isl/isl_aff_private.h b/gcc/isl/isl_aff_private.h index 8ee5b00..48719c5 100644 --- a/gcc/isl/isl_aff_private.h +++ a/gcc/isl/isl_aff_private.h @@ -41,6 +41,11 @@ struct isl_pw_aff_piece p[1]; }; +#undef PW +#define PW isl_pw_aff + +#include + #undef EL #define EL isl_pw_aff @@ -61,10 +66,18 @@ size_t size; struct isl_pw_multi_aff_piece p[1]; }; + +#undef PW +#define PW isl_pw_multi_aff +#include + __isl_give isl_aff *isl_aff_alloc_vec(__isl_take isl_local_space *ls, __isl_take isl_vec *v); __isl_give isl_aff *isl_aff_alloc(__isl_take isl_local_space *ls); + +isl_size isl_aff_domain_dim(__isl_keep isl_aff *aff, enum isl_dim_type type); +isl_size isl_aff_domain_offset(__isl_keep isl_aff *aff, enum isl_dim_type type); __isl_give isl_aff *isl_aff_reset_space_and_domain(__isl_take isl_aff *aff, __isl_take isl_space *space, __isl_take isl_space *domain); @@ -78,8 +91,11 @@ enum isl_dim_type type, int pos, isl_int v); __isl_give isl_aff *isl_aff_add_constant(__isl_take isl_aff *aff, isl_int v); +__isl_give isl_aff *isl_aff_domain_factor_domain(__isl_take isl_aff *aff); + int isl_aff_plain_cmp(__isl_keep isl_aff *aff1, __isl_keep isl_aff *aff2); +__isl_give isl_aff *isl_aff_remove_unused_divs(__isl_take isl_aff *aff); __isl_give isl_aff *isl_aff_normalize(__isl_take isl_aff *aff); __isl_give isl_aff *isl_aff_expand_divs( __isl_take isl_aff *aff, @@ -93,6 +109,9 @@ __isl_take isl_pw_aff *pwaff, __isl_take isl_space *space); __isl_give isl_pw_aff *isl_pw_aff_add_disjoint( __isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2); + +__isl_give isl_pw_aff *isl_pw_aff_domain_factor_domain( + __isl_take isl_pw_aff *pa); __isl_give isl_pw_aff *isl_pw_aff_union_opt(__isl_take isl_pw_aff *pwaff1, __isl_take isl_pw_aff *pwaff2, int max); @@ -128,6 +147,11 @@ __isl_give isl_multi_aff *isl_multi_aff_from_aff_mat( __isl_take isl_space *space, __isl_take isl_mat *mat); +#undef EL +#define EL isl_pw_multi_aff + +#include + __isl_give isl_pw_multi_aff *isl_pw_multi_aff_reset_domain_space( __isl_take isl_pw_multi_aff *pwmaff, __isl_take isl_space *space); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_reset_space( @@ -139,7 +163,7 @@ __isl_take isl_pw_multi_aff *pma, enum isl_dim_type type, unsigned first, unsigned n); -void isl_seq_preimage(isl_int *dst, isl_int *src, +isl_stat isl_seq_preimage(isl_int *dst, isl_int *src, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div_ma, int n_div_bmap, isl_int f, isl_int c1, isl_int c2, isl_int g, int has_denom); @@ -149,6 +173,9 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_substitute( __isl_take isl_pw_multi_aff *pma, enum isl_dim_type type, unsigned pos, __isl_keep isl_pw_aff *subs); + +isl_stat isl_pw_aff_check_named_params(__isl_keep isl_pw_aff *pa); +isl_stat isl_pw_multi_aff_check_named_params(__isl_keep isl_pw_multi_aff *pma); isl_bool isl_pw_aff_matching_params(__isl_keep isl_pw_aff *pa, __isl_keep isl_space *space); @@ -159,9 +186,14 @@ #undef BASE #define BASE pw_aff +#undef DOMBASE +#define DOMBASE set +#define EXPLICIT_DOMAIN #include +#undef EXPLICIT_DOMAIN + #undef EL #define EL isl_union_pw_aff @@ -169,8 +201,13 @@ #undef BASE #define BASE union_pw_aff +#undef DOMBASE +#define DOMBASE union_set +#define EXPLICIT_DOMAIN #include + +#undef EXPLICIT_DOMAIN #undef EL #define EL isl_union_pw_multi_aff diff --git a/gcc/isl/isl_affine_hull.c b/gcc/isl/isl_affine_hull.c index a60a34c..45593a5 100644 --- a/gcc/isl/isl_affine_hull.c +++ a/gcc/isl/isl_affine_hull.c @@ -114,18 +114,21 @@ * so that * A[i][col] = B[i][col] = a * old(B[i][col]) */ -static void construct_column( - struct isl_basic_set *bset1, struct isl_basic_set *bset2, +static isl_stat construct_column( + __isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, unsigned row, unsigned col) { int r; isl_int a; isl_int b; - unsigned total; + isl_size total; + total = isl_basic_set_dim(bset1, isl_dim_set); + if (total < 0) + return isl_stat_error; + isl_int_init(a); isl_int_init(b); - total = 1 + isl_basic_set_n_dim(bset1); for (r = 0; r < row; ++r) { if (isl_int_is_zero(bset2->eq[r][col])) continue; @@ -133,12 +136,14 @@ isl_int_divexact(a, bset1->eq[row][col], b); isl_int_divexact(b, bset2->eq[r][col], b); isl_seq_combine(bset1->eq[r], a, bset1->eq[r], - b, bset1->eq[row], total); - isl_seq_scale(bset2->eq[r], bset2->eq[r], a, total); + b, bset1->eq[row], 1 + total); + isl_seq_scale(bset2->eq[r], bset2->eq[r], a, 1 + total); } isl_int_clear(a); isl_int_clear(b); delete_row(bset1, row); + + return isl_stat_ok; } /* Make first row entries in column col of bset1 identical to @@ -150,21 +155,23 @@ * so that * A[i][col] = B[i][col] = old(A[t][col]*B[i][col]-A[i][col]*B[t][col]) */ -static int transform_column( - struct isl_basic_set *bset1, struct isl_basic_set *bset2, +static isl_bool transform_column( + __isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, unsigned row, unsigned col) { int i, t; isl_int a, b, g; - unsigned total; + isl_size total; for (t = row-1; t >= 0; --t) if (isl_int_ne(bset1->eq[t][col], bset2->eq[t][col])) break; if (t < 0) - return 0; - - total = 1 + isl_basic_set_n_dim(bset1); + return isl_bool_false; + + total = isl_basic_set_dim(bset1, isl_dim_set); + if (total < 0) + return isl_bool_error; isl_int_init(a); isl_int_init(b); isl_int_init(g); @@ -175,16 +182,16 @@ isl_int_divexact(a, a, g); isl_int_divexact(g, b, g); isl_seq_combine(bset1->eq[i], g, bset1->eq[i], a, bset1->eq[t], - total); + 1 + total); isl_seq_combine(bset2->eq[i], g, bset2->eq[i], a, bset2->eq[t], - total); + 1 + total); } isl_int_clear(a); isl_int_clear(b); isl_int_clear(g); delete_row(bset1, t); delete_row(bset2, t); - return 1; + return isl_bool_true; } /* The implementation is based on Section 5.2 of Michael Karr, @@ -192,17 +199,19 @@ * except that the echelon form we use starts from the last column * and that we are dealing with integer coefficients. */ -static struct isl_basic_set *affine_hull( - struct isl_basic_set *bset1, struct isl_basic_set *bset2) +static __isl_give isl_basic_set *affine_hull( + __isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2) { + isl_size dim; unsigned total; int col; int row; - if (!bset1 || !bset2) + dim = isl_basic_set_dim(bset1, isl_dim_set); + if (dim < 0 || !bset2) goto error; - total = 1 + isl_basic_set_n_dim(bset1); + total = 1 + dim; row = 0; for (col = total-1; col >= 0; --col) { @@ -214,11 +223,18 @@ set_common_multiple(bset1, bset2, row, col); ++row; } else if (!is_zero1 && is_zero2) { - construct_column(bset1, bset2, row, col); + if (construct_column(bset1, bset2, row, col) < 0) + goto error; } else if (is_zero1 && !is_zero2) { - construct_column(bset2, bset1, row, col); + if (construct_column(bset2, bset1, row, col) < 0) + goto error; } else { - if (transform_column(bset1, bset2, row, col)) + isl_bool transform; + + transform = transform_column(bset1, bset2, row, col); + if (transform < 0) + goto error; + if (transform) --row; } } @@ -301,11 +317,17 @@ __isl_take isl_basic_set *bset) { int i; + isl_bool empty; + + empty = isl_basic_set_plain_is_empty(bset); + if (empty < 0) + return isl_basic_set_free(bset); + if (empty) + return bset; bset = isl_basic_set_cow(bset); - if (!bset) - return NULL; - isl_assert(bset->ctx, bset->n_div == 0, goto error); + if (isl_basic_set_check_no_locals(bset) < 0) + return isl_basic_set_free(bset); for (i = 0; i < bset->n_eq; ++i) isl_int_set_si(bset->eq[i][0], 0); @@ -315,9 +337,6 @@ ISL_F_CLR(bset, ISL_BASIC_SET_NO_IMPLICIT); return isl_basic_set_implicit_equalities(bset); -error: - isl_basic_set_free(bset); - return NULL; } /* Move "sample" to a point that is one up (or down) from the original @@ -343,12 +362,11 @@ __isl_keep isl_basic_set *bset) { int i, up; - int dim; - - if (!sample) - goto error; + isl_size dim; dim = isl_basic_set_dim(hull, isl_dim_set); + if (!sample || dim < 0) + goto error; for (i = 0; i < dim; ++i) { for (up = 0; up <= 1; ++up) { @@ -476,17 +494,20 @@ * we check if there is any point on a hyperplane parallel to the * corresponding hyperplane shifted by at least one (in either direction). */ -static struct isl_basic_set *uset_affine_hull_bounded(struct isl_basic_set *bset) +static __isl_give isl_basic_set *uset_affine_hull_bounded( + __isl_take isl_basic_set *bset) { struct isl_vec *sample = NULL; struct isl_basic_set *hull; struct isl_tab *tab = NULL; - unsigned dim; + isl_size dim; if (isl_basic_set_plain_is_empty(bset)) return bset; - dim = isl_basic_set_n_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + return isl_basic_set_free(bset); if (bset->sample && bset->sample->size == 1 + dim) { int contains = isl_basic_set_contains(bset, bset->sample); @@ -557,7 +578,7 @@ int k; struct isl_basic_set *bset = NULL; struct isl_ctx *ctx; - unsigned dim; + isl_size dim; if (!vec || !tab) return NULL; @@ -565,9 +586,10 @@ isl_assert(ctx, vec->size != 0, goto error); bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0); - if (!bset) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) goto error; - dim = isl_basic_set_n_dim(bset) - tab->n_unbounded; + dim -= tab->n_unbounded; for (i = 0; i < dim; ++i) { k = isl_basic_set_alloc_equality(bset); if (k < 0) @@ -707,15 +729,15 @@ static struct isl_basic_set *affine_hull_with_cone(struct isl_basic_set *bset, struct isl_basic_set *cone) { - unsigned total; + isl_size total; unsigned cone_dim; struct isl_basic_set *hull; struct isl_mat *M, *U, *Q; - if (!bset || !cone) + total = isl_basic_set_dim(cone, isl_dim_all); + if (!bset || total < 0) goto error; - total = isl_basic_set_total_dim(cone); cone_dim = total - cone->n_eq; M = isl_mat_sub_alloc6(bset->ctx, cone->eq, 0, cone->n_eq, 1, total); @@ -785,6 +807,7 @@ static struct isl_basic_set *uset_affine_hull(struct isl_basic_set *bset) { struct isl_basic_set *cone; + isl_size total; if (isl_basic_set_plain_is_empty(bset)) return bset; @@ -800,7 +823,10 @@ return isl_basic_set_universe(space); } - if (cone->n_eq < isl_basic_set_total_dim(cone)) + total = isl_basic_set_dim(cone, isl_dim_all); + if (total < 0) + bset = isl_basic_set_free(bset); + if (cone->n_eq < total) return affine_hull_with_cone(bset, cone); isl_basic_set_free(cone); @@ -876,6 +902,7 @@ __isl_take isl_basic_map *bmap) { int i, j; + isl_size total; struct isl_basic_set *hull = NULL; if (!bmap) @@ -898,12 +925,14 @@ } bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim), 0, hull->n_eq, 0); + total = isl_basic_set_dim(hull, isl_dim_all); + if (total < 0) + goto error; for (i = 0; i < hull->n_eq; ++i) { j = isl_basic_map_alloc_equality(bmap); if (j < 0) goto error; - isl_seq_cpy(bmap->eq[j], hull->eq[i], - 1 + isl_basic_set_total_dim(hull)); + isl_seq_cpy(bmap->eq[j], hull->eq[i], 1 + total); } isl_vec_free(bmap->sample); bmap->sample = isl_vec_copy(hull->sample); @@ -1060,10 +1089,10 @@ static __isl_give isl_basic_map *isl_basic_map_make_strides_explicit( __isl_take isl_basic_map *bmap) { - int known; + isl_bool known; int n_known; int n, n_col; - int total; + isl_size v_div; isl_ctx *ctx; isl_mat *A, *B, *M; @@ -1081,16 +1110,18 @@ if (isl_int_is_zero(bmap->div[n_known][0])) break; ctx = isl_basic_map_get_ctx(bmap); - total = isl_space_dim(bmap->dim, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); for (n = 0; n < bmap->n_eq; ++n) - if (isl_seq_first_non_zero(bmap->eq[n] + 1 + total + n_known, + if (isl_seq_first_non_zero(bmap->eq[n] + 1 + v_div + n_known, bmap->n_div - n_known) == -1) break; if (n == 0) return bmap; - B = isl_mat_sub_alloc6(ctx, bmap->eq, 0, n, 0, 1 + total + n_known); + B = isl_mat_sub_alloc6(ctx, bmap->eq, 0, n, 0, 1 + v_div + n_known); n_col = bmap->n_div - n_known; - A = isl_mat_sub_alloc6(ctx, bmap->eq, 0, n, 1 + total + n_known, n_col); + A = isl_mat_sub_alloc6(ctx, bmap->eq, 0, n, 1 + v_div + n_known, n_col); A = isl_mat_left_hermite(A, 0, NULL, NULL); A = isl_mat_drop_cols(A, n, n_col - n); A = isl_mat_lin_to_aff(A); diff --git a/gcc/isl/isl_arg.c b/gcc/isl/isl_arg.c index 4798a42..2494837 100644 --- a/gcc/isl/isl_arg.c +++ a/gcc/isl/isl_arg.c @@ -21,7 +21,7 @@ static void set_default_choice(struct isl_arg *arg, void *opt) { - if (arg->offset == (size_t) -1) + if (arg->offset == ISL_ARG_OFFSET_NONE) return; *(unsigned *)(((char *)opt) + arg->offset) = arg->u.choice.default_value; } @@ -33,7 +33,7 @@ static void set_default_bool(struct isl_arg *arg, void *opt) { - if (arg->offset == (size_t) -1) + if (arg->offset == ISL_ARG_OFFSET_NONE) return; *(unsigned *)(((char *)opt) + arg->offset) = arg->u.b.default_value; } @@ -42,7 +42,7 @@ { void *child; - if (arg->offset == (size_t) -1) + if (arg->offset == ISL_ARG_OFFSET_NONE) child = opt; else { child = calloc(1, arg->u.child.child->options_size); @@ -137,7 +137,7 @@ static void free_child(struct isl_arg *arg, void *opt) { - if (arg->offset == (size_t) -1) + if (arg->offset == ISL_ARG_OFFSET_NONE) free_args(arg->u.child.child->args, opt); else isl_args_free(arg->u.child.child, @@ -520,7 +520,7 @@ int no = p ? *p == 1 : 0; pos = print_arg_help(decl, prefixes, no); pos = print_help_msg(decl, pos); - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) print_default(decl, no ? "yes" : "no", pos); printf("\n"); } @@ -667,7 +667,7 @@ printf("\n"); if (arg[i].help_msg) printf(" %s\n", arg[i].help_msg); - if (arg[i].offset == (size_t) -1) + if (arg[i].offset == ISL_ARG_OFFSET_NONE) child = opt; else child = *(void **)(((char *) opt) + arg[i].offset); @@ -812,7 +812,7 @@ if (!has_argument && (!arg[1] || arg[1][0] == '-')) { unsigned u = decl->u.choice.default_selected; - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) *(unsigned *)(((char *)opt) + decl->offset) = u; if (decl->u.choice.set) decl->u.choice.set(opt, u); @@ -830,7 +830,7 @@ continue; u = decl->u.choice.choice[i].value; - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) *(unsigned *)(((char *)opt) + decl->offset) = u; if (decl->u.choice.set) decl->u.choice.set(opt, u); @@ -904,14 +904,14 @@ char *endptr; int val = strtol(arg[1], &endptr, 0); if (*endptr == '\0' && (val == 0 || val == 1)) { - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) *p = val; if (decl->u.b.set) decl->u.b.set(opt, val); return 2; } } - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) *p = 1; if (decl->u.b.set) decl->u.b.set(opt, 1); @@ -936,7 +936,7 @@ name = skip_prefixes(name, prefixes, &next_prefix); if (match_long_name(decl, name, name + strlen(name))) { - if (decl->offset != (size_t) -1) + if (decl->offset != ISL_ARG_OFFSET_NONE) *p = 0; if (decl->u.b.set) decl->u.b.set(opt, 0); @@ -1116,7 +1116,7 @@ void *child; int first, parsed; - if (decl->offset == (size_t) -1) + if (decl->offset == ISL_ARG_OFFSET_NONE) child = opt; else child = *(void **)(((char *)opt) + decl->offset); @@ -1240,7 +1240,7 @@ } /* Unless ISL_ARG_SKIP_HELP is set, check if "arg" is - * equal to "--help" and if so call print_help_and_exit. + * equal to "--help" or "-h" and if so call print_help_and_exit. */ static void check_help(struct isl_args *args, char *arg, char *prog, void *opt, unsigned flags) @@ -1248,7 +1248,7 @@ if (ISL_FL_ISSET(flags, ISL_ARG_SKIP_HELP)) return; - if (strcmp(arg, "--help") == 0) + if (strcmp(arg, "--help") == 0 || strcmp(arg, "-h") == 0) print_help_and_exit(args->args, prog, opt); } diff --git a/gcc/isl/isl_ast.c b/gcc/isl/isl_ast.c index 91d0e99..f0f7433 100644 --- a/gcc/isl/isl_ast.c +++ a/gcc/isl/isl_ast.c @@ -9,16 +9,17 @@ #include +#include #include #include -#undef BASE -#define BASE ast_expr +#undef EL_BASE +#define EL_BASE ast_expr #include -#undef BASE -#define BASE ast_node +#undef EL_BASE +#define EL_BASE ast_node #include @@ -104,7 +105,7 @@ /* Set the print_user callback of "options" to "print_user". * - * If this callback is set, then it used to print user nodes in the AST. + * If this callback is set, then it is used to print user nodes in the AST. * Otherwise, the expression associated to the user node is printed. */ __isl_give isl_ast_print_options *isl_ast_print_options_set_print_user( @@ -246,7 +247,7 @@ /* Return the integer value represented by "expr". */ -__isl_give isl_val *isl_ast_expr_get_val(__isl_keep isl_ast_expr *expr) +__isl_give isl_val *isl_ast_expr_int_get_val(__isl_keep isl_ast_expr *expr) { if (!expr) return NULL; @@ -256,7 +257,14 @@ return isl_val_copy(expr->u.v); } -__isl_give isl_id *isl_ast_expr_get_id(__isl_keep isl_ast_expr *expr) +/* This is an alternative name for the function above. + */ +__isl_give isl_val *isl_ast_expr_get_val(__isl_keep isl_ast_expr *expr) +{ + return isl_ast_expr_int_get_val(expr); +} + +__isl_give isl_id *isl_ast_expr_id_get_id(__isl_keep isl_ast_expr *expr) { if (!expr) return NULL; @@ -265,29 +273,59 @@ "expression not an identifier", return NULL); return isl_id_copy(expr->u.id); +} + +/* This is an alternative name for the function above. + */ +__isl_give isl_id *isl_ast_expr_get_id(__isl_keep isl_ast_expr *expr) +{ + return isl_ast_expr_id_get_id(expr); } -enum isl_ast_op_type isl_ast_expr_get_op_type(__isl_keep isl_ast_expr *expr) +/* Return the type of operation represented by "expr". + */ +enum isl_ast_expr_op_type isl_ast_expr_op_get_type( + __isl_keep isl_ast_expr *expr) { if (!expr) - return isl_ast_op_error; + return isl_ast_expr_op_error; if (expr->type != isl_ast_expr_op) isl_die(isl_ast_expr_get_ctx(expr), isl_error_invalid, - "expression not an operation", return isl_ast_op_error); + "expression not an operation", + return isl_ast_expr_op_error); return expr->u.op.op; +} + +/* This is an alternative name for the function above. + */ +enum isl_ast_expr_op_type isl_ast_expr_get_op_type( + __isl_keep isl_ast_expr *expr) +{ + return isl_ast_expr_op_get_type(expr); } -int isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr) +/* Return the number of arguments of the operation represented by "expr". + */ +isl_size isl_ast_expr_op_get_n_arg(__isl_keep isl_ast_expr *expr) { if (!expr) - return -1; + return isl_size_error; if (expr->type != isl_ast_expr_op) isl_die(isl_ast_expr_get_ctx(expr), isl_error_invalid, - "expression not an operation", return -1); + "expression not an operation", return isl_size_error); return expr->u.op.n_arg; } -__isl_give isl_ast_expr *isl_ast_expr_get_op_arg(__isl_keep isl_ast_expr *expr, +/* This is an alternative name for the function above. + */ +isl_size isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr) +{ + return isl_ast_expr_op_get_n_arg(expr); +} + +/* Return the argument at position "pos" of the operation represented by "expr". + */ +__isl_give isl_ast_expr *isl_ast_expr_op_get_arg(__isl_keep isl_ast_expr *expr, int pos) { if (!expr) @@ -300,6 +338,14 @@ "index out of bounds", return NULL); return isl_ast_expr_copy(expr->u.op.args[pos]); +} + +/* This is an alternative name for the function above. + */ +__isl_give isl_ast_expr *isl_ast_expr_get_op_arg(__isl_keep isl_ast_expr *expr, + int pos) +{ + return isl_ast_expr_op_get_arg(expr, pos); } /* Replace the argument at position "pos" of "expr" by "arg". @@ -344,7 +390,7 @@ case isl_ast_expr_int: return isl_val_eq(expr1->u.v, expr2->u.v); case isl_ast_expr_id: - return expr1->u.id == expr2->u.id; + return isl_bool_ok(expr1->u.id == expr2->u.id); case isl_ast_expr_op: if (expr1->u.op.op != expr2->u.op.op) return isl_bool_false; @@ -357,7 +403,7 @@ if (equal < 0 || !equal) return equal; } - return 1; + return isl_bool_true; case isl_ast_expr_error: return isl_bool_error; } @@ -370,7 +416,7 @@ * with "n_arg" as yet unspecified arguments. */ __isl_give isl_ast_expr *isl_ast_expr_alloc_op(isl_ctx *ctx, - enum isl_ast_op_type op, int n_arg) + enum isl_ast_expr_op_type op, int n_arg) { isl_ast_expr *expr; @@ -473,8 +519,8 @@ /* Create an expression representing the unary operation "type" applied to * "arg". */ -__isl_give isl_ast_expr *isl_ast_expr_alloc_unary(enum isl_ast_op_type type, - __isl_take isl_ast_expr *arg) +__isl_give isl_ast_expr *isl_ast_expr_alloc_unary( + enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *arg) { isl_ctx *ctx; isl_ast_expr *expr = NULL; @@ -499,7 +545,7 @@ */ __isl_give isl_ast_expr *isl_ast_expr_neg(__isl_take isl_ast_expr *arg) { - return isl_ast_expr_alloc_unary(isl_ast_op_minus, arg); + return isl_ast_expr_alloc_unary(isl_ast_expr_op_minus, arg); } /* Create an expression representing the address of "expr". @@ -510,18 +556,19 @@ return NULL; if (isl_ast_expr_get_type(expr) != isl_ast_expr_op || - isl_ast_expr_get_op_type(expr) != isl_ast_op_access) + isl_ast_expr_get_op_type(expr) != isl_ast_expr_op_access) isl_die(isl_ast_expr_get_ctx(expr), isl_error_invalid, "can only take address of access expressions", return isl_ast_expr_free(expr)); - return isl_ast_expr_alloc_unary(isl_ast_op_address_of, expr); + return isl_ast_expr_alloc_unary(isl_ast_expr_op_address_of, expr); } /* Create an expression representing the binary operation "type" * applied to "expr1" and "expr2". */ -__isl_give isl_ast_expr *isl_ast_expr_alloc_binary(enum isl_ast_op_type type, +__isl_give isl_ast_expr *isl_ast_expr_alloc_binary( + enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { isl_ctx *ctx; @@ -550,7 +597,7 @@ __isl_give isl_ast_expr *isl_ast_expr_add(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_add, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_add, expr1, expr2); } /* Create an expression representing the difference of "expr1" and "expr2". @@ -558,7 +605,7 @@ __isl_give isl_ast_expr *isl_ast_expr_sub(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_sub, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_sub, expr1, expr2); } /* Create an expression representing the product of "expr1" and "expr2". @@ -566,7 +613,7 @@ __isl_give isl_ast_expr *isl_ast_expr_mul(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_mul, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_mul, expr1, expr2); } /* Create an expression representing the quotient of "expr1" and "expr2". @@ -574,7 +621,7 @@ __isl_give isl_ast_expr *isl_ast_expr_div(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_div, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_div, expr1, expr2); } /* Create an expression representing the quotient of the integer @@ -584,7 +631,7 @@ __isl_give isl_ast_expr *isl_ast_expr_pdiv_q(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_pdiv_q, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_pdiv_q, expr1, expr2); } /* Create an expression representing the remainder of the integer @@ -594,7 +641,7 @@ __isl_give isl_ast_expr *isl_ast_expr_pdiv_r(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_pdiv_r, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_pdiv_r, expr1, expr2); } /* Create an expression representing the conjunction of "expr1" and "expr2". @@ -602,7 +649,7 @@ __isl_give isl_ast_expr *isl_ast_expr_and(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_and, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_and, expr1, expr2); } /* Create an expression representing the conjunction of "expr1" and "expr2", @@ -611,7 +658,7 @@ __isl_give isl_ast_expr *isl_ast_expr_and_then(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_and_then, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_and_then, expr1, expr2); } /* Create an expression representing the disjunction of "expr1" and "expr2". @@ -619,7 +666,7 @@ __isl_give isl_ast_expr *isl_ast_expr_or(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_or, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_or, expr1, expr2); } /* Create an expression representing the disjunction of "expr1" and "expr2", @@ -628,7 +675,7 @@ __isl_give isl_ast_expr *isl_ast_expr_or_else(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_or_else, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_or_else, expr1, expr2); } /* Create an expression representing "expr1" less than or equal to "expr2". @@ -636,7 +683,7 @@ __isl_give isl_ast_expr *isl_ast_expr_le(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_le, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_le, expr1, expr2); } /* Create an expression representing "expr1" less than "expr2". @@ -644,7 +691,7 @@ __isl_give isl_ast_expr *isl_ast_expr_lt(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_lt, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_lt, expr1, expr2); } /* Create an expression representing "expr1" greater than or equal to "expr2". @@ -652,7 +699,7 @@ __isl_give isl_ast_expr *isl_ast_expr_ge(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_ge, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_ge, expr1, expr2); } /* Create an expression representing "expr1" greater than "expr2". @@ -660,7 +707,7 @@ __isl_give isl_ast_expr *isl_ast_expr_gt(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_gt, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_gt, expr1, expr2); } /* Create an expression representing "expr1" equal to "expr2". @@ -668,17 +715,18 @@ __isl_give isl_ast_expr *isl_ast_expr_eq(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) { - return isl_ast_expr_alloc_binary(isl_ast_op_eq, expr1, expr2); + return isl_ast_expr_alloc_binary(isl_ast_expr_op_eq, expr1, expr2); } /* Create an expression of type "type" with as arguments "arg0" followed * by "arguments". */ static __isl_give isl_ast_expr *ast_expr_with_arguments( - enum isl_ast_op_type type, __isl_take isl_ast_expr *arg0, + enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *arg0, __isl_take isl_ast_expr_list *arguments) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_expr *res = NULL; @@ -687,6 +735,8 @@ ctx = isl_ast_expr_get_ctx(arg0); n = isl_ast_expr_list_n_ast_expr(arguments); + if (n < 0) + goto error; res = isl_ast_expr_alloc_op(ctx, type, 1 + n); if (!res) goto error; @@ -714,7 +764,7 @@ __isl_give isl_ast_expr *isl_ast_expr_access(__isl_take isl_ast_expr *array, __isl_take isl_ast_expr_list *indices) { - return ast_expr_with_arguments(isl_ast_op_access, array, indices); + return ast_expr_with_arguments(isl_ast_expr_op_access, array, indices); } /* Create an expression representing a call to "function" with argument @@ -723,7 +773,7 @@ __isl_give isl_ast_expr *isl_ast_expr_call(__isl_take isl_ast_expr *function, __isl_take isl_ast_expr_list *arguments) { - return ast_expr_with_arguments(isl_ast_op_call, function, arguments); + return ast_expr_with_arguments(isl_ast_expr_op_call, function, arguments); } /* For each subexpression of "expr" of type isl_ast_expr_id, @@ -941,15 +991,22 @@ __isl_give isl_ast_node *isl_ast_node_from_ast_node_list( __isl_take isl_ast_node_list *list) { + isl_size n; isl_ast_node *node; - if (isl_ast_node_list_n_ast_node(list) != 1) + n = isl_ast_node_list_n_ast_node(list); + if (n < 0) + goto error; + if (n != 1) return isl_ast_node_alloc_block(list); node = isl_ast_node_list_get_ast_node(list, 0); isl_ast_node_list_free(list); return node; +error: + isl_ast_node_list_free(list); + return NULL; } __isl_give isl_ast_node *isl_ast_node_copy(__isl_keep isl_ast_node *node) @@ -1119,7 +1176,7 @@ if (node->type != isl_ast_node_for) isl_die(isl_ast_node_get_ctx(node), isl_error_invalid, "not a for node", return isl_bool_error); - return node->u.f.degenerate; + return isl_bool_ok(node->u.f.degenerate); } __isl_give isl_ast_expr *isl_ast_node_for_get_iterator( @@ -1162,7 +1219,7 @@ if (!node->u.f.degenerate) return isl_ast_expr_copy(node->u.f.cond); - return isl_ast_expr_alloc_binary(isl_ast_op_le, + return isl_ast_expr_alloc_binary(isl_ast_expr_op_le, isl_ast_expr_copy(node->u.f.iterator), isl_ast_expr_copy(node->u.f.init)); } @@ -1207,7 +1264,9 @@ return NULL; } -__isl_give isl_ast_node *isl_ast_node_if_get_then( +/* Return the then-node of the given if-node. + */ +__isl_give isl_ast_node *isl_ast_node_if_get_then_node( __isl_keep isl_ast_node *node) { if (!node) @@ -1218,18 +1277,37 @@ return isl_ast_node_copy(node->u.i.then); } -isl_bool isl_ast_node_if_has_else( +/* This is an alternative name for the function above. + */ +__isl_give isl_ast_node *isl_ast_node_if_get_then( __isl_keep isl_ast_node *node) +{ + return isl_ast_node_if_get_then_node(node); +} + +/* Does the given if-node have an else-node? + */ +isl_bool isl_ast_node_if_has_else_node(__isl_keep isl_ast_node *node) { if (!node) return isl_bool_error; if (node->type != isl_ast_node_if) isl_die(isl_ast_node_get_ctx(node), isl_error_invalid, "not an if node", return isl_bool_error); - return node->u.i.else_node != NULL; + return isl_bool_ok(node->u.i.else_node != NULL); } -__isl_give isl_ast_node *isl_ast_node_if_get_else( +/* This is an alternative name for the function above. + */ +isl_bool isl_ast_node_if_has_else(__isl_keep isl_ast_node *node) +{ + return isl_ast_node_if_has_else_node(node); +} + +/* Return the else-node of the given if-node, + * assuming there is one. + */ +__isl_give isl_ast_node *isl_ast_node_if_get_else_node( __isl_keep isl_ast_node *node) { if (!node) @@ -1240,6 +1318,14 @@ return isl_ast_node_copy(node->u.i.else_node); } +/* This is an alternative name for the function above. + */ +__isl_give isl_ast_node *isl_ast_node_if_get_else( + __isl_keep isl_ast_node *node) +{ + return isl_ast_node_if_get_else_node(node); +} + __isl_give isl_ast_expr *isl_ast_node_if_get_cond( __isl_keep isl_ast_node *node) { @@ -1405,28 +1491,28 @@ /* Textual C representation of the various operators. */ static char *op_str_c[] = { - [isl_ast_op_and] = "&&", - [isl_ast_op_and_then] = "&&", - [isl_ast_op_or] = "||", - [isl_ast_op_or_else] = "||", - [isl_ast_op_max] = "max", - [isl_ast_op_min] = "min", - [isl_ast_op_minus] = "-", - [isl_ast_op_add] = "+", - [isl_ast_op_sub] = "-", - [isl_ast_op_mul] = "*", - [isl_ast_op_fdiv_q] = "floord", - [isl_ast_op_pdiv_q] = "/", - [isl_ast_op_pdiv_r] = "%", - [isl_ast_op_zdiv_r] = "%", - [isl_ast_op_div] = "/", - [isl_ast_op_eq] = "==", - [isl_ast_op_le] = "<=", - [isl_ast_op_ge] = ">=", - [isl_ast_op_lt] = "<", - [isl_ast_op_gt] = ">", - [isl_ast_op_member] = ".", - [isl_ast_op_address_of] = "&" + [isl_ast_expr_op_and] = "&&", + [isl_ast_expr_op_and_then] = "&&", + [isl_ast_expr_op_or] = "||", + [isl_ast_expr_op_or_else] = "||", + [isl_ast_expr_op_max] = "max", + [isl_ast_expr_op_min] = "min", + [isl_ast_expr_op_minus] = "-", + [isl_ast_expr_op_add] = "+", + [isl_ast_expr_op_sub] = "-", + [isl_ast_expr_op_mul] = "*", + [isl_ast_expr_op_fdiv_q] = "floord", + [isl_ast_expr_op_pdiv_q] = "/", + [isl_ast_expr_op_pdiv_r] = "%", + [isl_ast_expr_op_zdiv_r] = "%", + [isl_ast_expr_op_div] = "/", + [isl_ast_expr_op_eq] = "==", + [isl_ast_expr_op_le] = "<=", + [isl_ast_expr_op_ge] = ">=", + [isl_ast_expr_op_lt] = "<", + [isl_ast_expr_op_gt] = ">", + [isl_ast_expr_op_member] = ".", + [isl_ast_expr_op_address_of] = "&" }; /* Precedence in C of the various operators. @@ -1434,85 +1520,85 @@ * Lowest value means highest precedence. */ static int op_prec[] = { - [isl_ast_op_and] = 13, - [isl_ast_op_and_then] = 13, - [isl_ast_op_or] = 14, - [isl_ast_op_or_else] = 14, - [isl_ast_op_max] = 2, - [isl_ast_op_min] = 2, - [isl_ast_op_minus] = 3, - [isl_ast_op_add] = 6, - [isl_ast_op_sub] = 6, - [isl_ast_op_mul] = 5, - [isl_ast_op_div] = 5, - [isl_ast_op_fdiv_q] = 2, - [isl_ast_op_pdiv_q] = 5, - [isl_ast_op_pdiv_r] = 5, - [isl_ast_op_zdiv_r] = 5, - [isl_ast_op_cond] = 15, - [isl_ast_op_select] = 15, - [isl_ast_op_eq] = 9, - [isl_ast_op_le] = 8, - [isl_ast_op_ge] = 8, - [isl_ast_op_lt] = 8, - [isl_ast_op_gt] = 8, - [isl_ast_op_call] = 2, - [isl_ast_op_access] = 2, - [isl_ast_op_member] = 2, - [isl_ast_op_address_of] = 3 + [isl_ast_expr_op_and] = 13, + [isl_ast_expr_op_and_then] = 13, + [isl_ast_expr_op_or] = 14, + [isl_ast_expr_op_or_else] = 14, + [isl_ast_expr_op_max] = 2, + [isl_ast_expr_op_min] = 2, + [isl_ast_expr_op_minus] = 3, + [isl_ast_expr_op_add] = 6, + [isl_ast_expr_op_sub] = 6, + [isl_ast_expr_op_mul] = 5, + [isl_ast_expr_op_div] = 5, + [isl_ast_expr_op_fdiv_q] = 2, + [isl_ast_expr_op_pdiv_q] = 5, + [isl_ast_expr_op_pdiv_r] = 5, + [isl_ast_expr_op_zdiv_r] = 5, + [isl_ast_expr_op_cond] = 15, + [isl_ast_expr_op_select] = 15, + [isl_ast_expr_op_eq] = 9, + [isl_ast_expr_op_le] = 8, + [isl_ast_expr_op_ge] = 8, + [isl_ast_expr_op_lt] = 8, + [isl_ast_expr_op_gt] = 8, + [isl_ast_expr_op_call] = 2, + [isl_ast_expr_op_access] = 2, + [isl_ast_expr_op_member] = 2, + [isl_ast_expr_op_address_of] = 3 }; /* Is the operator left-to-right associative? */ static int op_left[] = { - [isl_ast_op_and] = 1, - [isl_ast_op_and_then] = 1, - [isl_ast_op_or] = 1, - [isl_ast_op_or_else] = 1, - [isl_ast_op_max] = 1, - [isl_ast_op_min] = 1, - [isl_ast_op_minus] = 0, - [isl_ast_op_add] = 1, - [isl_ast_op_sub] = 1, - [isl_ast_op_mul] = 1, - [isl_ast_op_div] = 1, - [isl_ast_op_fdiv_q] = 1, - [isl_ast_op_pdiv_q] = 1, - [isl_ast_op_pdiv_r] = 1, - [isl_ast_op_zdiv_r] = 1, - [isl_ast_op_cond] = 0, - [isl_ast_op_select] = 0, - [isl_ast_op_eq] = 1, - [isl_ast_op_le] = 1, - [isl_ast_op_ge] = 1, - [isl_ast_op_lt] = 1, - [isl_ast_op_gt] = 1, - [isl_ast_op_call] = 1, - [isl_ast_op_access] = 1, - [isl_ast_op_member] = 1, - [isl_ast_op_address_of] = 0 + [isl_ast_expr_op_and] = 1, + [isl_ast_expr_op_and_then] = 1, + [isl_ast_expr_op_or] = 1, + [isl_ast_expr_op_or_else] = 1, + [isl_ast_expr_op_max] = 1, + [isl_ast_expr_op_min] = 1, + [isl_ast_expr_op_minus] = 0, + [isl_ast_expr_op_add] = 1, + [isl_ast_expr_op_sub] = 1, + [isl_ast_expr_op_mul] = 1, + [isl_ast_expr_op_div] = 1, + [isl_ast_expr_op_fdiv_q] = 1, + [isl_ast_expr_op_pdiv_q] = 1, + [isl_ast_expr_op_pdiv_r] = 1, + [isl_ast_expr_op_zdiv_r] = 1, + [isl_ast_expr_op_cond] = 0, + [isl_ast_expr_op_select] = 0, + [isl_ast_expr_op_eq] = 1, + [isl_ast_expr_op_le] = 1, + [isl_ast_expr_op_ge] = 1, + [isl_ast_expr_op_lt] = 1, + [isl_ast_expr_op_gt] = 1, + [isl_ast_expr_op_call] = 1, + [isl_ast_expr_op_access] = 1, + [isl_ast_expr_op_member] = 1, + [isl_ast_expr_op_address_of] = 0 }; -static int is_and(enum isl_ast_op_type op) +static int is_and(enum isl_ast_expr_op_type op) { - return op == isl_ast_op_and || op == isl_ast_op_and_then; + return op == isl_ast_expr_op_and || op == isl_ast_expr_op_and_then; } -static int is_or(enum isl_ast_op_type op) +static int is_or(enum isl_ast_expr_op_type op) { - return op == isl_ast_op_or || op == isl_ast_op_or_else; + return op == isl_ast_expr_op_or || op == isl_ast_expr_op_or_else; } -static int is_add_sub(enum isl_ast_op_type op) +static int is_add_sub(enum isl_ast_expr_op_type op) { - return op == isl_ast_op_add || op == isl_ast_op_sub; + return op == isl_ast_expr_op_add || op == isl_ast_expr_op_sub; } -static int is_div_mod(enum isl_ast_op_type op) +static int is_div_mod(enum isl_ast_expr_op_type op) { - return op == isl_ast_op_div || - op == isl_ast_op_pdiv_r || - op == isl_ast_op_zdiv_r; + return op == isl_ast_expr_op_div || + op == isl_ast_expr_op_pdiv_r || + op == isl_ast_expr_op_zdiv_r; } static __isl_give isl_printer *print_ast_expr_c(__isl_take isl_printer *p, @@ -1536,7 +1622,7 @@ * Computations such as "a / b * c" and "a % b + c" can be somewhat * difficult to read, so we add parentheses for those as well. */ -static int sub_expr_need_parens(enum isl_ast_op_type op, +static int sub_expr_need_parens(enum isl_ast_expr_op_type op, __isl_keep isl_ast_expr *expr, int left) { if (expr->type != isl_ast_expr_op) @@ -1549,7 +1635,7 @@ if (is_or(op) && is_and(expr->u.op.op)) return 1; - if (op == isl_ast_op_mul && expr->u.op.op != isl_ast_op_mul && + if (op == isl_ast_expr_op_mul && expr->u.op.op != isl_ast_expr_op_mul && op_prec[expr->u.op.op] == op_prec[op]) return 1; if (is_add_sub(op) && is_div_mod(expr->u.op.op)) @@ -1562,7 +1648,7 @@ * If "left" is set, then "expr" is the left-most operand. */ static __isl_give isl_printer *print_sub_expr_c(__isl_take isl_printer *p, - enum isl_ast_op_type op, __isl_keep isl_ast_expr *expr, int left) + enum isl_ast_expr_op_type op, __isl_keep isl_ast_expr *expr, int left) { int need_parens; @@ -1576,46 +1662,46 @@ return p; } -#define isl_ast_op_last isl_ast_op_address_of +#define isl_ast_expr_op_last isl_ast_expr_op_address_of /* Data structure that holds the user-specified textual * representations for the operators in C format. * The entries are either NULL or copies of strings. * A NULL entry means that the default name should be used. */ -struct isl_ast_op_names { - char *op_str[isl_ast_op_last + 1]; +struct isl_ast_expr_op_names { + char *op_str[isl_ast_expr_op_last + 1]; }; -/* Create an empty struct isl_ast_op_names. +/* Create an empty struct isl_ast_expr_op_names. */ static void *create_names(isl_ctx *ctx) { - return isl_calloc_type(ctx, struct isl_ast_op_names); + return isl_calloc_type(ctx, struct isl_ast_expr_op_names); } -/* Free a struct isl_ast_op_names along with all memory +/* Free a struct isl_ast_expr_op_names along with all memory * owned by the struct. */ static void free_names(void *user) { int i; - struct isl_ast_op_names *names = user; + struct isl_ast_expr_op_names *names = user; if (!user) return; - for (i = 0; i <= isl_ast_op_last; ++i) + for (i = 0; i <= isl_ast_expr_op_last; ++i) free(names->op_str[i]); free(user); } /* Create an identifier that is used to store - * an isl_ast_op_names note. + * an isl_ast_expr_op_names note. */ static __isl_give isl_id *names_id(isl_ctx *ctx) { - return isl_id_alloc(ctx, "isl_ast_op_type_names", NULL); + return isl_id_alloc(ctx, "isl_ast_expr_op_type_names", NULL); } /* Ensure that "p" has a note identified by "id". @@ -1652,7 +1738,7 @@ return p; } -/* Ensure that "p" has an isl_ast_op_names note identified by "id". +/* Ensure that "p" has an isl_ast_expr_op_names note identified by "id". */ static __isl_give isl_printer *alloc_names(__isl_take isl_printer *p, __isl_keep isl_id *id) @@ -1676,19 +1762,19 @@ /* Use "name" to print operations of type "type" to "p". * - * Store the name in an isl_ast_op_names note attached to "p", such that + * Store the name in an isl_ast_expr_op_names note attached to "p", such that * it can be retrieved by get_op_str. */ -__isl_give isl_printer *isl_ast_op_type_set_print_name( - __isl_take isl_printer *p, enum isl_ast_op_type type, +__isl_give isl_printer *isl_ast_expr_op_type_set_print_name( + __isl_take isl_printer *p, enum isl_ast_expr_op_type type, __isl_keep const char *name) { isl_id *id; - struct isl_ast_op_names *names; + struct isl_ast_expr_op_names *names; if (!p) return NULL; - if (type > isl_ast_op_last) + if (type > isl_ast_expr_op_last) isl_die(isl_printer_get_ctx(p), isl_error_invalid, "invalid type", return isl_printer_free(p)); @@ -1702,20 +1788,29 @@ names->op_str[type] = strdup(name); return p; +} + +/* This is an alternative name for the function above. + */ +__isl_give isl_printer *isl_ast_op_type_set_print_name( + __isl_take isl_printer *p, enum isl_ast_expr_op_type type, + __isl_keep const char *name) +{ + return isl_ast_expr_op_type_set_print_name(p, type, name); } /* Return the textual representation of "type" in C format. * - * If there is a user-specified name in an isl_ast_op_names note + * If there is a user-specified name in an isl_ast_expr_op_names note * associated to "p", then return that. - * Otherwise, return the default name in op_str. + * Otherwise, return the default name in op_str_c. */ static const char *get_op_str_c(__isl_keep isl_printer *p, - enum isl_ast_op_type type) + enum isl_ast_expr_op_type type) { isl_id *id; isl_bool has_names; - struct isl_ast_op_names *names = NULL; + struct isl_ast_expr_op_names *names = NULL; id = names_id(isl_printer_get_ctx(p)); has_names = isl_printer_has_note(p, id); @@ -1800,11 +1895,11 @@ switch (expr->type) { case isl_ast_expr_op: - if (expr->u.op.op == isl_ast_op_call) { + if (expr->u.op.op == isl_ast_expr_op_call) { p = print_call_c(p, expr); break; } - if (expr->u.op.op == isl_ast_op_access) { + if (expr->u.op.op == isl_ast_expr_op_access) { p = print_access_c(p, expr); break; } @@ -1815,8 +1910,10 @@ expr->u.op.args[0], 0); break; } - if (expr->u.op.op == isl_ast_op_fdiv_q) { - const char *name = get_op_str_c(p, isl_ast_op_fdiv_q); + if (expr->u.op.op == isl_ast_expr_op_fdiv_q) { + const char *name; + + name = get_op_str_c(p, isl_ast_expr_op_fdiv_q); p = isl_printer_print_str(p, name); p = isl_printer_print_str(p, "("); p = print_ast_expr_c(p, expr->u.op.args[0]); @@ -1825,13 +1922,13 @@ p = isl_printer_print_str(p, ")"); break; } - if (expr->u.op.op == isl_ast_op_max || - expr->u.op.op == isl_ast_op_min) { + if (expr->u.op.op == isl_ast_expr_op_max || + expr->u.op.op == isl_ast_expr_op_min) { p = print_min_max_c(p, expr); break; } - if (expr->u.op.op == isl_ast_op_cond || - expr->u.op.op == isl_ast_op_select) { + if (expr->u.op.op == isl_ast_expr_op_cond || + expr->u.op.op == isl_ast_expr_op_select) { p = print_ast_expr_c(p, expr->u.op.args[0]); p = isl_printer_print_str(p, " ? "); p = print_ast_expr_c(p, expr->u.op.args[1]); @@ -1844,10 +1941,10 @@ "operation should have two arguments", return isl_printer_free(p)); p = print_sub_expr_c(p, expr->u.op.op, expr->u.op.args[0], 1); - if (expr->u.op.op != isl_ast_op_member) + if (expr->u.op.op != isl_ast_expr_op_member) p = isl_printer_print_str(p, " "); p = isl_printer_print_str(p, get_op_str_c(p, expr->u.op.op)); - if (expr->u.op.op != isl_ast_op_member) + if (expr->u.op.op != isl_ast_expr_op_member) p = isl_printer_print_str(p, " "); p = print_sub_expr_c(p, expr->u.op.op, expr->u.op.args[1], 0); break; @@ -1864,36 +1961,36 @@ return p; } -/* Textual representation of the isl_ast_op_type elements +/* Textual representation of the isl_ast_expr_op_type elements * for use in a YAML representation of an isl_ast_expr. */ static char *op_str[] = { - [isl_ast_op_and] = "and", - [isl_ast_op_and_then] = "and_then", - [isl_ast_op_or] = "or", - [isl_ast_op_or_else] = "or_else", - [isl_ast_op_max] = "max", - [isl_ast_op_min] = "min", - [isl_ast_op_minus] = "minus", - [isl_ast_op_add] = "add", - [isl_ast_op_sub] = "sub", - [isl_ast_op_mul] = "mul", - [isl_ast_op_div] = "div", - [isl_ast_op_fdiv_q] = "fdiv_q", - [isl_ast_op_pdiv_q] = "pdiv_q", - [isl_ast_op_pdiv_r] = "pdiv_r", - [isl_ast_op_zdiv_r] = "zdiv_r", - [isl_ast_op_cond] = "cond", - [isl_ast_op_select] = "select", - [isl_ast_op_eq] = "eq", - [isl_ast_op_le] = "le", - [isl_ast_op_lt] = "lt", - [isl_ast_op_ge] = "ge", - [isl_ast_op_gt] = "gt", - [isl_ast_op_call] = "call", - [isl_ast_op_access] = "access", - [isl_ast_op_member] = "member", - [isl_ast_op_address_of] = "address_of" + [isl_ast_expr_op_and] = "and", + [isl_ast_expr_op_and_then] = "and_then", + [isl_ast_expr_op_or] = "or", + [isl_ast_expr_op_or_else] = "or_else", + [isl_ast_expr_op_max] = "max", + [isl_ast_expr_op_min] = "min", + [isl_ast_expr_op_minus] = "minus", + [isl_ast_expr_op_add] = "add", + [isl_ast_expr_op_sub] = "sub", + [isl_ast_expr_op_mul] = "mul", + [isl_ast_expr_op_div] = "div", + [isl_ast_expr_op_fdiv_q] = "fdiv_q", + [isl_ast_expr_op_pdiv_q] = "pdiv_q", + [isl_ast_expr_op_pdiv_r] = "pdiv_r", + [isl_ast_expr_op_zdiv_r] = "zdiv_r", + [isl_ast_expr_op_cond] = "cond", + [isl_ast_expr_op_select] = "select", + [isl_ast_expr_op_eq] = "eq", + [isl_ast_expr_op_le] = "le", + [isl_ast_expr_op_lt] = "lt", + [isl_ast_expr_op_ge] = "ge", + [isl_ast_expr_op_gt] = "gt", + [isl_ast_expr_op_call] = "call", + [isl_ast_expr_op_access] = "access", + [isl_ast_expr_op_member] = "member", + [isl_ast_expr_op_address_of] = "address_of" }; static __isl_give isl_printer *print_ast_expr_isl(__isl_take isl_printer *p, @@ -1908,7 +2005,8 @@ static __isl_give isl_printer *print_arguments(__isl_take isl_printer *p, __isl_keep isl_ast_expr *expr) { - int i, n; + int i; + isl_size n; n = isl_ast_expr_get_op_n_arg(expr); if (n < 0) @@ -1940,7 +2038,7 @@ __isl_keep isl_ast_expr *expr) { enum isl_ast_expr_type type; - enum isl_ast_op_type op; + enum isl_ast_expr_op_type op; isl_id *id; isl_val *v; @@ -1954,7 +2052,7 @@ return isl_printer_free(p); case isl_ast_expr_op: op = isl_ast_expr_get_op_type(expr); - if (op == isl_ast_op_error) + if (op == isl_ast_expr_op_error) return isl_printer_free(p); p = isl_printer_print_str(p, "op"); p = isl_printer_yaml_next(p); @@ -2019,7 +2117,8 @@ static __isl_give isl_printer *print_ast_node_list(__isl_take isl_printer *p, __isl_keep isl_ast_node_list *list) { - int i, n; + int i; + isl_size n; n = isl_ast_node_list_n_ast_node(list); if (n < 0) @@ -2489,15 +2588,15 @@ return p; } -#define ISL_AST_MACRO_FLOORD (1 << 0) +#define ISL_AST_MACRO_FDIV_Q (1 << 0) #define ISL_AST_MACRO_MIN (1 << 1) #define ISL_AST_MACRO_MAX (1 << 2) -#define ISL_AST_MACRO_ALL (ISL_AST_MACRO_FLOORD | \ +#define ISL_AST_MACRO_ALL (ISL_AST_MACRO_FDIV_Q | \ ISL_AST_MACRO_MIN | \ ISL_AST_MACRO_MAX) -/* If "expr" contains an isl_ast_op_min, isl_ast_op_max or isl_ast_op_fdiv_q - * then set the corresponding bit in "macros". +/* If "expr" contains an isl_ast_expr_op_min, isl_ast_expr_op_max or + * isl_ast_expr_op_fdiv_q then set the corresponding bit in "macros". */ static int ast_expr_required_macros(__isl_keep isl_ast_expr *expr, int macros) { @@ -2509,12 +2608,12 @@ if (expr->type != isl_ast_expr_op) return macros; - if (expr->u.op.op == isl_ast_op_min) + if (expr->u.op.op == isl_ast_expr_op_min) macros |= ISL_AST_MACRO_MIN; - if (expr->u.op.op == isl_ast_op_max) + if (expr->u.op.op == isl_ast_expr_op_max) macros |= ISL_AST_MACRO_MAX; - if (expr->u.op.op == isl_ast_op_fdiv_q) - macros |= ISL_AST_MACRO_FLOORD; + if (expr->u.op.op == isl_ast_expr_op_fdiv_q) + macros |= ISL_AST_MACRO_FDIV_Q; for (i = 0; i < expr->u.op.n_arg; ++i) macros = ast_expr_required_macros(expr->u.op.args[i], macros); @@ -2525,8 +2624,8 @@ static int ast_node_list_required_macros(__isl_keep isl_ast_node_list *list, int macros); -/* If "node" contains an isl_ast_op_min, isl_ast_op_max or isl_ast_op_fdiv_q - * then set the corresponding bit in "macros". +/* If "node" contains an isl_ast_expr_op_min, isl_ast_expr_op_max or + * isl_ast_expr_op_fdiv_q then set the corresponding bit in "macros". */ static int ast_node_required_macros(__isl_keep isl_ast_node *node, int macros) { @@ -2568,8 +2667,8 @@ return macros; } -/* If "list" contains an isl_ast_op_min, isl_ast_op_max or isl_ast_op_fdiv_q - * then set the corresponding bit in "macros". +/* If "list" contains an isl_ast_expr_op_min, isl_ast_expr_op_max or + * isl_ast_expr_op_fdiv_q then set the corresponding bit in "macros". */ static int ast_node_list_required_macros(__isl_keep isl_ast_node_list *list, int macros) @@ -2586,25 +2685,25 @@ * for a given type has already been printed. * The value is zero if no definition has been printed and non-zero otherwise. */ -struct isl_ast_op_printed { - char printed[isl_ast_op_last + 1]; +struct isl_ast_expr_op_printed { + char printed[isl_ast_expr_op_last + 1]; }; -/* Create an empty struct isl_ast_op_printed. +/* Create an empty struct isl_ast_expr_op_printed. */ static void *create_printed(isl_ctx *ctx) { - return isl_calloc_type(ctx, struct isl_ast_op_printed); + return isl_calloc_type(ctx, struct isl_ast_expr_op_printed); } -/* Free a struct isl_ast_op_printed. +/* Free a struct isl_ast_expr_op_printed. */ static void free_printed(void *user) { free(user); } -/* Ensure that "p" has an isl_ast_op_printed note identified by "id". +/* Ensure that "p" has an isl_ast_expr_op_printed note identified by "id". */ static __isl_give isl_printer *alloc_printed(__isl_take isl_printer *p, __isl_keep isl_id *id) @@ -2613,11 +2712,11 @@ } /* Create an identifier that is used to store - * an isl_ast_op_printed note. + * an isl_ast_expr_op_printed note. */ static __isl_give isl_id *printed_id(isl_ctx *ctx) { - return isl_id_alloc(ctx, "isl_ast_op_type_printed", NULL); + return isl_id_alloc(ctx, "isl_ast_expr_op_type_printed", NULL); } /* Did the user specify that a macro definition should only be @@ -2629,11 +2728,11 @@ * The actual printing is taken care of by the caller. */ static isl_bool already_printed_once(__isl_keep isl_printer *p, - enum isl_ast_op_type type) + enum isl_ast_expr_op_type type) { isl_ctx *ctx; isl_id *id; - struct isl_ast_op_printed *printed; + struct isl_ast_expr_op_printed *printed; if (!p) return isl_bool_error; @@ -2642,7 +2741,7 @@ if (!isl_options_get_ast_print_macro_once(ctx)) return isl_bool_false; - if (type > isl_ast_op_last) + if (type > isl_ast_expr_op_last) isl_die(isl_printer_get_ctx(p), isl_error_invalid, "invalid type", return isl_bool_error); @@ -2666,8 +2765,8 @@ * only be printed once to any given printer and if the macro definition * has already been printed to "p", then do not print the definition. */ -__isl_give isl_printer *isl_ast_op_type_print_macro( - enum isl_ast_op_type type, __isl_take isl_printer *p) +__isl_give isl_printer *isl_ast_expr_op_type_print_macro( + enum isl_ast_expr_op_type type, __isl_take isl_printer *p) { isl_bool skip; @@ -2678,7 +2777,7 @@ return p; switch (type) { - case isl_ast_op_min: + case isl_ast_expr_op_min: p = isl_printer_start_line(p); p = isl_printer_print_str(p, "#define "); p = isl_printer_print_str(p, get_op_str_c(p, type)); @@ -2686,7 +2785,7 @@ "(x,y) ((x) < (y) ? (x) : (y))"); p = isl_printer_end_line(p); break; - case isl_ast_op_max: + case isl_ast_expr_op_max: p = isl_printer_start_line(p); p = isl_printer_print_str(p, "#define "); p = isl_printer_print_str(p, get_op_str_c(p, type)); @@ -2694,7 +2793,7 @@ "(x,y) ((x) > (y) ? (x) : (y))"); p = isl_printer_end_line(p); break; - case isl_ast_op_fdiv_q: + case isl_ast_expr_op_fdiv_q: p = isl_printer_start_line(p); p = isl_printer_print_str(p, "#define "); p = isl_printer_print_str(p, get_op_str_c(p, type)); @@ -2710,17 +2809,26 @@ return p; } +/* This is an alternative name for the function above. + */ +__isl_give isl_printer *isl_ast_op_type_print_macro( + enum isl_ast_expr_op_type type, __isl_take isl_printer *p) +{ + return isl_ast_expr_op_type_print_macro(type, p); +} + /* Call "fn" for each type of operation represented in the "macros" * bit vector. */ -static isl_stat foreach_ast_op_type(int macros, - isl_stat (*fn)(enum isl_ast_op_type type, void *user), void *user) +static isl_stat foreach_ast_expr_op_type(int macros, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user) { - if (macros & ISL_AST_MACRO_MIN && fn(isl_ast_op_min, user) < 0) + if (macros & ISL_AST_MACRO_MIN && fn(isl_ast_expr_op_min, user) < 0) return isl_stat_error; - if (macros & ISL_AST_MACRO_MAX && fn(isl_ast_op_max, user) < 0) + if (macros & ISL_AST_MACRO_MAX && fn(isl_ast_expr_op_max, user) < 0) return isl_stat_error; - if (macros & ISL_AST_MACRO_FLOORD && fn(isl_ast_op_fdiv_q, user) < 0) + if (macros & ISL_AST_MACRO_FDIV_Q && + fn(isl_ast_expr_op_fdiv_q, user) < 0) return isl_stat_error; return isl_stat_ok; @@ -2729,8 +2837,8 @@ /* Call "fn" for each type of operation that appears in "expr" * and that requires a macro definition. */ -isl_stat isl_ast_expr_foreach_ast_op_type(__isl_keep isl_ast_expr *expr, - isl_stat (*fn)(enum isl_ast_op_type type, void *user), void *user) +isl_stat isl_ast_expr_foreach_ast_expr_op_type(__isl_keep isl_ast_expr *expr, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user) { int macros; @@ -2738,14 +2846,22 @@ return isl_stat_error; macros = ast_expr_required_macros(expr, 0); - return foreach_ast_op_type(macros, fn, user); + return foreach_ast_expr_op_type(macros, fn, user); } +/* This is an alternative name for the function above. + */ +isl_stat isl_ast_expr_foreach_ast_op_type(__isl_keep isl_ast_expr *expr, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user) +{ + return isl_ast_expr_foreach_ast_expr_op_type(expr, fn, user); +} + /* Call "fn" for each type of operation that appears in "node" * and that requires a macro definition. */ -isl_stat isl_ast_node_foreach_ast_op_type(__isl_keep isl_ast_node *node, - isl_stat (*fn)(enum isl_ast_op_type type, void *user), void *user) +isl_stat isl_ast_node_foreach_ast_expr_op_type(__isl_keep isl_ast_node *node, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user) { int macros; @@ -2753,14 +2869,23 @@ return isl_stat_error; macros = ast_node_required_macros(node, 0); - return foreach_ast_op_type(macros, fn, user); + return foreach_ast_expr_op_type(macros, fn, user); } -static isl_stat ast_op_type_print_macro(enum isl_ast_op_type type, void *user) +/* This is an alternative name for the function above. + */ +isl_stat isl_ast_node_foreach_ast_op_type(__isl_keep isl_ast_node *node, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user) +{ + return isl_ast_node_foreach_ast_expr_op_type(node, fn, user); +} + +static isl_stat ast_op_type_print_macro(enum isl_ast_expr_op_type type, + void *user) { isl_printer **p = user; - *p = isl_ast_op_type_print_macro(type, *p); + *p = isl_ast_expr_op_type_print_macro(type, *p); return isl_stat_ok; } @@ -2771,7 +2896,7 @@ __isl_give isl_printer *isl_ast_expr_print_macros( __isl_keep isl_ast_expr *expr, __isl_take isl_printer *p) { - if (isl_ast_expr_foreach_ast_op_type(expr, + if (isl_ast_expr_foreach_ast_expr_op_type(expr, &ast_op_type_print_macro, &p) < 0) return isl_printer_free(p); return p; @@ -2783,7 +2908,7 @@ __isl_give isl_printer *isl_ast_node_print_macros( __isl_keep isl_ast_node *node, __isl_take isl_printer *p) { - if (isl_ast_node_foreach_ast_op_type(node, + if (isl_ast_node_foreach_ast_expr_op_type(node, &ast_op_type_print_macro, &p) < 0) return isl_printer_free(p); return p; diff --git a/gcc/isl/isl_ast_build.c b/gcc/isl/isl_ast_build.c index c7be0a9..1c4cbd9 100644 --- a/gcc/isl/isl_ast_build.c +++ a/gcc/isl/isl_ast_build.c @@ -10,6 +10,7 @@ * B.P. 105 - 78153 Le Chesnay, France */ +#include #include #include #include @@ -56,13 +57,17 @@ { isl_ctx *ctx; isl_vec *strides; + isl_size dim; build = isl_ast_build_cow(build); if (!build || !build->domain) goto error; ctx = isl_ast_build_get_ctx(build); - strides = isl_vec_alloc(ctx, isl_space_dim(space, isl_dim_set)); + dim = isl_space_dim(space, isl_dim_set); + if (dim < 0) + goto error; + strides = isl_vec_alloc(ctx, dim); strides = isl_vec_set_si(strides, 1); isl_vec_free(build->strides); @@ -113,14 +118,16 @@ */ __isl_give isl_ast_build *isl_ast_build_from_context(__isl_take isl_set *set) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_space *space; isl_ast_build *build; set = isl_set_compute_divs(set); - if (!set) - return NULL; + n = isl_set_dim(set, isl_dim_set); + if (n < 0) + goto error; ctx = isl_set_get_ctx(set); @@ -133,7 +140,6 @@ build->generated = isl_set_copy(build->domain); build->pending = isl_set_universe(isl_set_get_space(build->domain)); build->options = isl_union_map_empty(isl_space_params_alloc(ctx, 0)); - n = isl_set_dim(set, isl_dim_set); build->depth = n; build->iterators = isl_id_list_alloc(ctx, n); for (i = 0; i < n; ++i) { @@ -357,14 +363,16 @@ __isl_give isl_ast_build *isl_ast_build_set_iterators( __isl_take isl_ast_build *build, __isl_take isl_id_list *iterators) { - int dim, n_it; + isl_size dim, n_it; build = isl_ast_build_cow(build); if (!build) goto error; - dim = isl_set_dim(build->domain, isl_dim_set); + dim = isl_ast_build_dim(build, isl_dim_set); n_it = isl_id_list_n_id(build->iterators); + if (dim < 0 || n_it < 0) + goto error; if (n_it < dim) isl_die(isl_ast_build_get_ctx(build), isl_error_internal, "isl_ast_build in inconsistent state", goto error); @@ -561,15 +569,14 @@ * if code has been generated for the entire schedule and if none * of the loops have been eliminated. */ -__isl_give int isl_ast_build_need_schedule_map(__isl_keep isl_ast_build *build) +isl_bool isl_ast_build_need_schedule_map(__isl_keep isl_ast_build *build) { - int dim; - - if (!build) - return -1; + isl_size dim; - dim = isl_set_dim(build->domain, isl_dim_set); - return build->depth != dim || any_eliminated(build); + dim = isl_ast_build_dim(build, isl_dim_set); + if (dim < 0) + return isl_bool_error; + return isl_bool_ok(build->depth != dim || any_eliminated(build)); } /* Return a mapping from the internal schedule space to the external @@ -593,6 +600,7 @@ __isl_give isl_multi_aff *isl_ast_build_get_schedule_map_multi_aff( __isl_keep isl_ast_build *build) { + isl_bool needs_map; isl_space *space; isl_multi_aff *ma; @@ -600,13 +608,19 @@ return NULL; if (build->schedule_map) return isl_multi_aff_copy(build->schedule_map); + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) + return NULL; space = isl_ast_build_get_space(build, 1); space = isl_space_map_from_set(space); ma = isl_multi_aff_identity(space); - if (isl_ast_build_need_schedule_map(build)) { + if (needs_map) { int i; - int dim = isl_set_dim(build->domain, isl_dim_set); + isl_size dim = isl_ast_build_dim(build, isl_dim_set); + + if (dim < 0) + ma = isl_multi_aff_free(ma); ma = isl_multi_aff_drop_dims(ma, isl_dim_out, build->depth, dim - build->depth); for (i = build->depth - 1; i >= 0; --i) @@ -761,7 +775,8 @@ static __isl_give isl_ast_build *update_values( __isl_take isl_ast_build *build, __isl_take isl_basic_set *bounds) { - int sv; + isl_bool sv; + isl_size n; isl_pw_multi_aff *pma; isl_aff *aff = NULL; isl_map *it_map; @@ -786,10 +801,10 @@ build->value = isl_pw_aff_coalesce(build->value); isl_pw_multi_aff_free(pma); - if (!build->value) + n = isl_pw_aff_n_piece(build->value); + if (n < 0) return isl_ast_build_free(build); - - if (isl_pw_aff_n_piece(build->value) != 1) + if (n != 1) return build; isl_pw_aff_foreach_piece(build->value, &extract_single_piece, &aff); @@ -991,15 +1006,24 @@ __isl_give isl_ast_build *isl_ast_build_restrict( __isl_take isl_ast_build *build, __isl_take isl_set *set) { + isl_bool needs_map; + if (isl_set_is_params(set)) return isl_ast_build_restrict_generated(build, set); - if (isl_ast_build_need_schedule_map(build)) { + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) + goto error; + if (needs_map) { isl_multi_aff *ma; ma = isl_ast_build_get_schedule_map_multi_aff(build); set = isl_set_preimage_multi_aff(set, ma); } return isl_ast_build_restrict_generated(build, set); +error: + isl_ast_build_free(build); + isl_set_free(set); + return NULL; } /* Replace build->executed by "executed". @@ -1048,18 +1072,22 @@ __isl_take isl_ast_build *build) { int i; + isl_size n; isl_ctx *ctx; isl_schedule_node *node; if (!build) return NULL; + n = isl_schedule_node_band_n_member(build->node); + if (n < 0) + return isl_ast_build_free(build); ctx = isl_ast_build_get_ctx(build); if (!build->node) isl_die(ctx, isl_error_internal, "missing AST node", return isl_ast_build_free(build)); free(build->loop_type); - build->n = isl_schedule_node_band_n_member(build->node); + build->n = n; build->loop_type = isl_alloc_array(ctx, enum isl_ast_loop_type, build->n); if (build->n && !build->loop_type) @@ -1145,11 +1173,11 @@ /* Return the number of variables of the given type * in the (internal) schedule space. */ -unsigned isl_ast_build_dim(__isl_keep isl_ast_build *build, +isl_size isl_ast_build_dim(__isl_keep isl_ast_build *build, enum isl_dim_type type) { if (!build) - return 0; + return isl_size_error; return isl_set_dim(build->domain, type); } @@ -1166,7 +1194,8 @@ int internal) { int i; - int dim; + isl_size dim; + isl_bool needs_map; isl_space *space; if (!build) @@ -1176,10 +1205,15 @@ if (internal) return space; - if (!isl_ast_build_need_schedule_map(build)) + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) + return isl_space_free(space); + if (!needs_map) return space; - dim = isl_set_dim(build->domain, isl_dim_set); + dim = isl_ast_build_dim(build, isl_dim_set); + if (dim < 0) + return isl_space_free(space); space = isl_space_drop_dims(space, isl_dim_set, build->depth, dim - build->depth); for (i = build->depth - 1; i >= 0; --i) { @@ -1231,14 +1265,16 @@ __isl_give isl_union_map *isl_ast_build_get_schedule( __isl_keep isl_ast_build *build) { + isl_bool needs_map; isl_union_map *executed; isl_union_map *schedule; - if (!build) + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) return NULL; executed = isl_union_map_copy(build->executed); - if (isl_ast_build_need_schedule_map(build)) { + if (needs_map) { isl_map *proj = isl_ast_build_get_schedule_map(build); executed = isl_union_map_apply_domain(executed, isl_union_map_from_map(proj)); @@ -1819,7 +1855,7 @@ isl_vec *strides; isl_set *set; isl_multi_aff *embedding; - int dim, n_it; + isl_size dim, space_dim, n_it; build = isl_ast_build_cow(build); if (!build) @@ -1828,9 +1864,12 @@ build->outer_pos = build->depth; ctx = isl_ast_build_get_ctx(build); - dim = isl_set_dim(build->domain, isl_dim_set); - dim += isl_space_dim(space, isl_dim_set); + dim = isl_ast_build_dim(build, isl_dim_set); + space_dim = isl_space_dim(space, isl_dim_set); n_it = isl_id_list_n_id(build->iterators); + if (dim < 0 || space_dim < 0 || n_it < 0) + goto error; + dim += space_dim; if (n_it < dim) { isl_id_list *l; l = generate_names(ctx, dim - n_it, n_it, build); @@ -1845,7 +1884,7 @@ build->pending = isl_set_product(build->pending, isl_set_copy(set)); build->generated = isl_set_product(build->generated, set); - strides = isl_vec_alloc(ctx, isl_space_dim(space, isl_dim_set)); + strides = isl_vec_alloc(ctx, space_dim); strides = isl_vec_set_si(strides, 1); build->strides = isl_vec_concat(build->strides, strides); diff --git a/gcc/isl/isl_ast_build_expr.c b/gcc/isl/isl_ast_build_expr.c index 76cd57f..769d56f 100644 --- a/gcc/isl/isl_ast_build_expr.c +++ a/gcc/isl/isl_ast_build_expr.c @@ -10,6 +10,7 @@ * B.P. 105 - 78153 Le Chesnay, France */ +#include #include #include #include @@ -187,14 +188,14 @@ isl_aff *aff; isl_ast_expr *num, *den; isl_val *d; - enum isl_ast_op_type type; + enum isl_ast_expr_op_type type; aff = isl_local_space_get_div(ls, pos); d = isl_aff_get_denominator_val(aff); aff = isl_aff_scale_val(aff, isl_val_copy(d)); den = isl_ast_expr_from_val(isl_val_copy(d)); - type = isl_ast_op_fdiv_q; + type = isl_ast_expr_op_fdiv_q; if (isl_options_get_ast_build_prefer_pdiv(ctx)) { int non_neg = isl_ast_build_aff_is_nonneg(data->build, aff); if (non_neg >= 0 && !non_neg) { @@ -216,7 +217,7 @@ if (non_neg < 0) aff = isl_aff_free(aff); else if (non_neg) - type = isl_ast_op_pdiv_q; + type = isl_ast_expr_op_pdiv_q; } isl_val_free(d); @@ -296,11 +297,11 @@ * If expr2 is zero, we simply return expr1. * If expr1 is zero, we return * - * (isl_ast_op_minus, expr2) + * (isl_ast_expr_op_minus, expr2) * * Otherwise, we return * - * (isl_ast_op_sub, expr1, expr2) + * (isl_ast_expr_op_sub, expr1, expr2) */ static __isl_give isl_ast_expr *ast_expr_sub(__isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2) @@ -345,7 +346,7 @@ expr = isl_ast_expr_from_aff(isl_aff_copy(aff), build); c = isl_ast_expr_from_val(isl_val_copy(d)); - expr = isl_ast_expr_alloc_binary(isl_ast_op_pdiv_r, expr, c); + expr = isl_ast_expr_alloc_binary(isl_ast_expr_op_pdiv_r, expr, c); if (!isl_val_is_one(v)) { c = isl_ast_expr_from_val(isl_val_copy(v)); @@ -360,11 +361,11 @@ * If v is 1, we simply return expr. * If v is -1, we return * - * (isl_ast_op_minus, expr) + * (isl_ast_expr_op_minus, expr) * * Otherwise, we return * - * (isl_ast_op_mul, expr(v), expr) + * (isl_ast_expr_op_mul, expr(v), expr) */ static __isl_give isl_ast_expr *scale(__isl_take isl_ast_expr *expr, __isl_take isl_val *v) @@ -403,17 +404,17 @@ * multiplied by the absolute value of "*v". * If "*v" is negative, we create * - * (isl_ast_op_sub, expr, e) + * (isl_ast_expr_op_sub, expr, e) * * except when expr is trivially zero, in which case we create * - * (isl_ast_op_minus, e) + * (isl_ast_expr_op_minus, e) * * instead. * * If "*v" is positive, we simply create * - * (isl_ast_op_add, expr, e) + * (isl_ast_expr_op_add, expr, e) * */ static __isl_give isl_ast_expr *isl_ast_expr_add_term( @@ -678,11 +679,13 @@ enum isl_dim_type c_type[2] = { isl_dim_param, isl_dim_set }; enum isl_dim_type a_type[2] = { isl_dim_param, isl_dim_in }; int i, t; - int n[2]; + isl_size n[2]; int parallel = 1, opposite = 1; for (t = 0; t < 2; ++t) { n[t] = isl_constraint_dim(c, c_type[t]); + if (n[t] < 0) + return isl_stat_error; for (i = 0; i < n[t]; ++i) { int a, b; @@ -823,12 +826,15 @@ { isl_basic_set *hull; isl_val *v1, *v2; - int r, n; + isl_stat r; + isl_size n; if (!data->build) goto error; n = isl_aff_dim(data->div, isl_dim_div); + if (n < 0) + goto error; if (isl_aff_involves_dims(data->div, isl_dim_div, 0, n)) return extract_nonneg_mod(data); @@ -900,7 +906,7 @@ * * Note that in order to represent "a mod m" as * - * (isl_ast_op_pdiv_r, a, m) + * (isl_ast_expr_op_pdiv_r, a, m) * * we need to make sure that a is non-negative. * If not, we check if "-a + m - 1" is non-negative. @@ -953,7 +959,7 @@ { struct isl_extract_mod_data data = { build, aff, *pos, *neg }; isl_ctx *ctx; - int n; + isl_size n; if (!aff) return NULL; @@ -963,6 +969,8 @@ return aff; n = isl_aff_dim(data.aff, isl_dim_div); + if (n < 0) + return isl_aff_free(aff); for (data.i = 0; data.i < n; ++data.i) { data.v = isl_aff_get_coefficient_val(data.aff, isl_dim_div, data.i); @@ -999,7 +1007,8 @@ static __isl_give isl_aff *extract_rational(__isl_take isl_aff *aff, __isl_keep isl_ast_expr **expr, __isl_keep isl_ast_build *build) { - int i, j, n; + int i, j; + isl_size n; isl_aff *rat = NULL; isl_local_space *ls = NULL; isl_ast_expr *rat_expr; @@ -1024,6 +1033,8 @@ for (i = 0; i < 3; ++i) { n = isl_aff_dim(aff, t[i]); + if (n < 0) + goto error; for (j = 0; j < n; ++j) { isl_aff *rat_j; @@ -1081,7 +1092,7 @@ __isl_keep isl_ast_build *build) { int i, j; - int n; + isl_size n; isl_val *v; isl_ctx *ctx = isl_aff_get_ctx(aff); isl_ast_expr *expr, *expr_neg; @@ -1107,6 +1118,8 @@ data.cst = isl_aff_get_constant_val(aff); for (i = 0; i < 3; ++i) { n = isl_aff_dim(aff, t[i]); + if (n < 0) + expr = isl_ast_expr_free(expr); for (j = 0; j < n; ++j) { v = isl_aff_get_coefficient_val(aff, t[i], j); if (!v) @@ -1143,7 +1156,9 @@ ls = isl_aff_get_domain_local_space(aff); for (i = 0; i < 3; ++i) { - int n = isl_aff_dim(aff, t[i]); + isl_size n = isl_aff_dim(aff, t[i]); + if (n < 0) + expr = isl_ast_expr_free(expr); for (j = 0; j < n; ++j) { v = isl_aff_get_coefficient_val(aff, t[i], j); if (sign * isl_val_sgn(v) <= 0) { @@ -1234,24 +1249,26 @@ /* Are all coefficients of "aff" (zero or) negative? */ -static int all_negative_coefficients(__isl_keep isl_aff *aff) +static isl_bool all_negative_coefficients(__isl_keep isl_aff *aff) { - int i, n; - - if (!aff) - return 0; + int i; + isl_size n; n = isl_aff_dim(aff, isl_dim_param); + if (n < 0) + return isl_bool_error; for (i = 0; i < n; ++i) if (isl_aff_coefficient_sgn(aff, isl_dim_param, i) > 0) - return 0; + return isl_bool_false; n = isl_aff_dim(aff, isl_dim_in); + if (n < 0) + return isl_bool_error; for (i = 0; i < n; ++i) if (isl_aff_coefficient_sgn(aff, isl_dim_in, i) > 0) - return 0; + return isl_bool_false; - return 1; + return isl_bool_true; } /* Give an equality of the form @@ -1265,17 +1282,20 @@ * with the integer division "pos" equal to floor(e/d), * construct the AST expression * - * (isl_ast_op_eq, (isl_ast_op_zdiv_r, expr(e), expr(d)), expr(0)) + * (isl_ast_expr_op_eq, + * (isl_ast_expr_op_zdiv_r, expr(e), expr(d)), expr(0)) * * If e only has negative coefficients, then construct * - * (isl_ast_op_eq, (isl_ast_op_zdiv_r, expr(-e), expr(d)), expr(0)) + * (isl_ast_expr_op_eq, + * (isl_ast_expr_op_zdiv_r, expr(-e), expr(d)), expr(0)) * * instead. */ static __isl_give isl_ast_expr *extract_stride_constraint( __isl_take isl_aff *aff, int pos, __isl_keep isl_ast_build *build) { + isl_bool all_neg; isl_ctx *ctx; isl_val *c; isl_ast_expr *expr, *cst; @@ -1288,15 +1308,18 @@ c = isl_aff_get_coefficient_val(aff, isl_dim_div, pos); aff = isl_aff_set_coefficient_si(aff, isl_dim_div, pos, 0); - if (all_negative_coefficients(aff)) + all_neg = all_negative_coefficients(aff); + if (all_neg < 0) + aff = isl_aff_free(aff); + else if (all_neg) aff = isl_aff_neg(aff); cst = isl_ast_expr_from_val(isl_val_abs(c)); expr = isl_ast_expr_from_aff(aff, build); - expr = isl_ast_expr_alloc_binary(isl_ast_op_zdiv_r, expr, cst); + expr = isl_ast_expr_alloc_binary(isl_ast_expr_op_zdiv_r, expr, cst); cst = isl_ast_expr_alloc_int_si(ctx, 0); - expr = isl_ast_expr_alloc_binary(isl_ast_op_eq, expr, cst); + expr = isl_ast_expr_alloc_binary(isl_ast_expr_op_eq, expr, cst); return expr; } @@ -1314,7 +1337,8 @@ * * If so, we convert it to * - * (isl_ast_op_eq, (isl_ast_op_zdiv_r, expr(e), expr(d)), expr(0)) + * (isl_ast_expr_op_eq, + * (isl_ast_expr_op_zdiv_r, expr(e), expr(d)), expr(0)) * * Otherwise, let the constraint by either "a >= 0" or "a == 0". * We first extract hidden modulo computations from "a" @@ -1323,11 +1347,11 @@ * * The result is then of the form * - * (isl_ast_op_ge, expr(pos), expr(-neg))) + * (isl_ast_expr_op_ge, expr(pos), expr(-neg))) * * or * - * (isl_ast_op_eq, expr(pos), expr(-neg))) + * (isl_ast_expr_op_eq, expr(pos), expr(-neg))) * * However, if the first expression is an integer constant (and the second * is not), then we swap the two expressions. This ensures that we construct, @@ -1340,14 +1364,15 @@ static __isl_give isl_ast_expr *isl_ast_expr_from_constraint( __isl_take isl_constraint *constraint, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_expr *expr_pos; isl_ast_expr *expr_neg; isl_ast_expr *expr; isl_aff *aff; int eq; - enum isl_ast_op_type type; + enum isl_ast_expr_op_type type; struct isl_ast_add_term_data data; if (!constraint) @@ -1358,6 +1383,8 @@ isl_constraint_free(constraint); n = isl_aff_dim(aff, isl_dim_div); + if (n < 0) + aff = isl_aff_free(aff); if (eq && n > 0) for (i = 0; i < n; ++i) { int is_stride; @@ -1390,10 +1417,10 @@ if (isl_ast_expr_get_type(expr_pos) == isl_ast_expr_int && isl_ast_expr_get_type(expr_neg) != isl_ast_expr_int) { - type = eq ? isl_ast_op_eq : isl_ast_op_le; + type = eq ? isl_ast_expr_op_eq : isl_ast_expr_op_le; expr = isl_ast_expr_alloc_binary(type, expr_neg, expr_pos); } else { - type = eq ? isl_ast_op_eq : isl_ast_op_ge; + type = eq ? isl_ast_expr_op_eq : isl_ast_expr_op_ge; expr = isl_ast_expr_alloc_binary(type, expr_pos, expr_neg); } @@ -1423,7 +1450,7 @@ /* Construct an isl_ast_expr that evaluates the conditions defining "bset". * The result is simplified in terms of build->domain. * - * If "bset" is not bounded by any constraint, then we contruct + * If "bset" is not bounded by any constraint, then we construct * the expression "1", i.e., "true". * * Otherwise, we sort the constraints, putting constraints that involve @@ -1443,7 +1470,8 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_basic_set( __isl_keep isl_ast_build *build, __isl_take isl_basic_set *bset) { - int i, n; + int i; + isl_size n; isl_constraint *c; isl_constraint_list *list; isl_ast_expr *res; @@ -1452,9 +1480,9 @@ list = isl_basic_set_get_constraint_list(bset); isl_basic_set_free(bset); list = isl_constraint_list_sort(list, &cmp_constraint, NULL); - if (!list) - return NULL; n = isl_constraint_list_n_constraint(list); + if (n < 0) + build = NULL; if (n == 0) { isl_ctx *ctx = isl_constraint_list_get_ctx(list); isl_constraint_list_free(list); @@ -1509,7 +1537,8 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_set_internal( __isl_keep isl_ast_build *build, __isl_take isl_set *set) { - int i, n; + int i; + isl_size n; isl_basic_set *bset; isl_basic_set_list *list; isl_set *domain; @@ -1518,9 +1547,9 @@ list = isl_set_get_basic_set_list(set); isl_set_free(set); - if (!list) - return NULL; n = isl_basic_set_list_n_basic_set(list); + if (n < 0) + build = NULL; if (n == 0) { isl_ctx *ctx = isl_ast_build_get_ctx(build); isl_basic_set_list_free(list); @@ -1569,7 +1598,12 @@ __isl_give isl_ast_expr *isl_ast_build_expr_from_set( __isl_keep isl_ast_build *build, __isl_take isl_set *set) { - if (isl_ast_build_need_schedule_map(build)) { + isl_bool needs_map; + + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) { + set = isl_set_free(set); + } else if (needs_map) { isl_multi_aff *ma; ma = isl_ast_build_get_schedule_map_multi_aff(build); set = isl_set_preimage_multi_aff(set, ma); @@ -1645,11 +1679,13 @@ static isl_stat isl_from_pw_aff_data_init(struct isl_from_pw_aff_data *data, __isl_keep isl_ast_build *build, __isl_keep isl_pw_aff *pa) { - int n; + isl_size n; isl_ctx *ctx; ctx = isl_pw_aff_get_ctx(pa); n = isl_pw_aff_n_piece(pa); + if (n < 0) + return isl_stat_error; if (n == 0) isl_die(ctx, isl_error_invalid, "cannot handle void expression", return isl_stat_error); @@ -1770,10 +1806,11 @@ __isl_take isl_aff_list *list, enum isl_from_pw_aff_state state, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; isl_aff *aff; - isl_ast_expr *expr; - enum isl_ast_op_type op_type; + isl_ast_expr *expr = NULL; + enum isl_ast_expr_op_type op_type; if (state == isl_state_single) { aff = isl_aff_list_get_aff(list, 0); @@ -1781,7 +1818,10 @@ return isl_ast_expr_from_aff(aff, build); } n = isl_aff_list_n_aff(list); - op_type = state == isl_state_min ? isl_ast_op_min : isl_ast_op_max; + if (n < 0) + goto error; + op_type = state == isl_state_min ? isl_ast_expr_op_min + : isl_ast_expr_op_max; expr = isl_ast_expr_alloc_op(isl_ast_build_get_ctx(build), op_type, n); if (!expr) goto error; @@ -1828,7 +1868,7 @@ set = data->p[pos].set; data->p[pos].set = NULL; ctx = isl_ast_build_get_ctx(data->build); - ternary = isl_ast_expr_alloc_op(ctx, isl_ast_op_select, 3); + ternary = isl_ast_expr_alloc_op(ctx, isl_ast_expr_op_select, 3); gist = isl_set_gist(isl_set_copy(set), isl_set_copy(data->dom)); arg = isl_ast_build_expr_from_set_internal(data->build, gist); ternary = isl_ast_expr_set_op_arg(ternary, 0, arg); @@ -1891,7 +1931,7 @@ { const struct isl_from_pw_aff_piece *piece1 = p1; const struct isl_from_pw_aff_piece *piece2 = p2; - int n1, n2; + isl_size n1, n2; n1 = isl_set_n_basic_set(piece1->set); n2 = isl_set_n_basic_set(piece2->set); @@ -1982,10 +2022,14 @@ */ static isl_bool is_single_rational_aff(__isl_keep isl_aff_list *list) { + isl_size n; isl_bool rational; isl_aff *aff; - if (isl_aff_list_n_aff(list) != 1) + n = isl_aff_list_n_aff(list); + if (n < 0) + return isl_bool_error; + if (n != 1) return isl_bool_false; aff = isl_aff_list_get_aff(list, 0); rational = aff_is_rational(aff); @@ -2018,7 +2062,8 @@ __isl_give isl_basic_set *(*test)(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2)) { - int i, n; + int i; + isl_size n; isl_bool is_rational; isl_ctx *ctx; isl_set *dom; @@ -2032,11 +2077,14 @@ ctx = isl_ast_build_get_ctx(data->build); if (!isl_options_get_ast_build_detect_min_max(ctx)) return isl_bool_false; + + n = isl_set_list_n_set(data->p[data->n].set_list); + if (n < 0) + return isl_bool_error; dom = isl_ast_build_get_domain(data->build); set = isl_set_intersect(dom, isl_set_copy(set)); - n = isl_set_list_n_set(data->p[data->n].set_list); for (i = 0; i < n ; ++i) { isl_aff *aff_i; isl_set *valid; @@ -2205,8 +2253,12 @@ __isl_keep isl_ast_build *build, __isl_take isl_pw_aff *pa) { isl_ast_expr *expr; - - if (isl_ast_build_need_schedule_map(build)) { + isl_bool needs_map; + + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) { + pa = isl_pw_aff_free(pa); + } else if (needs_map) { isl_multi_aff *ma; ma = isl_ast_build_get_schedule_map_multi_aff(build); pa = isl_pw_aff_pullback_multi_aff(pa, ma); @@ -2223,9 +2275,12 @@ static __isl_give isl_multi_pw_aff *set_iterator_names( __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa) { - int i, n; + int i; + isl_size n; n = isl_multi_pw_aff_dim(mpa, isl_dim_in); + if (n < 0) + return isl_multi_pw_aff_free(mpa); for (i = 0; i < n; ++i) { isl_id *id; @@ -2242,17 +2297,18 @@ * with arguments/indices specified by "mpa". */ static __isl_give isl_ast_expr *isl_ast_build_with_arguments( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *arg0, __isl_take isl_multi_pw_aff *mpa) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_expr *expr; ctx = isl_ast_build_get_ctx(build); n = isl_multi_pw_aff_dim(mpa, isl_dim_out); - expr = isl_ast_expr_alloc_op(ctx, type, 1 + n); + expr = n >= 0 ? isl_ast_expr_alloc_op(ctx, type, 1 + n) : NULL; expr = isl_ast_expr_set_op_arg(expr, 0, arg0); for (i = 0; i < n; ++i) { isl_pw_aff *pa; @@ -2268,7 +2324,7 @@ } static __isl_give isl_ast_expr *isl_ast_build_from_multi_pw_aff_internal( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_multi_pw_aff *mpa); /* Construct an isl_ast_expr that accesses the member specified by "mpa". @@ -2285,7 +2341,7 @@ isl_id *id; isl_multi_pw_aff *domain; isl_ast_expr *domain_expr, *expr; - enum isl_ast_op_type type = isl_ast_op_access; + enum isl_ast_expr_op_type type = isl_ast_expr_op_access; domain = isl_multi_pw_aff_copy(mpa); domain = isl_multi_pw_aff_range_factor_domain(domain); @@ -2297,7 +2353,8 @@ "missing field name", goto error); id = isl_multi_pw_aff_get_tuple_id(mpa, isl_dim_out); expr = isl_ast_expr_from_id(id); - expr = isl_ast_expr_alloc_binary(isl_ast_op_member, domain_expr, expr); + expr = isl_ast_expr_alloc_binary(isl_ast_expr_op_member, + domain_expr, expr); return isl_ast_build_with_arguments(build, type, expr, mpa); error: isl_multi_pw_aff_free(mpa); @@ -2315,7 +2372,7 @@ * The domain of "mpa" is assumed to live in the internal schedule domain. */ static __isl_give isl_ast_expr *isl_ast_build_from_multi_pw_aff_internal( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_multi_pw_aff *mpa) { isl_ctx *ctx; @@ -2325,7 +2382,7 @@ if (!mpa) goto error; - if (type == isl_ast_op_access && + if (type == isl_ast_expr_op_access && isl_multi_pw_aff_range_is_wrapping(mpa)) return isl_ast_build_from_multi_pw_aff_member(build, mpa); @@ -2355,7 +2412,7 @@ * The domain of "pma" is assumed to live in the internal schedule domain. */ static __isl_give isl_ast_expr *isl_ast_build_from_pw_multi_aff_internal( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_pw_multi_aff *pma) { isl_multi_pw_aff *mpa; @@ -2372,10 +2429,11 @@ * The domain of "mpa" is assumed to live in the external schedule domain. */ static __isl_give isl_ast_expr *isl_ast_build_from_multi_pw_aff( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_multi_pw_aff *mpa) { - int is_domain; + isl_bool is_domain; + isl_bool needs_map; isl_ast_expr *expr; isl_space *space_build, *space_mpa; @@ -2391,7 +2449,10 @@ isl_die(isl_ast_build_get_ctx(build), isl_error_invalid, "spaces don't match", goto error); - if (isl_ast_build_need_schedule_map(build)) { + needs_map = isl_ast_build_need_schedule_map(build); + if (needs_map < 0) + goto error; + if (needs_map) { isl_multi_aff *ma; ma = isl_ast_build_get_schedule_map_multi_aff(build); mpa = isl_multi_pw_aff_pullback_multi_aff(mpa, ma); @@ -2413,7 +2474,8 @@ __isl_give isl_ast_expr *isl_ast_build_call_from_multi_pw_aff( __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa) { - return isl_ast_build_from_multi_pw_aff(build, isl_ast_op_call, mpa); + return isl_ast_build_from_multi_pw_aff(build, + isl_ast_expr_op_call, mpa); } /* Construct an isl_ast_expr that accesses the array element specified by "mpa". @@ -2425,7 +2487,8 @@ __isl_give isl_ast_expr *isl_ast_build_access_from_multi_pw_aff( __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa) { - return isl_ast_build_from_multi_pw_aff(build, isl_ast_op_access, mpa); + return isl_ast_build_from_multi_pw_aff(build, + isl_ast_expr_op_access, mpa); } /* Construct an isl_ast_expr of type "type" that calls or accesses @@ -2436,7 +2499,7 @@ * The domain of "pma" is assumed to live in the external schedule domain. */ static __isl_give isl_ast_expr *isl_ast_build_from_pw_multi_aff( - __isl_keep isl_ast_build *build, enum isl_ast_op_type type, + __isl_keep isl_ast_build *build, enum isl_ast_expr_op_type type, __isl_take isl_pw_multi_aff *pma) { isl_multi_pw_aff *mpa; @@ -2454,7 +2517,8 @@ __isl_give isl_ast_expr *isl_ast_build_call_from_pw_multi_aff( __isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma) { - return isl_ast_build_from_pw_multi_aff(build, isl_ast_op_call, pma); + return isl_ast_build_from_pw_multi_aff(build, + isl_ast_expr_op_call, pma); } /* Construct an isl_ast_expr that accesses the array element specified by "pma". @@ -2466,7 +2530,8 @@ __isl_give isl_ast_expr *isl_ast_build_access_from_pw_multi_aff( __isl_keep isl_ast_build *build, __isl_take isl_pw_multi_aff *pma) { - return isl_ast_build_from_pw_multi_aff(build, isl_ast_op_access, pma); + return isl_ast_build_from_pw_multi_aff(build, + isl_ast_expr_op_access, pma); } /* Construct an isl_ast_expr that calls the domain element @@ -2485,7 +2550,7 @@ iteration = isl_ast_build_compute_gist_pw_multi_aff(build, iteration); iteration = isl_pw_multi_aff_intersect_domain(iteration, isl_ast_build_get_domain(build)); - expr = isl_ast_build_from_pw_multi_aff_internal(build, isl_ast_op_call, - iteration); + expr = isl_ast_build_from_pw_multi_aff_internal(build, + isl_ast_expr_op_call, iteration); return isl_ast_node_alloc_user(expr); } diff --git a/gcc/isl/isl_ast_build_private.h b/gcc/isl/isl_ast_build_private.h index 77d4ffd..9767679 100644 --- a/gcc/isl/isl_ast_build_private.h +++ a/gcc/isl/isl_ast_build_private.h @@ -50,7 +50,7 @@ * * "strides" contains the stride of each loop. The number of elements * is equal to the number of dimensions in "domain". - * "offsets" constains the offsets of strided loops. If s is the stride + * "offsets" contains the offsets of strided loops. If s is the stride * for a given dimension and f is the corresponding offset, then the * dimension takes on values * @@ -133,7 +133,7 @@ * an AST from a schedule tree. It may be NULL if we are not generating * an AST from a schedule tree or if we are not inside a band node. * - * "loop_type" originally constains loop AST generation types for + * "loop_type" originally contains loop AST generation types for * the "n" members of "node" and it is updated (along with "n") when * a schedule dimension is inserted. * It is NULL if "node" is NULL. @@ -204,7 +204,7 @@ __isl_give isl_ast_build *isl_ast_build_increase_depth( __isl_take isl_ast_build *build); int isl_ast_build_get_depth(__isl_keep isl_ast_build *build); -unsigned isl_ast_build_dim(__isl_keep isl_ast_build *build, +isl_size isl_ast_build_dim(__isl_keep isl_ast_build *build, enum isl_dim_type type); __isl_give isl_space *isl_ast_build_get_space( __isl_keep isl_ast_build *build, int internal); @@ -244,8 +244,7 @@ __isl_take isl_ast_build *build, __isl_take isl_set *set); __isl_give isl_ast_build *isl_ast_build_replace_pending_by_guard( __isl_take isl_ast_build *build, __isl_take isl_set *guard); -__isl_give int isl_ast_build_need_schedule_map( - __isl_keep isl_ast_build *build); +isl_bool isl_ast_build_need_schedule_map(__isl_keep isl_ast_build *build); __isl_give isl_multi_aff *isl_ast_build_get_schedule_map_multi_aff( __isl_keep isl_ast_build *build); __isl_give isl_map *isl_ast_build_get_schedule_map( diff --git a/gcc/isl/isl_ast_codegen.c b/gcc/isl/isl_ast_codegen.c index 8f2e9c7..89cc725 100644 --- a/gcc/isl/isl_ast_codegen.c +++ a/gcc/isl/isl_ast_codegen.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -20,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +29,25 @@ #include #include +/* Try and reduce the number of disjuncts in the representation of "set", + * without dropping explicit representations of local variables. + */ +static __isl_give isl_set *isl_set_coalesce_preserve(__isl_take isl_set *set) +{ + isl_ctx *ctx; + int save_preserve; + + if (!set) + return NULL; + + ctx = isl_set_get_ctx(set); + save_preserve = isl_options_get_coalesce_preserve_locals(ctx); + isl_options_set_coalesce_preserve_locals(ctx, 1); + set = isl_set_coalesce(set); + isl_options_set_coalesce_preserve_locals(ctx, save_preserve); + return set; +} + /* Data used in generate_domain. * * "build" is the input build. @@ -143,7 +164,7 @@ guard = isl_map_domain(isl_map_copy(map)); guard = isl_set_compute_divs(guard); - guard = isl_set_coalesce(guard); + guard = isl_set_coalesce_preserve(guard); guard = isl_set_gist(guard, isl_ast_build_get_generated(build)); guard = isl_ast_build_specialize(build, guard); @@ -508,14 +529,15 @@ static __isl_give isl_pw_aff_list *remove_redundant_lower_bounds( __isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build) { - int i, j, n; + int i, j; + isl_size n; isl_set *domain; list = isl_pw_aff_list_sort(list, &reduce_list_cmp, NULL); - if (!list) - return NULL; n = isl_pw_aff_list_n_pw_aff(list); + if (n < 0) + return isl_pw_aff_list_free(list); if (n <= 1) return list; @@ -579,12 +601,15 @@ { isl_ctx *ctx; isl_pw_aff_list *list; - int i, n; + int i; + isl_size n; if (!build) return NULL; n = isl_constraint_list_n_constraint(constraints); + if (n < 0) + return NULL; if (n == 0) { isl_pw_aff *pa; pa = exact_bound(domain, build, 0); @@ -621,9 +646,12 @@ { isl_ctx *ctx; isl_pw_aff_list *list; - int i, n; + int i; + isl_size n; n = isl_constraint_list_n_constraint(constraints); + if (n < 0) + return NULL; if (n == 0) { isl_pw_aff *pa; pa = exact_bound(domain, build, 1); @@ -654,19 +682,19 @@ * If the list contains exactly one element, then the returned isl_ast_expr * simply computes that affine expression. * If the list contains more than one element, then we sort it - * using a fairly abitrary but hopefully reasonably stable order. + * using a fairly arbitrary but hopefully reasonably stable order. */ -static __isl_give isl_ast_expr *reduce_list(enum isl_ast_op_type type, +static __isl_give isl_ast_expr *reduce_list(enum isl_ast_expr_op_type type, __isl_keep isl_pw_aff_list *list, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_expr *expr; - - if (!list) - return NULL; n = isl_pw_aff_list_n_pw_aff(list); + if (n < 0) + return NULL; if (n == 1) return isl_ast_build_expr_from_pw_aff_internal(build, @@ -782,10 +810,13 @@ static __isl_give isl_set *intersect_constraints( __isl_keep isl_constraint_list *list) { - int i, n; + int i; + isl_size n; isl_basic_set *bset; n = isl_constraint_list_n_constraint(list); + if (n < 0) + return NULL; if (n < 1) isl_die(isl_constraint_list_get_ctx(list), isl_error_internal, "expecting at least one constraint", return NULL); @@ -838,9 +869,11 @@ isl_space *space; isl_basic_set *enforced; isl_pw_multi_aff *pma; - int i, n; + int i; + isl_size n; - if (!graft || !lower) + n = isl_pw_aff_list_n_pw_aff(lower); + if (!graft || n < 0) return isl_ast_graft_free(graft); space = isl_set_get_space(upper); @@ -849,7 +882,6 @@ space = isl_space_map_from_set(space); pma = isl_pw_multi_aff_identity(space); - n = isl_pw_aff_list_n_pw_aff(lower); for (i = 0; i < n; ++i) { isl_pw_aff *pa; isl_set *enforced_i; @@ -950,17 +982,21 @@ static __isl_give isl_pw_aff_list *list_add_one( __isl_take isl_pw_aff_list *list, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; isl_space *space; isl_aff *aff; isl_pw_aff *one; + n = isl_pw_aff_list_n_pw_aff(list); + if (n < 0) + return isl_pw_aff_list_free(list); + space = isl_ast_build_get_space(build, 1); aff = isl_aff_zero_on_domain(isl_local_space_from_space(space)); aff = isl_aff_add_constant_si(aff, 1); one = isl_pw_aff_from_aff(aff); - n = isl_pw_aff_list_n_pw_aff(list); for (i = 0; i < n; ++i) { isl_pw_aff *pa; pa = isl_pw_aff_list_get_pw_aff(list, i); @@ -992,7 +1028,7 @@ { int neg; isl_ast_expr *bound, *iterator, *cond; - enum isl_ast_op_type type = isl_ast_op_le; + enum isl_ast_expr_op_type type = isl_ast_expr_op_le; if (!graft || !list) return isl_ast_graft_free(graft); @@ -1003,10 +1039,10 @@ list = isl_pw_aff_list_copy(list); if (neg) { list = list_add_one(list, build); - type = isl_ast_op_lt; + type = isl_ast_expr_op_lt; } - bound = reduce_list(isl_ast_op_min, list, build); + bound = reduce_list(isl_ast_expr_op_min, list, build); iterator = isl_ast_expr_copy(graft->node->u.f.iterator); cond = isl_ast_expr_alloc_binary(type, iterator, bound); graft->node->u.f.cond = cond; @@ -1106,7 +1142,7 @@ build = isl_ast_build_copy(build); node = graft->node; - node->u.f.init = reduce_list(isl_ast_op_max, lower, build); + node->u.f.init = reduce_list(isl_ast_expr_op_max, lower, build); node->u.f.inc = for_inc(build); if (!node->u.f.init || !node->u.f.inc) @@ -1165,7 +1201,7 @@ int use_list; isl_set *upper_set = NULL; isl_pw_aff_list *upper_list = NULL; - int n_lower, n_upper; + isl_size n_lower, n_upper; if (!graft || !c_lower || !c_upper || !build) goto error; @@ -1175,6 +1211,8 @@ n_lower = isl_constraint_list_n_constraint(c_lower); n_upper = isl_constraint_list_n_constraint(c_upper); + if (n_lower < 0 || n_upper < 0) + goto error; use_list = use_upper_bound_list(ctx, n_upper, domain, depth); @@ -1457,6 +1495,7 @@ int depth; int degenerate; isl_bool eliminated; + isl_size n; isl_basic_set *hull; isl_basic_set *enforced; isl_set *guard, *hoisted; @@ -1501,7 +1540,10 @@ enforced = extract_shared_enforced(children, build); guard = extract_pending(sub_build, enforced); hoisted = isl_ast_graft_list_extract_hoistable_guard(children, build); - if (isl_set_n_basic_set(hoisted) > 1) + n = isl_set_n_basic_set(hoisted); + if (n < 0) + children = isl_ast_graft_list_free(children); + if (n > 1) children = isl_ast_graft_list_gist_guards(children, isl_set_copy(hoisted)); guard = isl_set_intersect(guard, hoisted); @@ -1558,7 +1600,8 @@ void *user) { struct isl_check_scaled_data *data = user; - int i, j, n; + int i, j; + isl_size n; enum isl_dim_type t[] = { isl_dim_param, isl_dim_in, isl_dim_out, isl_dim_div }; @@ -1569,6 +1612,8 @@ for (i = 0; i < 4; ++i) { n = isl_constraint_dim(c, t[i]); + if (n < 0) + break; for (j = 0; j < n; ++j) { isl_val *d; @@ -1749,16 +1794,18 @@ static __isl_give isl_basic_set_list *isl_basic_set_list_from_set( __isl_take isl_set *set) { - int n; + isl_size n; isl_ctx *ctx; isl_basic_set_list *list; + n = isl_set_n_basic_set(set); + if (n < 0) + set = isl_set_free(set); if (!set) return NULL; ctx = isl_set_get_ctx(set); - n = isl_set_n_basic_set(set); list = isl_basic_set_list_alloc(ctx, n); if (isl_set_foreach_basic_set(set, &collect_basic_set, &list) < 0) list = isl_basic_set_list_free(list); @@ -1848,7 +1895,7 @@ empty = isl_basic_map_is_empty(test); isl_basic_map_free(test); - return empty < 0 ? isl_bool_error : !empty; + return isl_bool_not(empty); } /* Split up each element of "list" into a part that is related to "bset" @@ -1859,15 +1906,16 @@ __isl_take isl_basic_set_list *list, __isl_take isl_basic_set *bset, __isl_keep isl_basic_map *gt) { - int i, n; + int i; + isl_size n; isl_basic_set_list *res; - if (!list) + n = isl_basic_set_list_n_basic_set(list); + if (n < 0) bset = isl_basic_set_free(bset); gt = isl_basic_map_copy(gt); gt = isl_basic_map_intersect_domain(gt, isl_basic_set_copy(bset)); - n = isl_basic_set_list_n_basic_set(list); res = isl_basic_set_list_from_basic_set(bset); for (i = 0; res && i < n; ++i) { isl_basic_set *bset; @@ -1955,13 +2003,16 @@ static isl_stat add_nodes(__isl_take isl_basic_set_list *scc, void *user) { struct isl_add_nodes_data *data = user; - int i, n, depth; + int i, depth; + isl_size n; isl_basic_set *bset, *first; isl_basic_set_list *list; isl_space *space; isl_basic_map *gt; n = isl_basic_set_list_n_basic_set(scc); + if (n < 0) + goto error; bset = isl_basic_set_list_get_basic_set(scc, 0); if (n == 1) { isl_basic_set_list_free(scc); @@ -2006,6 +2057,9 @@ isl_basic_set_list_free(scc); return data->list ? isl_stat_ok : isl_stat_error; +error: + isl_basic_set_list_free(scc); + return isl_stat_error; } /* Sort the domains in "domain_list" according to the execution order @@ -2028,13 +2082,13 @@ isl_ctx *ctx; struct isl_add_nodes_data data; int depth; - int n; + isl_size n; - if (!domain_list) + n = isl_basic_set_list_n_basic_set(domain_list); + if (n < 0) return NULL; ctx = isl_basic_set_list_get_ctx(domain_list); - n = isl_basic_set_list_n_basic_set(domain_list); data.list = isl_ast_graft_list_alloc(ctx, n); if (n == 0) return data.list; @@ -2072,7 +2126,7 @@ empty = isl_basic_map_is_empty(test); isl_basic_map_free(test); - return empty < 0 ? isl_bool_error : !empty; + return isl_bool_not(empty); } /* Internal data structure for generate_sorted_domains_wrap. @@ -2086,7 +2140,7 @@ * "list" collects the results. */ struct isl_ast_generate_parallel_domains_data { - int n; + isl_size n; isl_union_map *executed; isl_ast_build *build; @@ -2108,9 +2162,13 @@ { struct isl_ast_generate_parallel_domains_data *data = user; isl_ast_graft_list *list; + isl_size n; + n = isl_basic_set_list_n_basic_set(scc); + if (n < 0) + scc = isl_basic_set_list_free(scc); list = generate_sorted_domains(scc, data->executed, data->build); - data->single = isl_basic_set_list_n_basic_set(scc) == data->n; + data->single = n == data->n; if (!data->single) list = isl_ast_graft_list_fuse(list, data->build); if (!data->list) @@ -2148,10 +2206,10 @@ int depth; struct isl_ast_generate_parallel_domains_data data; - if (!domain_list) + data.n = isl_basic_set_list_n_basic_set(domain_list); + if (data.n < 0) return NULL; - data.n = isl_basic_set_list_n_basic_set(domain_list); if (data.n <= 1) return generate_sorted_domains(domain_list, executed, build); @@ -2211,9 +2269,12 @@ __isl_keep isl_ast_build *build) { isl_set *domain; - int depth, dim; + int depth; + isl_size dim; dim = isl_map_dim(map, isl_dim_out); + if (dim < 0) + return isl_map_domain(isl_map_free(map)); map = isl_map_drop_constraints_involving_dims(map, isl_dim_out, 0, dim); domain = isl_map_domain(map); @@ -2322,7 +2383,7 @@ return isl_equality_from_aff(aff); } -/* Update *user to the number of integer divsions in the first element +/* Update *user to the number of integer divisions in the first element * of "ma", if it is larger than the current value. */ static isl_stat update_n_div(__isl_take isl_set *set, @@ -2330,7 +2391,7 @@ { isl_aff *aff; int *n = user; - int n_div; + isl_size n_div; aff = isl_multi_aff_get_aff(ma, 0); n_div = isl_aff_dim(aff, isl_dim_div); @@ -2341,7 +2402,7 @@ if (n_div > *n) *n = n_div; - return aff ? isl_stat_ok : isl_stat_error; + return n_div >= 0 ? isl_stat_ok : isl_stat_error; } /* Get the number of integer divisions in the expression for the iterator @@ -2651,7 +2712,7 @@ * "executed" and "build" are inputs to compute_domains. * "schedule_domain" is the domain of "executed". * - * "option" constains the domains at the current depth that should by + * "option" contains the domains at the current depth that should by * atomic, separated or unrolled. These domains are as specified by * the user, except that inner dimensions have been eliminated and * that they have been made pair-wise disjoint. @@ -2765,8 +2826,9 @@ { isl_set *unroll_domain; isl_basic_set_list *unroll_list; - int i, n; - int empty; + int i; + isl_size n; + isl_bool empty; empty = isl_set_is_empty(domains->option[isl_ast_loop_unroll]); if (empty < 0) @@ -2778,6 +2840,8 @@ unroll_list = isl_basic_set_list_from_set(unroll_domain); n = isl_basic_set_list_n_basic_set(unroll_list); + if (n < 0) + class_domain = isl_set_free(class_domain); for (i = 0; i < n; ++i) { isl_basic_set *bset; @@ -2840,7 +2904,7 @@ } domain = isl_ast_build_eliminate(domains->build, domain); - domain = isl_set_coalesce(domain); + domain = isl_set_coalesce_preserve(domain); bset = isl_set_unshifted_simple_hull(domain); domain = isl_set_from_basic_set(bset); atomic_domain = isl_set_copy(domain); @@ -2958,7 +3022,7 @@ domain = isl_ast_build_eliminate(domains->build, domain); domain = isl_set_intersect(domain, isl_set_copy(class_domain)); - domain = isl_set_coalesce(domain); + domain = isl_set_coalesce_preserve(domain); domain = isl_set_make_disjoint(domain); list = isl_basic_set_list_from_set(domain); @@ -3062,7 +3126,7 @@ isl_space *space; int n_param; enum isl_ast_loop_type type; - int empty; + isl_bool empty; if (!executed) return NULL; @@ -3078,6 +3142,8 @@ domains.sep_class = isl_ast_build_get_separation_class(build); classes = isl_map_range(isl_map_copy(domains.sep_class)); n_param = isl_set_dim(classes, isl_dim_param); + if (n_param < 0) + classes = isl_set_free(classes); classes = isl_set_project_out(classes, isl_dim_param, 0, n_param); space = isl_set_get_space(domain); @@ -3237,14 +3303,21 @@ isl_basic_set *hull; isl_set *shared, *inner; isl_bool equal; - int depth, dim; + int depth; + isl_size n; + isl_size dim; - if (isl_set_n_basic_set(domain) <= 1) + n = isl_set_n_basic_set(domain); + if (n < 0) + return isl_bool_error; + if (n <= 1) return isl_bool_false; + dim = isl_set_dim(domain, isl_dim_set); + if (dim < 0) + return isl_bool_error; inner = isl_set_copy(domain); depth = isl_ast_build_get_depth(build); - dim = isl_set_dim(inner, isl_dim_set); inner = isl_set_drop_constraints_not_involving_dims(inner, isl_dim_set, depth, dim - depth); hull = isl_set_plain_unshifted_simple_hull(isl_set_copy(inner)); @@ -3315,7 +3388,7 @@ build); domain = isl_ast_build_eliminate(build, domain); - domain = isl_set_coalesce(domain); + domain = isl_set_coalesce_preserve(domain); outer_disjunction = has_pure_outer_disjunction(domain, build); if (outer_disjunction < 0) @@ -3354,11 +3427,14 @@ __isl_keep isl_ast_build *build) { isl_set *hull; - int depth, dim; + int depth; + isl_size dim; domain = isl_ast_build_specialize(build, domain); depth = isl_ast_build_get_depth(build); dim = isl_set_dim(domain, isl_dim_set); + if (dim < 0) + return isl_set_free(domain); domain = isl_set_eliminate(domain, isl_dim_set, depth, dim - depth); domain = isl_set_remove_unknown_divs(domain); hull = isl_set_copy(domain); @@ -3381,10 +3457,14 @@ __isl_keep isl_ast_build *build, __isl_keep isl_ast_build *sub_build) { isl_ast_graft *graft; + isl_size n; list = isl_ast_graft_list_fuse(list, sub_build); - if (isl_ast_graft_list_n_ast_graft(list) != 1) + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return isl_ast_graft_list_free(list); + if (n != 1) return list; graft = isl_ast_graft_list_get_ast_graft(list, 0); @@ -3880,7 +3960,7 @@ * with "<<" the lexicographic order, proving that the order is preserved * in all cases. */ -static __isl_give isl_union_map *contruct_shifted_executed( +static __isl_give isl_union_map *construct_shifted_executed( struct isl_set_map_pair *domain, int *order, int n, __isl_keep isl_val *stride, __isl_keep isl_multi_val *offset, __isl_take isl_ast_build *build) @@ -3951,9 +4031,9 @@ * domain is equal to zero. The other offsets are reduced modulo stride. * * Based on this information, we construct a new inverse schedule in - * contruct_shifted_executed that exposes the stride. + * construct_shifted_executed that exposes the stride. * Since this involves the introduction of a new schedule dimension, - * the build needs to be changed accodingly. + * the build needs to be changed accordingly. * After computing the AST, the newly introduced dimension needs * to be removed again from the list of grafts. We do this by plugging * in a mapping that represents the new schedule domain in terms of the @@ -3985,7 +4065,7 @@ mv = isl_multi_val_add_val(mv, val); mv = isl_multi_val_mod_val(mv, isl_val_copy(stride)); - executed = contruct_shifted_executed(domain, order, n, stride, mv, + executed = construct_shifted_executed(domain, order, n, stride, mv, build); space = isl_ast_build_get_space(build, 1); space = isl_space_map_from_set(space); @@ -4210,18 +4290,18 @@ return isl_stat_ok; } -static int after_in_tree(__isl_keep isl_union_map *umap, +static isl_bool after_in_tree(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node); /* Is any domain element of "umap" scheduled after any of * the corresponding image elements by the tree rooted at * the child of "node"? */ -static int after_in_child(__isl_keep isl_union_map *umap, +static isl_bool after_in_child(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { isl_schedule_node *child; - int after; + isl_bool after; child = isl_schedule_node_get_child(node, 0); after = after_in_tree(umap, child); @@ -4242,17 +4322,21 @@ * If there are no such pairs then the map passed to after_in_child * will be empty causing it to return 0. */ -static int after_in_band(__isl_keep isl_union_map *umap, +static isl_bool after_in_band(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { isl_multi_union_pw_aff *mupa; isl_union_map *partial, *test, *gt, *universe, *umap1, *umap2; isl_union_set *domain, *range; isl_space *space; - int empty; - int after; + isl_bool empty; + isl_bool after; + isl_size n; - if (isl_schedule_node_band_n_member(node) == 0) + n = isl_schedule_node_band_n_member(node); + if (n < 0) + return isl_bool_error; + if (n == 0) return after_in_child(umap, node); mupa = isl_schedule_node_band_get_partial_schedule(node); @@ -4268,7 +4352,7 @@ if (empty < 0 || !empty) { isl_union_map_free(partial); - return empty < 0 ? -1 : 1; + return isl_bool_not(empty); } universe = isl_union_map_universe(isl_union_map_copy(umap)); @@ -4294,13 +4378,13 @@ * to the range of the prefix schedule for both domain and * range of "umap". */ -static int after_in_context(__isl_keep isl_union_map *umap, +static isl_bool after_in_context(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { isl_union_map *prefix, *universe, *umap1, *umap2; isl_union_set *domain, *range; isl_set *context; - int after; + isl_bool after; umap = isl_union_map_copy(umap); context = isl_schedule_node_context_get_context(node); @@ -4330,11 +4414,11 @@ * We apply the expansion to domain and range of "umap" and * continue with its child. */ -static int after_in_expansion(__isl_keep isl_union_map *umap, +static isl_bool after_in_expansion(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { isl_union_map *expansion; - int after; + isl_bool after; expansion = isl_schedule_node_expansion_get_expansion(node); umap = isl_union_map_copy(umap); @@ -4353,13 +4437,13 @@ * the extension node "node"? * * Since the extension node may add statement instances before or - * after the pairs of statement instances in "umap", we return 1 + * after the pairs of statement instances in "umap", we return isl_bool_true * to ensure that these pairs are not broken up. */ -static int after_in_extension(__isl_keep isl_union_map *umap, +static isl_bool after_in_extension(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { - return 1; + return isl_bool_true; } /* Is any domain element of "umap" scheduled after any of @@ -4369,11 +4453,11 @@ * We intersect domain and range of "umap" with the filter and * continue with its child. */ -static int after_in_filter(__isl_keep isl_union_map *umap, +static isl_bool after_in_filter(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { isl_union_set *filter; - int after; + isl_bool after; umap = isl_union_map_copy(umap); filter = isl_schedule_node_filter_get_filter(node); @@ -4397,15 +4481,18 @@ * are contained in different children, then the condition * does not hold. */ -static int after_in_set(__isl_keep isl_union_map *umap, +static isl_bool after_in_set(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { - int i, n; + int i; + isl_size n; n = isl_schedule_node_n_children(node); + if (n < 0) + return isl_bool_error; for (i = 0; i < n; ++i) { isl_schedule_node *child; - int after; + isl_bool after; child = isl_schedule_node_get_child(node, i); after = after_in_tree(umap, child); @@ -4415,7 +4502,7 @@ return after; } - return 0; + return isl_bool_false; } /* Return the filter of child "i" of "node". @@ -4442,14 +4529,18 @@ * if the condition holds within a given child in the sequence. * The later part of the condition is checked by after_in_set. */ -static int after_in_sequence(__isl_keep isl_union_map *umap, +static isl_bool after_in_sequence(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { - int i, j, n; + int i, j; + isl_size n; isl_union_map *umap_i; - int empty, after = 0; + isl_bool empty; + isl_bool after = isl_bool_false; n = isl_schedule_node_n_children(node); + if (n < 0) + return isl_bool_error; for (i = 1; i < n; ++i) { isl_union_set *filter_i; @@ -4478,7 +4569,7 @@ if (empty < 0) goto error; if (!empty) - after = 1; + after = isl_bool_true; if (after) break; } @@ -4494,7 +4585,7 @@ return after_in_set(umap, node); error: isl_union_map_free(umap_i); - return -1; + return isl_bool_error; } /* Is any domain element of "umap" scheduled after any of @@ -4503,31 +4594,32 @@ * If "umap" is empty, then clearly there is no such element. * Otherwise, consider the different types of nodes separately. */ -static int after_in_tree(__isl_keep isl_union_map *umap, +static isl_bool after_in_tree(__isl_keep isl_union_map *umap, __isl_keep isl_schedule_node *node) { - int empty; + isl_bool empty; enum isl_schedule_node_type type; empty = isl_union_map_is_empty(umap); if (empty < 0) - return -1; + return isl_bool_error; if (empty) - return 0; + return isl_bool_false; if (!node) - return -1; + return isl_bool_error; type = isl_schedule_node_get_type(node); switch (type) { case isl_schedule_node_error: - return -1; + return isl_bool_error; case isl_schedule_node_leaf: - return 0; + return isl_bool_false; case isl_schedule_node_band: return after_in_band(umap, node); case isl_schedule_node_domain: isl_die(isl_schedule_node_get_ctx(node), isl_error_internal, - "unexpected internal domain node", return -1); + "unexpected internal domain node", + return isl_bool_error); case isl_schedule_node_context: return after_in_context(umap, node); case isl_schedule_node_expansion: @@ -4545,7 +4637,7 @@ return after_in_sequence(umap, node); } - return 1; + return isl_bool_true; } /* Is any domain element of "map1" scheduled after any domain @@ -4561,21 +4653,21 @@ * together and then check if the subtree underneath the current * band node determines their relative order. */ -static int after_in_subtree(__isl_keep isl_ast_build *build, +static isl_bool after_in_subtree(__isl_keep isl_ast_build *build, __isl_keep isl_map *map1, __isl_keep isl_map *map2) { isl_schedule_node *node; isl_map *map; isl_union_map *umap; - int after; + isl_bool after; node = isl_ast_build_get_schedule_node(build); if (!node) - return -1; + return isl_bool_error; node = isl_schedule_node_child(node, 0); if (isl_schedule_node_get_type(node) == isl_schedule_node_leaf) { isl_schedule_node_free(node); - return 0; + return isl_bool_false; } map = isl_map_copy(map2); map = isl_map_apply_domain(map, isl_map_copy(map1)); @@ -4619,8 +4711,11 @@ static isl_bool any_scheduled_after(int i, int j, void *user) { struct isl_any_scheduled_after_data *data = user; - int dim = isl_set_dim(data->domain[i].set, isl_dim_set); + isl_size dim = isl_set_dim(data->domain[i].set, isl_dim_set); int pos; + + if (dim < 0) + return isl_bool_error; for (pos = data->depth; pos < dim; ++pos) { int follows; @@ -4637,7 +4732,7 @@ } if (isl_ast_build_has_schedule_node(data->build)) { - int after; + isl_bool after; after = after_in_subtree(data->build, data->domain[i].map, data->domain[j].map); @@ -4645,7 +4740,7 @@ return after; } - return data->group_coscheduled; + return isl_bool_ok(data->group_coscheduled); } /* Look for independent components at the current depth and generate code @@ -4673,13 +4768,16 @@ { int i; isl_ctx *ctx = isl_ast_build_get_ctx(build); - int n = isl_union_map_n_map(executed); + isl_size n = isl_union_map_n_map(executed); struct isl_any_scheduled_after_data data; struct isl_set_map_pair *next; struct isl_tarjan_graph *g = NULL; isl_ast_graft_list *list = NULL; int n_domain = 0; + data.domain = NULL; + if (n < 0) + goto error; data.domain = isl_calloc_array(ctx, struct isl_set_map_pair, n); if (!data.domain) goto error; @@ -4753,6 +4851,8 @@ __isl_take isl_union_map *executed, __isl_take isl_ast_build *build) { int depth; + isl_size dim; + isl_size n; if (!build || !executed) goto error; @@ -4765,10 +4865,16 @@ } depth = isl_ast_build_get_depth(build); - if (depth >= isl_ast_build_dim(build, isl_dim_set)) + dim = isl_ast_build_dim(build, isl_dim_set); + if (dim < 0) + goto error; + if (depth >= dim) return generate_inner_level(executed, build); - if (isl_union_map_n_map(executed) == 1) + n = isl_union_map_n_map(executed); + if (n < 0) + goto error; + if (n == 1) return generate_shifted_component(executed, build); return generate_components(executed, build); @@ -5065,6 +5171,37 @@ __isl_keep isl_ast_build *build, __isl_take isl_union_map *schedule) { return isl_ast_build_node_from_schedule_map(build, schedule); +} + +/* Generate an AST that visits the elements in the domain of "executed" + * in the relative order specified by the leaf node "node". + * + * The relation "executed" maps the outer generated loop iterators + * to the domain elements executed by those iterations. + * + * Simply pass control to generate_inner_level. + * Note that the current build does not refer to any band node, so + * that generate_inner_level will not try to visit the child of + * the leaf node. + * + * If multiple statement instances reach a leaf, + * then they can be executed in any order. + * Group the list of grafts based on shared guards + * such that identical guards are only generated once + * when the list is eventually passed on to isl_ast_graft_list_fuse. + */ +static __isl_give isl_ast_graft_list *build_ast_from_leaf( + __isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, + __isl_take isl_union_map *executed) +{ + isl_ast_graft_list *list; + + isl_schedule_node_free(node); + list = generate_inner_level(executed, isl_ast_build_copy(build)); + list = isl_ast_graft_list_group_on_guard(list, build); + isl_ast_build_free(build); + + return list; } /* Generate an AST that visits the elements in the domain of "executed" @@ -5089,12 +5226,14 @@ isl_multi_union_pw_aff *extra; isl_union_map *extra_umap; isl_ast_graft_list *list; - unsigned n1, n2; - - if (!build || !node || !executed) + isl_size n1, n2; + isl_size n; + + n = isl_schedule_node_band_n_member(node); + if (!build || n < 0 || !executed) goto error; - if (isl_schedule_node_band_n_member(node) == 0) + if (n == 0) return build_ast_from_child(build, node, executed); extra = isl_schedule_node_band_get_partial_schedule(node); @@ -5111,7 +5250,9 @@ n1 = isl_ast_build_dim(build, isl_dim_param); build = isl_ast_build_product(build, space); n2 = isl_ast_build_dim(build, isl_dim_param); - if (n2 > n1) + if (n1 < 0 || n2 < 0) + build = isl_ast_build_free(build); + else if (n2 > n1) isl_die(isl_ast_build_get_ctx(build), isl_error_invalid, "band node is not allowed to introduce new parameters", build = isl_ast_build_free(build)); @@ -5144,13 +5285,12 @@ isl_ast_graft *graft; isl_basic_set *enforced; isl_set *guard; - unsigned n_param, extra_param; - - if (!build || !sub_build) - return isl_ast_graft_list_free(list); + isl_size n_param, extra_param; n_param = isl_ast_build_dim(build, isl_dim_param); extra_param = isl_ast_build_dim(sub_build, isl_dim_param); + if (n_param < 0 || extra_param < 0) + return isl_ast_graft_list_free(list); if (extra_param == n_param) return list; @@ -5213,9 +5353,12 @@ isl_multi_aff *internal2input; isl_ast_build *sub_build; isl_ast_graft_list *list; - int n, depth; + isl_size n; + isl_size depth; depth = isl_schedule_node_get_tree_depth(node); + if (depth < 0) + build = isl_ast_build_free(build); space = isl_ast_build_get_space(build, 1); context = isl_schedule_node_context_get_context(node); context = isl_set_align_params(context, space); @@ -5264,7 +5407,7 @@ __isl_take isl_union_map *executed) { isl_union_map *expansion; - unsigned n1, n2; + isl_size n1, n2; expansion = isl_schedule_node_expansion_get_expansion(node); expansion = isl_union_map_align_params(expansion, @@ -5273,6 +5416,8 @@ n1 = isl_union_map_dim(executed, isl_dim_param); executed = isl_union_map_apply_range(executed, expansion); n2 = isl_union_map_dim(executed, isl_dim_param); + if (n1 < 0 || n2 < 0) + goto error; if (n2 > n1) isl_die(isl_ast_build_get_ctx(build), isl_error_invalid, "expansion node is not allowed to introduce " @@ -5349,7 +5494,7 @@ isl_ast_graft_list *list; int empty; isl_bool unchanged; - unsigned n1, n2; + isl_size n1, n2; orig = isl_union_map_copy(executed); if (!build || !node || !executed) @@ -5361,6 +5506,8 @@ n1 = isl_union_map_dim(executed, isl_dim_param); executed = isl_union_map_intersect_range(executed, filter); n2 = isl_union_map_dim(executed, isl_dim_param); + if (n1 < 0 || n2 < 0) + goto error; if (n2 > n1) isl_die(isl_ast_build_get_ctx(build), isl_error_invalid, "filter node is not allowed to introduce " @@ -5415,14 +5562,16 @@ isl_ast_build *sub_build; isl_ast_graft *graft; isl_ast_graft_list *list; - unsigned n1, n2; + isl_size n1, n2, n; space = isl_ast_build_get_space(build, 1); guard = isl_schedule_node_guard_get_guard(node); n1 = isl_space_dim(space, isl_dim_param); guard = isl_set_align_params(guard, space); n2 = isl_set_dim(guard, isl_dim_param); - if (n2 > n1) + if (n1 < 0 || n2 < 0) + guard = isl_set_free(guard); + else if (n2 > n1) isl_die(isl_ast_build_get_ctx(build), isl_error_invalid, "guard node is not allowed to introduce " "new parameters", guard = isl_set_free(guard)); @@ -5439,7 +5588,10 @@ node, executed); hoisted = isl_ast_graft_list_extract_hoistable_guard(list, sub_build); - if (isl_set_n_basic_set(hoisted) > 1) + n = isl_set_n_basic_set(hoisted); + if (n < 0) + list = isl_ast_graft_list_free(list); + if (n > 1) list = isl_ast_graft_list_gist_guards(list, isl_set_copy(hoisted)); guard = isl_set_intersect(guard, hoisted); @@ -5511,7 +5663,7 @@ isl_id *mark; isl_ast_graft *graft; isl_ast_graft_list *list; - int n; + isl_size n; build = isl_ast_build_set_executed(build, isl_union_map_copy(executed)); @@ -5555,7 +5707,8 @@ __isl_take isl_ast_build *build, __isl_take isl_schedule_node *node, __isl_take isl_union_map *executed) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_graft_list *list; @@ -5563,6 +5716,8 @@ list = isl_ast_graft_list_alloc(ctx, 0); n = isl_schedule_node_n_children(node); + if (n < 0) + list = isl_ast_graft_list_free(list); for (i = 0; i < n; ++i) { isl_schedule_node *child; isl_ast_graft_list *list_i; @@ -5585,12 +5740,7 @@ * The relation "executed" maps the outer generated loop iterators * to the domain elements executed by those iterations. * - * If the node is a leaf, then we pass control to generate_inner_level. - * Note that the current build does not refer to any band node, so - * that generate_inner_level will not try to visit the child of - * the leaf node. - * - * The other node types are handled in separate functions. + * The node types are handled in separate functions. * Set nodes are currently treated in the same way as sequence nodes. * The children of a set node may be executed in any order, * including the order of the children. @@ -5607,8 +5757,7 @@ case isl_schedule_node_error: goto error; case isl_schedule_node_leaf: - isl_schedule_node_free(node); - return generate_inner_level(executed, build); + return build_ast_from_leaf(build, node, executed); case isl_schedule_node_band: return build_ast_from_band(build, node, executed); case isl_schedule_node_context: diff --git a/gcc/isl/isl_ast_graft.c b/gcc/isl/isl_ast_graft.c index de061c7..7a09986 100644 --- a/gcc/isl/isl_ast_graft.c +++ a/gcc/isl/isl_ast_graft.c @@ -1,6 +1,7 @@ /* * Copyright 2012 Ecole Normale Superieure * Copyright 2014 INRIA Rocquencourt + * Copyright 2019 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -8,19 +9,22 @@ * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France * and Inria Paris - Rocquencourt, Domaine de Voluceau - Rocquencourt, * B.P. 105 - 78153 Le Chesnay, France + * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA */ +#include #include #include #include #include #include +#include "isl_set_to_ast_graft_list.h" static __isl_give isl_ast_graft *isl_ast_graft_copy( __isl_keep isl_ast_graft *graft); -#undef BASE -#define BASE ast_graft +#undef EL_BASE +#define EL_BASE ast_graft #include @@ -101,36 +105,43 @@ /* Do all the grafts in "list" have the same guard and is this guard * independent of the current depth? */ -static int equal_independent_guards(__isl_keep isl_ast_graft_list *list, +static isl_bool equal_independent_guards(__isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; int depth; + isl_size dim; isl_ast_graft *graft_0; - int equal = 1; - int skip; + isl_bool equal = isl_bool_true; + isl_bool skip; + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return isl_bool_error; graft_0 = isl_ast_graft_list_get_ast_graft(list, 0); if (!graft_0) - return -1; + return isl_bool_error; depth = isl_ast_build_get_depth(build); - if (isl_set_dim(graft_0->guard, isl_dim_set) <= depth) - skip = 0; + dim = isl_set_dim(graft_0->guard, isl_dim_set); + if (dim < 0) + return isl_bool_error; + if (dim <= depth) + skip = isl_bool_false; else skip = isl_set_involves_dims(graft_0->guard, isl_dim_set, depth, 1); if (skip < 0 || skip) { isl_ast_graft_free(graft_0); - return skip < 0 ? -1 : 0; + return isl_bool_not(skip); } - n = isl_ast_graft_list_n_ast_graft(list); for (i = 1; i < n; ++i) { isl_ast_graft *graft; graft = isl_ast_graft_list_get_ast_graft(list, i); if (!graft) - equal = -1; + equal = isl_bool_error; else equal = isl_set_is_equal(graft_0->guard, graft->guard); isl_ast_graft_free(graft); @@ -151,9 +162,13 @@ __isl_keep isl_ast_build *build) { int depth; + isl_size dim; depth = isl_ast_build_get_depth(build); - if (depth < isl_set_dim(guard, isl_dim_set)) { + dim = isl_set_dim(guard, isl_dim_set); + if (dim < 0) + return isl_set_free(guard); + if (depth < dim) { guard = isl_set_remove_divs_involving_dims(guard, isl_dim_set, depth, 1); guard = isl_set_eliminate(guard, isl_dim_set, depth, 1); @@ -192,8 +207,9 @@ __isl_give isl_set *isl_ast_graft_list_extract_hoistable_guard( __isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { - int i, n; - int equal; + int i; + isl_size n; + isl_bool equal; isl_ctx *ctx; isl_set *guard; isl_set_list *set_list; @@ -203,6 +219,8 @@ return NULL; n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return NULL; if (n == 0) return isl_set_universe(isl_ast_build_get_space(build, 1)); @@ -276,10 +294,13 @@ { struct isl_insert_if_data data; isl_ctx *ctx; + isl_size n; + n = isl_set_n_basic_set(guard); + if (n < 0) + goto error; ctx = isl_ast_build_get_ctx(build); - if (isl_options_get_ast_build_allow_or(ctx) || - isl_set_n_basic_set(guard) <= 1) { + if (isl_options_get_ast_build_allow_or(ctx) || n <= 1) { isl_ast_node *if_node; isl_ast_expr *expr; @@ -300,6 +321,10 @@ isl_set_free(guard); isl_ast_node_free(data.node); return isl_ast_node_alloc_block(data.list); +error: + isl_set_free(guard); + isl_ast_node_free(node); + return NULL; } /* Insert an if node around a copy of "data->node" testing the condition @@ -388,10 +413,14 @@ __isl_take isl_basic_set *enforced, __isl_keep isl_ast_graft *graft, int depth) { + isl_size dim; isl_basic_set *enforced_g; enforced_g = isl_ast_graft_get_enforced(graft); - if (depth < isl_basic_set_dim(enforced_g, isl_dim_set)) + dim = isl_basic_set_dim(enforced_g, isl_dim_set); + if (dim < 0) + enforced_g = isl_basic_set_free(enforced_g); + if (depth < dim) enforced_g = isl_basic_set_eliminate(enforced_g, isl_dim_set, depth, 1); enforced_g = isl_basic_set_remove_unknown_divs(enforced_g); @@ -443,19 +472,19 @@ __isl_keep isl_ast_node **body, __isl_take isl_ast_graft *graft, __isl_keep isl_ast_build *build) { - int n; + isl_size n; int depth; isl_ast_graft *last; isl_space *space; isl_basic_set *enforced; - if (!list || !graft) + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0 || !graft) goto error; extend_body(body, isl_ast_node_copy(graft->node)); if (!*body) goto error; - n = isl_ast_graft_list_n_ast_graft(list); last = isl_ast_graft_list_get_ast_graft(list, n - 1); depth = isl_ast_build_get_depth(build); @@ -542,17 +571,18 @@ __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { - int i, j, n, n_if; + int i, j, n_if; + isl_size n; int allow_else; isl_ctx *ctx; isl_ast_graft_list *res; struct isl_if_node *if_node = NULL; - if (!build || !list) + n = isl_ast_graft_list_n_ast_graft(list); + if (!build || n < 0) return isl_ast_graft_list_free(list); ctx = isl_ast_build_get_ctx(build); - n = isl_ast_graft_list_n_ast_graft(list); allow_else = isl_options_get_ast_build_allow_else(ctx); @@ -662,15 +692,16 @@ __isl_give isl_ast_graft_list *isl_ast_graft_list_insert_pending_guard_nodes( __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; isl_set *universe; list = insert_pending_guard_nodes(list, build); - if (!list) - return NULL; + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return isl_ast_graft_list_free(list); universe = isl_set_universe(isl_ast_build_get_space(build, 1)); - n = isl_ast_graft_list_n_ast_graft(list); for (i = 0; i < n; ++i) { isl_ast_graft *graft; @@ -695,14 +726,15 @@ static __isl_give isl_ast_node_list *extract_node_list( __isl_keep isl_ast_graft_list *list) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_ast_node_list *node_list; - if (!list) + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) return NULL; ctx = isl_ast_graft_list_get_ctx(list); - n = isl_ast_graft_list_n_ast_graft(list); node_list = isl_ast_node_list_alloc(ctx, n); for (i = 0; i < n; ++i) { isl_ast_node *node; @@ -726,19 +758,20 @@ __isl_keep isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { - int i, n; + int i; + isl_size n; int depth; isl_space *space; isl_basic_set *enforced; - if (!list) + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) return NULL; space = isl_ast_build_get_space(build, 1); enforced = isl_basic_set_empty(space); depth = isl_ast_build_get_depth(build); - n = isl_ast_graft_list_n_ast_graft(list); for (i = 0; i < n; ++i) { isl_ast_graft *graft; @@ -793,12 +826,13 @@ static __isl_give isl_ast_graft_list *gist_guards( __isl_take isl_ast_graft_list *list, __isl_keep isl_set *context) { - int i, n; + int i; + isl_size n; + n = isl_ast_graft_list_n_ast_graft(list); if (!list) - return NULL; + return isl_ast_graft_list_free(list); - n = isl_ast_graft_list_n_ast_graft(list); for (i = 0; i < n; ++i) { isl_ast_graft *graft; @@ -908,11 +942,13 @@ __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build) { + isl_size n; isl_ast_graft *graft; - if (!list) - return NULL; - if (isl_ast_graft_list_n_ast_graft(list) <= 1) + n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return isl_ast_graft_list_free(list); + if (n <= 1) return list; graft = ast_graft_list_fuse(list, build); return isl_ast_graft_list_from_ast_graft(graft); @@ -992,7 +1028,7 @@ return isl_ast_node_from_ast_node_list(node_list); } -void *isl_ast_graft_free(__isl_take isl_ast_graft *graft) +__isl_null isl_ast_graft *isl_ast_graft_free(__isl_take isl_ast_graft *graft) { if (!graft) return NULL; @@ -1097,9 +1133,12 @@ __isl_give isl_ast_graft_list *isl_ast_graft_list_unembed( __isl_take isl_ast_graft_list *list, int product) { - int i, n; + int i; + isl_size n; n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + return isl_ast_graft_list_free(list); for (i = 0; i < n; ++i) { isl_ast_graft *graft; @@ -1139,9 +1178,12 @@ __isl_give isl_ast_graft_list *isl_ast_graft_list_preimage_multi_aff( __isl_take isl_ast_graft_list *list, __isl_take isl_multi_aff *ma) { - int i, n; + int i; + isl_size n; n = isl_ast_graft_list_n_ast_graft(list); + if (n < 0) + list = isl_ast_graft_list_free(list); for (i = 0; i < n; ++i) { isl_ast_graft *graft; @@ -1275,6 +1317,130 @@ isl_ast_graft_list_free(list1); isl_ast_graft_list_free(list2); return NULL; +} + +/* Internal data structure for split_on_guard. + * + * "guard2list" is the constructed associative array. + * "any_match" gets set if any guard was seen more than once. + */ +struct isl_split_on_guard_data { + isl_set_to_ast_graft_list *guard2list; + int *any_match; +}; + +/* Add "graft" to the list associated to its guard in data->guard2list. + * If some other graft was already associated to this guard, + * then set data->any_match. + */ +static isl_stat add_to_guard_list(__isl_take isl_ast_graft *graft, void *user) +{ + struct isl_split_on_guard_data *data = user; + isl_set *guard; + isl_maybe_isl_ast_graft_list m; + + if (!graft) + return isl_stat_error; + m = isl_set_to_ast_graft_list_try_get(data->guard2list, graft->guard); + if (m.valid < 0) + return isl_stat_non_null(isl_ast_graft_free(graft)); + + if (m.valid) { + *data->any_match = 1; + m.value = isl_ast_graft_list_add(m.value, graft); + } else { + m.value = isl_ast_graft_list_from_ast_graft(graft); + } + guard = isl_set_copy(graft->guard); + data->guard2list = + isl_set_to_ast_graft_list_set(data->guard2list, guard, m.value); + + return isl_stat_non_null(data->guard2list); +} + +/* Construct an associative array that groups the elements + * of "list" based on their guards. + * If any guard appears more than once, then set "any_match". + */ +static __isl_give isl_set_to_ast_graft_list *split_on_guard( + __isl_keep isl_ast_graft_list *list, int *any_match) +{ + struct isl_split_on_guard_data data = { NULL, any_match }; + isl_size n; + isl_ctx *ctx; + + n = isl_ast_graft_list_size(list); + if (n < 0) + return NULL; + + ctx = isl_ast_graft_list_get_ctx(list); + data.guard2list = isl_set_to_ast_graft_list_alloc(ctx, n); + + if (isl_ast_graft_list_foreach(list, &add_to_guard_list, &data) < 0) + return isl_set_to_ast_graft_list_free(data.guard2list); + + return data.guard2list; +} + +/* Add the elements of "guard_list" to "list". + */ +static isl_stat add_same_guard(__isl_take isl_set *guard, + __isl_take isl_ast_graft_list *guard_list, void *user) +{ + isl_ast_graft_list **list = user; + + isl_set_free(guard); + *list = isl_ast_graft_list_concat(*list, guard_list); + + return isl_stat_non_null(*list); +} + +/* Given an associative array "guard2list" containing the elements + * of "list" grouped on common guards, reconstruct "list" + * by placing elements with the same guard consecutively. + */ +static __isl_give isl_ast_graft_list *reconstruct( + __isl_take isl_ast_graft_list *list, + __isl_keep isl_set_to_ast_graft_list *guard2list, + __isl_keep isl_ast_build *build) +{ + list = isl_ast_graft_list_clear(list); + if (isl_set_to_ast_graft_list_foreach(guard2list, + &add_same_guard, &list) < 0) + list = isl_ast_graft_list_free(list); + + return list; +} + +/* Group the grafts in "list" based on identical guards. + * + * Note that there need to be a least three elements in the list + * for the elements not to be grouped already. + * + * Group the elements in an associative array based on their guards. + * If any guard was seen more than once, then reconstruct the list + * from the associative array. Otherwise, simply return the original list. + */ +__isl_give isl_ast_graft_list *isl_ast_graft_list_group_on_guard( + __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build) +{ + int any_match = 0; + isl_size n; + isl_set_to_ast_graft_list *guard2list; + + n = isl_ast_graft_list_size(list); + if (n < 0) + return isl_ast_graft_list_free(list); + if (n <= 2) + return list; + + guard2list = split_on_guard(list, &any_match); + if (any_match) + list = reconstruct(list, guard2list, build); + + isl_set_to_ast_graft_list_free(guard2list); + + return list; } __isl_give isl_printer *isl_printer_print_ast_graft(__isl_take isl_printer *p, diff --git a/gcc/isl/isl_ast_graft_private.h b/gcc/isl/isl_ast_graft_private.h index 400b9a8..5ca7c03 100644 --- a/gcc/isl/isl_ast_graft_private.h +++ a/gcc/isl/isl_ast_graft_private.h @@ -1,7 +1,8 @@ #ifndef ISL_AST_GRAFT_PRIVATE_H #define ISL_AST_GRAFT_PRIVATE_H #include +#include #include #include #include @@ -53,7 +54,7 @@ __isl_keep isl_ast_build *build); __isl_give isl_ast_graft *isl_ast_graft_alloc_domain( __isl_take isl_map *schedule, __isl_keep isl_ast_build *build); -void *isl_ast_graft_free(__isl_take isl_ast_graft *graft); +__isl_null isl_ast_graft *isl_ast_graft_free(__isl_take isl_ast_graft *graft); __isl_give isl_ast_graft_list *isl_ast_graft_list_sort_guard( __isl_take isl_ast_graft_list *list); @@ -61,6 +62,8 @@ __isl_take isl_ast_graft_list *list1, __isl_take isl_ast_graft_list *list2, __isl_keep isl_ast_build *build); +__isl_give isl_ast_graft_list *isl_ast_graft_list_group_on_guard( + __isl_take isl_ast_graft_list *list, __isl_keep isl_ast_build *build); __isl_give isl_ast_node *isl_ast_graft_get_node( __isl_keep isl_ast_graft *graft); diff --git a/gcc/isl/isl_ast_private.h b/gcc/isl/isl_ast_private.h index 9470019..a7726a2 100644 --- a/gcc/isl/isl_ast_private.h +++ a/gcc/isl/isl_ast_private.h @@ -22,7 +22,7 @@ isl_val *v; isl_id *id; struct { - enum isl_ast_op_type op; + enum isl_ast_expr_op_type op; unsigned n_arg; isl_ast_expr **args; } op; @@ -36,8 +36,9 @@ __isl_give isl_ast_expr *isl_ast_expr_alloc_int_si(isl_ctx *ctx, int i); __isl_give isl_ast_expr *isl_ast_expr_alloc_op(isl_ctx *ctx, - enum isl_ast_op_type op, int n_arg); -__isl_give isl_ast_expr *isl_ast_expr_alloc_binary(enum isl_ast_op_type type, + enum isl_ast_expr_op_type op, int n_arg); +__isl_give isl_ast_expr *isl_ast_expr_alloc_binary( + enum isl_ast_expr_op_type type, __isl_take isl_ast_expr *expr1, __isl_take isl_ast_expr *expr2); #undef EL diff --git a/gcc/isl/isl_bernstein.c b/gcc/isl/isl_bernstein.c index 3036e8f..2b83c64 100644 --- a/gcc/isl/isl_bernstein.c +++ a/gcc/isl/isl_bernstein.c @@ -38,92 +38,105 @@ isl_pw_qpolynomial_fold *pwf_tight; }; -static int vertex_is_integral(__isl_keep isl_basic_set *vertex) +static isl_bool vertex_is_integral(__isl_keep isl_basic_set *vertex) { - unsigned nvar; - unsigned nparam; + isl_size nvar; + isl_size nparam; int i; nvar = isl_basic_set_dim(vertex, isl_dim_set); nparam = isl_basic_set_dim(vertex, isl_dim_param); + if (nvar < 0 || nparam < 0) + return isl_bool_error; for (i = 0; i < nvar; ++i) { int r = nvar - 1 - i; if (!isl_int_is_one(vertex->eq[r][1 + nparam + i]) && !isl_int_is_negone(vertex->eq[r][1 + nparam + i])) - return 0; + return isl_bool_false; } - return 1; + return isl_bool_true; } static __isl_give isl_qpolynomial *vertex_coordinate( - __isl_keep isl_basic_set *vertex, int i, __isl_take isl_space *dim) + __isl_keep isl_basic_set *vertex, int i, __isl_take isl_space *space) { - unsigned nvar; - unsigned nparam; + isl_size nvar; + isl_size nparam; + isl_size total; int r; isl_int denom; isl_qpolynomial *v; + + isl_int_init(denom); nvar = isl_basic_set_dim(vertex, isl_dim_set); nparam = isl_basic_set_dim(vertex, isl_dim_param); + total = isl_basic_set_dim(vertex, isl_dim_all); + if (nvar < 0 || nparam < 0 || total < 0) + goto error; r = nvar - 1 - i; - isl_int_init(denom); isl_int_set(denom, vertex->eq[r][1 + nparam + i]); isl_assert(vertex->ctx, !isl_int_is_zero(denom), goto error); if (isl_int_is_pos(denom)) - isl_seq_neg(vertex->eq[r], vertex->eq[r], - 1 + isl_basic_set_total_dim(vertex)); + isl_seq_neg(vertex->eq[r], vertex->eq[r], 1 + total); else isl_int_neg(denom, denom); - v = isl_qpolynomial_from_affine(dim, vertex->eq[r], denom); + v = isl_qpolynomial_from_affine(space, vertex->eq[r], denom); isl_int_clear(denom); return v; error: - isl_space_free(dim); + isl_space_free(space); isl_int_clear(denom); return NULL; } /* Check whether the bound associated to the selection "k" is tight, - * which is the case if we select exactly one vertex and if that vertex + * which is the case if we select exactly one vertex (i.e., one of the + * exponents in "k" is exactly "d") and if that vertex * is integral for all values of the parameters. */ -static int is_tight(int *k, int n, int d, isl_cell *cell) +static isl_bool is_tight(int *k, int n, int d, isl_cell *cell) { int i; for (i = 0; i < n; ++i) { int v; - if (k[i] != d) { - if (k[i]) - return 0; + if (!k[i]) continue; - } + if (k[i] != d) + return isl_bool_false; v = cell->ids[n - 1 - i]; return vertex_is_integral(cell->vertices->v[v].vertex); } - return 0; + return isl_bool_false; } -static void add_fold(__isl_take isl_qpolynomial *b, __isl_keep isl_set *dom, +static isl_stat add_fold(__isl_take isl_qpolynomial *b, __isl_keep isl_set *dom, int *k, int n, int d, struct bernstein_data *data) { isl_qpolynomial_fold *fold; + isl_bool tight; fold = isl_qpolynomial_fold_alloc(data->type, b); - if (data->check_tight && is_tight(k, n, d, data->cell)) + tight = isl_bool_false; + if (data->check_tight) + tight = is_tight(k, n, d, data->cell); + if (tight < 0) + return isl_stat_error; + if (tight) data->fold_tight = isl_qpolynomial_fold_fold_on_domain(dom, data->fold_tight, fold); else data->fold = isl_qpolynomial_fold_fold_on_domain(dom, data->fold, fold); + return isl_stat_ok; } /* Extract the coefficients of the Bernstein base polynomials and store @@ -136,25 +149,25 @@ * c[i] contains the coefficient of the selected powers of the first i+1 vars. * multinom[i] contains the partial multinomial coefficient. */ -static void extract_coefficients(isl_qpolynomial *poly, +static isl_stat extract_coefficients(isl_qpolynomial *poly, __isl_keep isl_set *dom, struct bernstein_data *data) { int i; int d; - int n; + isl_size n; isl_ctx *ctx; isl_qpolynomial **c = NULL; int *k = NULL; int *left = NULL; isl_vec *multinom = NULL; - if (!poly) - return; + n = isl_qpolynomial_dim(poly, isl_dim_in); + if (n < 0) + return isl_stat_error; ctx = isl_qpolynomial_get_ctx(poly); - n = isl_qpolynomial_dim(poly, isl_dim_in); d = isl_qpolynomial_degree(poly); - isl_assert(ctx, n >= 2, return); + isl_assert(ctx, n >= 2, return isl_stat_error); c = isl_calloc_array(ctx, isl_qpolynomial *, n); k = isl_alloc_array(ctx, int, n); @@ -188,7 +201,8 @@ multinom->el[i]); b = isl_qpolynomial_mul(b, f); k[n - 1] = left[n - 2]; - add_fold(b, dom, k, n, d, data); + if (add_fold(b, dom, k, n, d, data) < 0) + goto error; --i; continue; } @@ -218,7 +232,7 @@ free(left); free(k); free(c); - return; + return isl_stat_ok; error: isl_vec_free(multinom); free(left); @@ -227,7 +241,7 @@ for (i = 0; i < n; ++i) isl_qpolynomial_free(c[i]); free(c); - return; + return isl_stat_error; } /* Perform bernstein expansion on the parametric vertices that are active @@ -247,9 +261,10 @@ { int i, j; struct bernstein_data *data = (struct bernstein_data *)user; - isl_space *dim_param; - isl_space *dim_dst; + isl_space *space_param; + isl_space *space_dst; isl_qpolynomial *poly = data->poly; + isl_size n_in; unsigned nvar; int n_vertices; isl_qpolynomial **subs; @@ -257,10 +272,11 @@ isl_set *dom; isl_ctx *ctx; - if (!poly) + n_in = isl_qpolynomial_dim(poly, isl_dim_in); + if (n_in < 0) goto error; - nvar = isl_qpolynomial_dim(poly, isl_dim_in) - 1; + nvar = n_in - 1; n_vertices = cell->n_vertices; ctx = isl_qpolynomial_get_ctx(poly); @@ -272,22 +288,23 @@ if (!subs) goto error; - dim_param = isl_basic_set_get_space(cell->dom); - dim_dst = isl_qpolynomial_get_domain_space(poly); - dim_dst = isl_space_add_dims(dim_dst, isl_dim_set, n_vertices); + space_param = isl_basic_set_get_space(cell->dom); + space_dst = isl_qpolynomial_get_domain_space(poly); + space_dst = isl_space_add_dims(space_dst, isl_dim_set, n_vertices); for (i = 0; i < 1 + nvar; ++i) - subs[i] = isl_qpolynomial_zero_on_domain(isl_space_copy(dim_dst)); + subs[i] = + isl_qpolynomial_zero_on_domain(isl_space_copy(space_dst)); for (i = 0; i < n_vertices; ++i) { isl_qpolynomial *c; - c = isl_qpolynomial_var_on_domain(isl_space_copy(dim_dst), isl_dim_set, - 1 + nvar + i); + c = isl_qpolynomial_var_on_domain(isl_space_copy(space_dst), + isl_dim_set, 1 + nvar + i); for (j = 0; j < nvar; ++j) { int k = cell->ids[i]; isl_qpolynomial *v; v = vertex_coordinate(cell->vertices->v[k].vertex, j, - isl_space_copy(dim_param)); + isl_space_copy(space_param)); v = isl_qpolynomial_add_dims(v, isl_dim_in, 1 + nvar + n_vertices); v = isl_qpolynomial_mul(v, isl_qpolynomial_copy(c)); @@ -295,7 +312,7 @@ } subs[0] = isl_qpolynomial_add(subs[0], c); } - isl_space_free(dim_dst); + isl_space_free(space_dst); poly = isl_qpolynomial_copy(poly); @@ -305,9 +322,13 @@ data->cell = cell; dom = isl_set_from_basic_set(isl_basic_set_copy(cell->dom)); - data->fold = isl_qpolynomial_fold_empty(data->type, isl_space_copy(dim_param)); - data->fold_tight = isl_qpolynomial_fold_empty(data->type, dim_param); - extract_coefficients(poly, dom, data); + data->fold = isl_qpolynomial_fold_empty(data->type, + isl_space_copy(space_param)); + data->fold_tight = isl_qpolynomial_fold_empty(data->type, space_param); + if (extract_coefficients(poly, dom, data) < 0) { + data->fold = isl_qpolynomial_fold_free(data->fold); + data->fold_tight = isl_qpolynomial_fold_free(data->fold_tight); + } pwf = isl_pw_qpolynomial_fold_alloc(data->type, isl_set_copy(dom), data->fold); @@ -334,15 +355,18 @@ */ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_base( __isl_take isl_basic_set *bset, - __isl_take isl_qpolynomial *poly, struct bernstein_data *data, int *tight) + __isl_take isl_qpolynomial *poly, struct bernstein_data *data, + isl_bool *tight) { - unsigned nvar; - isl_space *dim; + isl_size nvar; + isl_space *space; isl_pw_qpolynomial_fold *pwf; isl_vertices *vertices; - int covers; + isl_bool covers; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0) + bset = isl_basic_set_free(bset); if (nvar == 0) { isl_set *dom; isl_qpolynomial_fold *fold; @@ -350,7 +374,7 @@ fold = isl_qpolynomial_fold_alloc(data->type, poly); dom = isl_set_from_basic_set(bset); if (tight) - *tight = 1; + *tight = isl_bool_true; pwf = isl_pw_qpolynomial_fold_alloc(data->type, dom, fold); return isl_pw_qpolynomial_fold_project_domain_on_params(pwf); } @@ -362,16 +386,17 @@ dom = isl_set_from_basic_set(bset); pwf = isl_pw_qpolynomial_fold_alloc(data->type, dom, fold); if (tight) - *tight = 1; + *tight = isl_bool_true; return isl_pw_qpolynomial_fold_project_domain_on_params(pwf); } - dim = isl_basic_set_get_space(bset); - dim = isl_space_params(dim); - dim = isl_space_from_domain(dim); - dim = isl_space_add_dims(dim, isl_dim_set, 1); - data->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(dim), data->type); - data->pwf_tight = isl_pw_qpolynomial_fold_zero(dim, data->type); + space = isl_basic_set_get_space(bset); + space = isl_space_params(space); + space = isl_space_from_domain(space); + space = isl_space_add_dims(space, isl_dim_set, 1); + data->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(space), + data->type); + data->pwf_tight = isl_pw_qpolynomial_fold_zero(space, data->type); data->poly = isl_qpolynomial_homogenize(isl_qpolynomial_copy(poly)); vertices = isl_basic_set_compute_vertices(bset); if (isl_vertices_foreach_disjoint_cell(vertices, @@ -409,18 +434,17 @@ */ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_recursive( __isl_take isl_pw_qpolynomial *pwqp, - int n_group, int *len, struct bernstein_data *data, int *tight) + int n_group, int *len, struct bernstein_data *data, isl_bool *tight) { int i; - unsigned nparam; - unsigned nvar; + isl_size nparam; + isl_size nvar; isl_pw_qpolynomial_fold *pwf; - if (!pwqp) - return NULL; - nparam = isl_pw_qpolynomial_dim(pwqp, isl_dim_param); nvar = isl_pw_qpolynomial_dim(pwqp, isl_dim_in); + if (nparam < 0 || nvar < 0) + goto error; pwqp = isl_pw_qpolynomial_move_dims(pwqp, isl_dim_param, nparam, isl_dim_in, 0, nvar - len[n_group - 1]); @@ -428,6 +452,8 @@ for (i = n_group - 2; i >= 0; --i) { nparam = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_param); + if (nparam < 0) + return isl_pw_qpolynomial_fold_free(pwf); pwf = isl_pw_qpolynomial_fold_move_dims(pwf, isl_dim_in, 0, isl_dim_param, nparam - len[i], len[i]); if (tight && !*tight) @@ -436,11 +462,15 @@ } return pwf; +error: + isl_pw_qpolynomial_free(pwqp); + return NULL; } static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_factors( __isl_take isl_basic_set *bset, - __isl_take isl_qpolynomial *poly, struct bernstein_data *data, int *tight) + __isl_take isl_qpolynomial *poly, struct bernstein_data *data, + isl_bool *tight) { isl_factorizer *f; isl_set *set; @@ -473,19 +503,19 @@ static __isl_give isl_pw_qpolynomial_fold *bernstein_coefficients_full_recursive( __isl_take isl_basic_set *bset, - __isl_take isl_qpolynomial *poly, struct bernstein_data *data, int *tight) + __isl_take isl_qpolynomial *poly, struct bernstein_data *data, + isl_bool *tight) { int i; int *len; - unsigned nvar; + isl_size nvar; isl_pw_qpolynomial_fold *pwf; isl_set *set; isl_pw_qpolynomial *pwqp; - - if (!bset || !poly) - goto error; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0 || !poly) + goto error; len = isl_alloc_array(bset->ctx, int, nvar); if (nvar && !len) @@ -525,17 +555,16 @@ { struct bernstein_data data; isl_pw_qpolynomial_fold *pwf; - unsigned nvar; - int tight = 0; - int *tp = bound->check_tight ? &tight : NULL; + isl_size nvar; + isl_bool tight = isl_bool_false; + isl_bool *tp = bound->check_tight ? &tight : NULL; - if (!bset || !poly) + nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0 || !poly) goto error; data.type = bound->type; data.check_tight = bound->check_tight; - - nvar = isl_basic_set_dim(bset, isl_dim_set); if (bset->ctx->opt->bernstein_recurse & ISL_BERNSTEIN_FACTORS) pwf = bernstein_coefficients_factors(bset, poly, &data, tp); diff --git a/gcc/isl/isl_bound.c b/gcc/isl/isl_bound.c index d4177f4..60d4ec7 100644 --- a/gcc/isl/isl_bound.c +++ a/gcc/isl/isl_bound.c @@ -45,7 +45,7 @@ error: isl_basic_set_free(bset); isl_qpolynomial_free(poly); - return -1; + return isl_stat_error; } static isl_stat unwrapped_guarded_poly_bound(__isl_take isl_basic_set *bset, @@ -109,11 +109,11 @@ __isl_take isl_qpolynomial *poly, void *user) { struct isl_bound *bound = (struct isl_bound *)user; - isl_space *dim; + isl_space *space; isl_pw_qpolynomial_fold *top_pwf; isl_pw_qpolynomial_fold *top_pwf_tight; - int nparam; - int n_in; + isl_size nparam; + isl_size n_in; isl_stat r; if (!bound->wrapping) @@ -121,23 +121,25 @@ nparam = isl_space_dim(bound->dim, isl_dim_param); n_in = isl_space_dim(bound->dim, isl_dim_in); + if (nparam < 0 || n_in < 0) + goto error; bset = isl_basic_set_move_dims(bset, isl_dim_param, nparam, isl_dim_set, 0, n_in); poly = isl_qpolynomial_move_dims(poly, isl_dim_param, nparam, isl_dim_in, 0, n_in); - dim = isl_basic_set_get_space(bset); - dim = isl_space_params(dim); + space = isl_basic_set_get_space(bset); + space = isl_space_params(space); top_pwf = bound->pwf; top_pwf_tight = bound->pwf_tight; - dim = isl_space_from_domain(dim); - dim = isl_space_add_dims(dim, isl_dim_out, 1); - bound->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(dim), + space = isl_space_from_domain(space); + space = isl_space_add_dims(space, isl_dim_out, 1); + bound->pwf = isl_pw_qpolynomial_fold_zero(isl_space_copy(space), bound->type); - bound->pwf_tight = isl_pw_qpolynomial_fold_zero(dim, bound->type); + bound->pwf_tight = isl_pw_qpolynomial_fold_zero(space, bound->type); r = unwrapped_guarded_poly_bound(bset, poly, user); @@ -151,6 +153,10 @@ bound->pwf_tight); return r; +error: + isl_basic_set_free(bset); + isl_qpolynomial_free(poly); + return isl_stat_error; } static isl_stat guarded_qp(__isl_take isl_qpolynomial *qp, void *user) @@ -203,11 +209,11 @@ } __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_bound( - __isl_take isl_pw_qpolynomial_fold *pwf, int *tight) + __isl_take isl_pw_qpolynomial_fold *pwf, isl_bool *tight) { - unsigned nvar; + isl_size nvar; struct isl_bound bound; - int covers; + isl_bool covers; if (!pwf) return NULL; @@ -218,13 +224,15 @@ if (bound.wrapping) bound.dim = isl_space_unwrap(bound.dim); nvar = isl_space_dim(bound.dim, isl_dim_out); + if (nvar < 0) + bound.dim = isl_space_free(bound.dim); bound.dim = isl_space_domain(bound.dim); bound.dim = isl_space_from_domain(bound.dim); bound.dim = isl_space_add_dims(bound.dim, isl_dim_out, 1); if (nvar == 0) { if (tight) - *tight = 1; + *tight = isl_bool_true; return isl_pw_qpolynomial_fold_reset_space(pwf, bound.dim); } @@ -232,7 +240,7 @@ enum isl_fold type = pwf->type; isl_pw_qpolynomial_fold_free(pwf); if (tight) - *tight = 1; + *tight = isl_bool_true; return isl_pw_qpolynomial_fold_zero(bound.dim, type); } @@ -273,7 +281,8 @@ } __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_bound( - __isl_take isl_pw_qpolynomial *pwqp, enum isl_fold type, int *tight) + __isl_take isl_pw_qpolynomial *pwqp, enum isl_fold type, + isl_bool *tight) { isl_pw_qpolynomial_fold *pwf; @@ -283,7 +292,7 @@ struct isl_union_bound_data { enum isl_fold type; - int tight; + isl_bool tight; isl_union_pw_qpolynomial_fold *res; }; @@ -302,7 +311,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_bound( __isl_take isl_union_pw_qpolynomial *upwqp, - enum isl_fold type, int *tight) + enum isl_fold type, isl_bool *tight) { isl_space *dim; struct isl_union_bound_data data = { type, 1, NULL }; @@ -311,7 +320,7 @@ return NULL; if (!tight) - data.tight = 0; + data.tight = isl_bool_false; dim = isl_union_pw_qpolynomial_get_space(upwqp); data.res = isl_union_pw_qpolynomial_fold_zero(dim, type); diff --git a/gcc/isl/isl_coalesce.c b/gcc/isl/isl_coalesce.c index 598eac2..ca304e7 100644 --- a/gcc/isl/isl_coalesce.c +++ a/gcc/isl/isl_coalesce.c @@ -66,13 +66,17 @@ struct isl_tab *tab_j) { int k, l; - int *eq = isl_calloc_array(bmap_i->ctx, int, 2 * bmap_i->n_eq); - unsigned dim; + int *eq; + isl_size dim; + + dim = isl_basic_map_dim(bmap_i, isl_dim_all); + if (dim < 0) + return NULL; + eq = isl_calloc_array(bmap_i->ctx, int, 2 * bmap_i->n_eq); if (!eq) return NULL; - dim = isl_basic_map_total_dim(bmap_i); for (k = 0; k < bmap_i->n_eq; ++k) { for (l = 0; l < 2; ++l) { isl_seq_neg(bmap_i->eq[k], bmap_i->eq[k], 1+dim); @@ -173,6 +177,8 @@ * "bmap" is the basic map itself (or NULL if "removed" is set) * "tab" is the corresponding tableau (or NULL if "removed" is set) * "hull_hash" identifies the affine space in which "bmap" lives. + * "modified" is set if this basic map may not be identical + * to any of the basic maps in the input. * "removed" is set if this basic map has been removed from the map * "simplify" is set if this basic map may have some unknown integer * divisions that were not present in the input basic maps. The basic @@ -190,6 +196,7 @@ isl_basic_map *bmap; struct isl_tab *tab; uint32_t hull_hash; + int modified; int removed; int simplify; int *eq; @@ -309,11 +316,13 @@ static int coalesce_info_set_hull_hash(struct isl_coalesce_info *info) { isl_basic_map *hull; - unsigned n_div; + isl_size n_div; hull = isl_basic_map_copy(info->bmap); hull = isl_basic_map_plain_affine_hull(hull); n_div = isl_basic_map_dim(hull, isl_dim_div); + if (n_div < 0) + hull = isl_basic_map_free(hull); hull = isl_basic_map_drop_constraints_involving_dims(hull, isl_dim_div, 0, n_div); info->hull_hash = isl_basic_map_get_hash(hull); @@ -338,6 +347,15 @@ } free(info); +} + +/* Clear the memory associated to "info". + */ +static void clear(struct isl_coalesce_info *info) +{ + info->bmap = isl_basic_map_free(info->bmap); + isl_tab_free(info->tab); + info->tab = NULL; } /* Drop the basic map represented by "info". @@ -346,9 +364,7 @@ */ static void drop(struct isl_coalesce_info *info) { - info->bmap = isl_basic_map_free(info->bmap); - isl_tab_free(info->tab); - info->tab = NULL; + clear(info); info->removed = 1; } @@ -491,11 +507,13 @@ int k, l; struct isl_basic_map *fused = NULL; struct isl_tab *fused_tab = NULL; - unsigned total = isl_basic_map_total_dim(info[i].bmap); + isl_size total = isl_basic_map_dim(info[i].bmap, isl_dim_all); unsigned extra_rows = extra ? extra->n_row : 0; unsigned n_eq, n_ineq; int simplify = 0; + if (total < 0) + return isl_change_error; if (j < i) return fuse(j, i, info, extra, detect_equalities, check_number); @@ -552,10 +570,10 @@ return isl_change_none; } - isl_basic_map_free(info[i].bmap); + clear(&info[i]); info[i].bmap = fused; - isl_tab_free(info[i].tab); info[i].tab = fused_tab; + info[i].modified = 1; drop(&info[j]); return isl_change_fuse; @@ -644,10 +662,12 @@ static isl_bool contains(struct isl_coalesce_info *info, struct isl_tab *tab) { int k; - unsigned dim; + isl_size dim; isl_basic_map *bmap = info->bmap; - dim = isl_basic_map_total_dim(bmap); + dim = isl_basic_map_dim(bmap, isl_dim_all); + if (dim < 0) + return isl_bool_error; for (k = 0; k < bmap->n_eq; ++k) { int stat; isl_seq_neg(bmap->eq[k], bmap->eq[k], 1 + dim); @@ -723,10 +743,12 @@ int k; struct isl_tab_undo *snap; unsigned n_eq = info[i].bmap->n_eq; - unsigned total = isl_basic_map_total_dim(info[i].bmap); + isl_size total = isl_basic_map_dim(info[i].bmap, isl_dim_all); isl_stat r; isl_bool super; + if (total < 0) + return isl_change_error; if (isl_tab_extend_cons(info[i].tab, 1 + info[j].bmap->n_ineq) < 0) return isl_change_error; @@ -982,7 +1004,7 @@ static isl_stat tighten_on_relaxed_facet(struct isl_coalesce_info *info, int n, int *relaxed, int l) { - unsigned total; + isl_size total; isl_ctx *ctx; isl_vec *v = NULL; isl_mat *T; @@ -992,7 +1014,9 @@ k = relaxed[l]; ctx = isl_basic_map_get_ctx(info->bmap); - total = isl_basic_map_total_dim(info->bmap); + total = isl_basic_map_dim(info->bmap, isl_dim_all); + if (total < 0) + return isl_stat_error; isl_int_add_ui(info->bmap->ineq[k][0], info->bmap->ineq[k][0], 1); T = isl_mat_sub_alloc6(ctx, info->bmap->ineq, k, 1, 0, 1 + total); T = isl_mat_variable_compression(T, NULL); @@ -1057,12 +1081,12 @@ struct isl_coalesce_info *info) { int l; - unsigned total; + isl_size total; info[i].bmap = isl_basic_map_cow(info[i].bmap); - if (!info[i].bmap) + total = isl_basic_map_dim(info[i].bmap, isl_dim_all); + if (total < 0) return isl_change_error; - total = isl_basic_map_total_dim(info[i].bmap); for (l = 0; l < info[i].bmap->n_div; ++l) if (!isl_seq_eq(info[i].bmap->div[l], info[j].bmap->div[l], 1 + 1 + total)) { @@ -1072,8 +1096,10 @@ for (l = 0; l < n; ++l) isl_int_add_ui(info[i].bmap->ineq[relax[l]][0], info[i].bmap->ineq[relax[l]][0], 1); + ISL_F_CLR(info[i].bmap, ISL_BASIC_MAP_NO_REDUNDANT); ISL_F_SET(info[i].bmap, ISL_BASIC_MAP_FINAL); drop(&info[j]); + info[i].modified = 1; if (j < i) exchange(&info[i], &info[j]); return isl_change_fuse; @@ -1191,8 +1217,10 @@ { int k; isl_int max_k; - unsigned total = isl_basic_map_total_dim(info->bmap); + isl_size total = isl_basic_map_dim(info->bmap, isl_dim_all); + if (total < 0) + return isl_stat_error; isl_int_init(max_k); for (k = 0; k < info->bmap->n_eq; ++k) { @@ -1254,6 +1282,14 @@ isl_mat_free(wraps->mat); if (wraps->bound) isl_int_clear(wraps->max); +} + +/* Mark the wrapping as failed by resetting wraps->mat->n_row to zero. + */ +static isl_stat wraps_mark_failed(struct isl_wraps *wraps) +{ + wraps->mat->n_row = 0; + return isl_stat_ok; } /* Is the wrapping constraint in row "row" allowed? @@ -1327,7 +1363,11 @@ int w; int added; isl_basic_map *bmap = info->bmap; - unsigned len = 1 + isl_basic_map_total_dim(bmap); + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); + unsigned len = 1 + total; + + if (total < 0) + return isl_stat_error; w = wraps->mat->n_row; @@ -1371,8 +1411,7 @@ wraps->mat->n_row = w; return isl_stat_ok; unbounded: - wraps->mat->n_row = 0; - return isl_stat_ok; + return wraps_mark_failed(wraps); } /* Check if the constraints in "wraps" from "first" until the last @@ -1424,6 +1463,32 @@ bset = isl_basic_set_cow(bset); bset = isl_basic_set_update_from_tab(bset, tab); return isl_set_from_basic_set(bset); +} + +/* Does "info" have any cut constraints that are redundant? + */ +static isl_bool has_redundant_cuts(struct isl_coalesce_info *info) +{ + int l; + int n_eq, n_ineq; + + n_eq = isl_basic_map_n_equality(info->bmap); + n_ineq = isl_basic_map_n_inequality(info->bmap); + if (n_eq < 0 || n_ineq < 0) + return isl_bool_error; + for (l = 0; l < n_ineq; ++l) { + int red; + + if (info->ineq[l] != STATUS_CUT) + continue; + red = isl_tab_is_redundant(info->tab, n_eq + l); + if (red < 0) + return isl_bool_error; + if (red) + return isl_bool_true; + } + + return isl_bool_false; } /* Wrap the constraints of info->bmap that bound the facet defined @@ -1433,14 +1498,24 @@ * of info->bmap, we check them in check_wraps. * If any of the wrapped constraints turn out to be invalid, then * check_wraps will reset wrap->n_row to zero. + * + * If any of the cut constraints of info->bmap turn out + * to be redundant with respect to other constraints + * then these will neither be wrapped nor added directly to the result. + * The result may therefore not be correct. + * Skip wrapping and reset wrap->mat->n_row to zero in this case. */ static isl_stat add_wraps_around_facet(struct isl_wraps *wraps, struct isl_coalesce_info *info, int k, isl_int *bound, __isl_keep isl_set *set) { + isl_bool nowrap; struct isl_tab_undo *snap; int n; - unsigned total = isl_basic_map_total_dim(info->bmap); + isl_size total = isl_basic_map_dim(info->bmap, isl_dim_all); + + if (total < 0) + return isl_stat_error; snap = isl_tab_snap(info->tab); @@ -1448,15 +1523,22 @@ return isl_stat_error; if (isl_tab_detect_redundant(info->tab) < 0) return isl_stat_error; - - isl_seq_neg(bound, info->bmap->ineq[k], 1 + total); + nowrap = has_redundant_cuts(info); + if (nowrap < 0) + return isl_stat_error; n = wraps->mat->n_row; - if (add_wraps(wraps, info, bound, set) < 0) - return isl_stat_error; + if (!nowrap) { + isl_seq_neg(bound, info->bmap->ineq[k], 1 + total); + + if (add_wraps(wraps, info, bound, set) < 0) + return isl_stat_error; + } if (isl_tab_rollback(info->tab, snap) < 0) return isl_stat_error; + if (nowrap) + return wraps_mark_failed(wraps); if (check_wraps(wraps->mat, n, info->tab) < 0) return isl_stat_error; @@ -1494,8 +1576,10 @@ struct isl_set *set_i = NULL; struct isl_set *set_j = NULL; struct isl_vec *bound = NULL; - unsigned total = isl_basic_map_total_dim(info[i].bmap); + isl_size total = isl_basic_map_dim(info[i].bmap, isl_dim_all); + if (total < 0) + return isl_change_error; set_i = set_from_updated_bmap(info[i].bmap, info[i].tab); set_j = set_from_updated_bmap(info[j].bmap, info[j].tab); ctx = isl_basic_map_get_ctx(info[i].bmap); @@ -1510,6 +1594,7 @@ isl_seq_cpy(bound->el, info[i].bmap->ineq[k], 1 + total); isl_int_add_ui(bound->el[0], bound->el[0], 1); + isl_seq_normalize(ctx, bound->el, 1 + total); isl_seq_cpy(wraps.mat->row[0], bound->el, 1 + total); wraps.mat->n_row = 1; @@ -1610,10 +1695,12 @@ __isl_keep isl_set *set_i) { int k, l, w; - unsigned total; + isl_size total; struct isl_tab_undo *snap; - total = isl_basic_map_total_dim(info[i].bmap); + total = isl_basic_map_dim(info[i].bmap, isl_dim_all); + if (total < 0) + return isl_change_error; snap = isl_tab_snap(info[j].tab); @@ -1673,9 +1760,11 @@ isl_ctx *ctx; isl_mat *mat; isl_set *set_i = NULL; - unsigned total = isl_basic_map_total_dim(info[i].bmap); + isl_size total = isl_basic_map_dim(info[i].bmap, isl_dim_all); int max_wrap; + if (total < 0) + return isl_change_error; if (isl_tab_extend_cons(info[j].tab, 1) < 0) return isl_change_error; @@ -1780,7 +1869,7 @@ { int k, l; int n; - unsigned total; + isl_size total; if (ISL_F_ISSET(info[i].bmap, ISL_BASIC_MAP_RATIONAL) || ISL_F_ISSET(info[j].bmap, ISL_BASIC_MAP_RATIONAL)) @@ -1790,7 +1879,9 @@ if (n == 0) return isl_change_none; - total = isl_basic_map_total_dim(info[i].bmap); + total = isl_basic_map_dim(info[i].bmap, isl_dim_all); + if (total < 0) + return isl_change_error; for (k = 0; k < info[i].bmap->n_eq; ++k) { for (l = 0; l < 2; ++l) { enum isl_ineq_type type; @@ -2027,8 +2118,10 @@ struct isl_set *set_i = NULL; struct isl_set *set_j = NULL; struct isl_vec *bound = NULL; - unsigned total = isl_basic_map_total_dim(info[i].bmap); + isl_size total = isl_basic_map_dim(info[i].bmap, isl_dim_all); + if (total < 0) + return isl_change_error; if (count_eq(&info[i], STATUS_ADJ_EQ) != 1) detect_equalities = 1; @@ -2371,14 +2464,17 @@ static isl_stat shift_div(struct isl_coalesce_info *info, int div, isl_int shift) { - unsigned total; + isl_size total, n_div; info->bmap = isl_basic_map_shift_div(info->bmap, div, 0, shift); if (!info->bmap) return isl_stat_error; total = isl_basic_map_dim(info->bmap, isl_dim_all); - total -= isl_basic_map_dim(info->bmap, isl_dim_div); + n_div = isl_basic_map_dim(info->bmap, isl_dim_div); + if (total < 0 || n_div < 0) + return isl_stat_error; + total -= n_div; if (isl_tab_shift_var(info->tab, total + div, shift) < 0) return isl_stat_error; @@ -2393,7 +2489,7 @@ * * c + f + m a = 0 * - * The integer division expression is then of the form + * The integer division expression is then typically of the form * * a = floor((-f - c')/m) * @@ -2411,11 +2507,12 @@ * a' = (-f - (c mod m))/m = floor((-f)/m) * * because a' is an integer and 0 <= (c mod m) < m. - * The constant term of a' can therefore be zeroed out. + * The constant term of a' can therefore be zeroed out, + * but only if the integer division expression is of the expected form. */ static isl_stat normalize_stride_div(struct isl_coalesce_info *info, int div) { - isl_bool defined; + isl_bool defined, valid; isl_stat r; isl_constraint *c; isl_int shift, stride; @@ -2428,6 +2525,7 @@ return isl_stat_ok; if (!c) return isl_stat_error; + valid = isl_constraint_is_div_equality(c, div); isl_int_init(shift); isl_int_init(stride); isl_constraint_get_constant(c, &shift); @@ -2437,8 +2535,10 @@ isl_int_clear(stride); isl_int_clear(shift); isl_constraint_free(c); - if (r < 0) + if (r < 0 || valid < 0) return isl_stat_error; + if (!valid) + return isl_stat_ok; info->bmap = isl_basic_map_set_div_expr_constant_num_si_inplace( info->bmap, div, 0); if (!info->bmap) @@ -2461,9 +2561,12 @@ static isl_stat harmonize_stride_divs(struct isl_coalesce_info *info1, struct isl_coalesce_info *info2) { - int i, n; + int i; + isl_size n; n = isl_basic_map_dim(info1->bmap, isl_dim_div); + if (n < 0) + return isl_stat_error; for (i = 0; i < n; ++i) { isl_bool known, harmonize; @@ -2572,10 +2675,12 @@ __isl_keep isl_basic_set *eq2) { int i; - int total; + isl_size total; isl_local_space *ls1, *ls2; - total = isl_basic_map_total_dim(info1->bmap); + total = isl_basic_map_dim(info1->bmap, isl_dim_all); + if (total < 0) + return isl_stat_error; ls1 = isl_local_space_wrap(isl_basic_map_get_local_space(info1->bmap)); ls2 = isl_local_space_wrap(isl_basic_map_get_local_space(info2->bmap)); for (i = 0; i < info1->bmap->n_div; ++i) { @@ -2679,7 +2784,7 @@ { int i; isl_bool known; - int total; + isl_size total; if (!bmap1 || !bmap2) return isl_bool_error; @@ -2696,12 +2801,14 @@ if (known < 0 || !known) return known; - total = isl_basic_map_total_dim(bmap1); + total = isl_basic_map_dim(bmap1, isl_dim_all); + if (total < 0) + return isl_bool_error; for (i = 0; i < bmap1->n_div; ++i) if (!isl_seq_eq(bmap1->div[i], bmap2->div[i], 2 + total)) - return 0; + return isl_bool_false; - return 1; + return isl_bool_true; } /* Assuming that "tab" contains the equality constraints and @@ -2779,9 +2886,8 @@ if (!expanded[i].cst) { info->bmap = isl_basic_map_extend_constraints( info->bmap, 0, 2); - if (isl_basic_map_add_div_constraints(info->bmap, - expanded[i].pos - o_div) < 0) - break; + info->bmap = isl_basic_map_add_div_constraints( + info->bmap, expanded[i].pos - o_div); } else { isl_int_set_si(ineq->el[1 + expanded[i].pos], -1); isl_int_set(ineq->el[0], expanded[i].val); @@ -2886,7 +2992,8 @@ if (isl_tab_rollback(info->tab, snap) < 0) return isl_stat_error; info->bmap = isl_basic_map_cow(info->bmap); - if (isl_basic_map_free_inequality(info->bmap, 2 * n) < 0) + info->bmap = isl_basic_map_free_inequality(info->bmap, 2 * n); + if (info->bmap < 0) return isl_stat_error; return fix_constant_divs(info, n, expanded); @@ -2924,11 +3031,14 @@ struct isl_expanded *expanded; int i, j, k, n; int extra_var; - unsigned total, pos, n_div; + isl_size total, n_div; + unsigned pos; isl_stat r; total = isl_basic_map_dim(bmap, isl_dim_all); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (total < 0 || n_div < 0) + return isl_stat_error; pos = total - n_div; extra_var = total - info->tab->n_var; n = n_div - extra_var; @@ -3130,7 +3240,7 @@ __isl_keep isl_basic_map *bmap_i, int i, int j, struct isl_coalesce_info *info) { - int known; + isl_bool known; isl_mat *div_i, *div_j, *div; int *exp1 = NULL; int *exp2 = NULL; @@ -3138,8 +3248,10 @@ enum isl_change change; known = isl_basic_map_divs_known(bmap_i); - if (known < 0 || !known) - return known; + if (known < 0) + return isl_change_error; + if (!known) + return isl_change_none; ctx = isl_basic_map_get_ctx(bmap_i); @@ -3290,11 +3402,13 @@ static isl_bool has_nested_div(__isl_keep isl_basic_map *bmap) { int i; - unsigned total; - unsigned n_div; + isl_size total; + isl_size n_div; total = isl_basic_map_dim(bmap, isl_dim_all); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (total < 0 || n_div < 0) + return isl_bool_error; total -= n_div; for (i = 0; i < n_div; ++i) @@ -3320,7 +3434,7 @@ __isl_keep isl_basic_map *bmap_i, __isl_keep isl_basic_map *bmap_j, __isl_take isl_basic_map *hull) { - unsigned n_div_i, n_div_j, total; + isl_size n_div_i, n_div_j, total; isl_ctx *ctx; isl_local_space *ls; isl_basic_set *wrap_hull; @@ -3328,14 +3442,14 @@ isl_aff_list *list; int i, j; - if (!hull) + n_div_i = isl_basic_map_dim(bmap_i, isl_dim_div); + n_div_j = isl_basic_map_dim(bmap_j, isl_dim_div); + total = isl_basic_map_dim(bmap_i, isl_dim_all); + if (!hull || n_div_i < 0 || n_div_j < 0 || total < 0) return NULL; ctx = isl_basic_map_get_ctx(hull); - - n_div_i = isl_basic_map_dim(bmap_i, isl_dim_div); - n_div_j = isl_basic_map_dim(bmap_j, isl_dim_div); - total = isl_basic_map_total_dim(bmap_i) - n_div_i; + total -= n_div_i; ls = isl_basic_map_get_local_space(bmap_i); ls = isl_local_space_wrap(ls); @@ -3347,6 +3461,7 @@ j = 0; for (i = 0; i < n_div_i; ++i) { isl_aff *aff; + isl_size n_div; if (j < n_div_j && isl_basic_map_equal_div_expr_part(bmap_i, i, bmap_j, j, @@ -3362,9 +3477,10 @@ aff = isl_aff_substitute_equalities(aff, isl_basic_set_copy(wrap_hull)); aff = isl_aff_floor(aff); - if (!aff) + n_div = isl_aff_dim(aff, isl_dim_div); + if (n_div < 0) goto error; - if (isl_aff_dim(aff, isl_dim_div) != 0) { + if (n_div != 0) { isl_aff_free(aff); break; } @@ -3404,16 +3520,17 @@ static isl_stat add_sub_vars(struct isl_coalesce_info *info, __isl_keep isl_aff_list *list, int dim, int extra_var) { - int i, j, n, d; + int i, j, d; + isl_size n; isl_space *space; space = isl_basic_map_get_space(info->bmap); info->bmap = isl_basic_map_cow(info->bmap); info->bmap = isl_basic_map_extend_space(info->bmap, space, extra_var, 0, 0); - if (!info->bmap) - return isl_stat_error; n = isl_aff_list_n_aff(list); + if (!info->bmap || n < 0) + return isl_stat_error; for (i = 0; i < n; ++i) { int is_nan; isl_aff *aff; @@ -3432,10 +3549,11 @@ if (d < 0) return isl_stat_error; info->bmap = isl_basic_map_mark_div_unknown(info->bmap, d); + for (j = d; j > i; --j) + info->bmap = isl_basic_map_swap_div(info->bmap, + j - 1, j); if (!info->bmap) return isl_stat_error; - for (j = d; j > i; --j) - isl_basic_map_swap_div(info->bmap, j - 1, j); } return isl_stat_ok; @@ -3449,20 +3567,23 @@ * This function assumes that a sufficient number of rows and * elements in the constraint array are available in the tableau. */ -static int add_sub_equalities(struct isl_tab *tab, +static isl_stat add_sub_equalities(struct isl_tab *tab, __isl_keep isl_aff_list *list, int dim) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_vec *sub; isl_aff *aff; n = isl_aff_list_n_aff(list); + if (n < 0) + return isl_stat_error; ctx = isl_tab_get_ctx(tab); sub = isl_vec_alloc(ctx, 1 + dim + n); if (!sub) - return -1; + return isl_stat_error; isl_seq_clr(sub->el + 1 + dim, n); for (i = 0; i < n; ++i) { @@ -3482,11 +3603,11 @@ } isl_vec_free(sub); - return 0; + return isl_stat_ok; error: isl_aff_free(aff); isl_vec_free(sub); - return -1; + return isl_stat_error; } /* Add variables to info->tab and info->bmap corresponding to the elements @@ -3497,24 +3618,24 @@ * When this function returns, the total number of variables in info->tab * is equal to "dim" plus the number of elements in "list". */ -static int add_subs(struct isl_coalesce_info *info, +static isl_stat add_subs(struct isl_coalesce_info *info, __isl_keep isl_aff_list *list, int dim) { int extra_var; - int n; - - if (!list) - return -1; + isl_size n; n = isl_aff_list_n_aff(list); + if (n < 0) + return isl_stat_error; + extra_var = n - (info->tab->n_var - dim); if (isl_tab_extend_vars(info->tab, extra_var) < 0) - return -1; + return isl_stat_error; if (isl_tab_extend_cons(info->tab, 2 * extra_var) < 0) - return -1; + return isl_stat_error; if (add_sub_vars(info, list, dim, extra_var) < 0) - return -1; + return isl_stat_error; return add_sub_equalities(info->tab, list, dim); } @@ -3537,14 +3658,17 @@ { isl_basic_map *bmap_j; struct isl_tab_undo *snap; - unsigned dim; + isl_size dim, n_div; enum isl_change change; bmap_j = isl_basic_map_copy(info[j].bmap); snap = isl_tab_snap(info[j].tab); dim = isl_basic_map_dim(bmap_j, isl_dim_all); - dim -= isl_basic_map_dim(bmap_j, isl_dim_div); + n_div = isl_basic_map_dim(bmap_j, isl_dim_div); + if (dim < 0 || n_div < 0) + goto error; + dim -= n_div; if (add_subs(&info[j], list, dim) < 0) goto error; @@ -3576,20 +3700,22 @@ * extra equalities to a purely affine expression. * If these tests succeed, then we try to coalesce the two basic maps * by introducing extra dimensions in "j" corresponding to - * the extra integer divsisions "i" fixed to the corresponding + * the extra integer divisions "i" fixed to the corresponding * purely affine expression. */ static enum isl_change check_coalesce_into_eq(int i, int j, struct isl_coalesce_info *info) { - unsigned n_div_i, n_div_j; + isl_size n_div_i, n_div_j, n; isl_basic_map *hull_i, *hull_j; - int equal, empty; + isl_bool equal, empty; isl_aff_list *list; enum isl_change change; n_div_i = isl_basic_map_dim(info[i].bmap, isl_dim_div); n_div_j = isl_basic_map_dim(info[j].bmap, isl_dim_div); + if (n_div_i < 0 || n_div_j < 0) + return isl_change_error; if (n_div_i <= n_div_j) return isl_change_none; if (info[j].bmap->n_eq == 0) @@ -3615,7 +3741,10 @@ list = set_up_substitutions(info[i].bmap, info[j].bmap, hull_j); if (!list) return isl_change_error; - if (isl_aff_list_n_aff(list) < n_div_i) + n = isl_aff_list_n_aff(list); + if (n < 0) + change = isl_change_error; + else if (n < n_div_i) change = isl_change_none; else change = coalesce_with_subs(i, j, info, list); @@ -3677,12 +3806,20 @@ * an obvious subset of the other or if the extra integer divisions * of one basic map can be simplified away using the extra equalities * of the other basic map. + * + * Note that trying to coalesce pairs of disjuncts with the same + * number, but different local variables may drop the explicit + * representation of some of these local variables. + * This operation is therefore not performed when + * the "coalesce_preserve_locals" option is set. */ static enum isl_change coalesce_pair(int i, int j, struct isl_coalesce_info *info) { + int preserve; isl_bool same; enum isl_change change; + isl_ctx *ctx; if (harmonize_divs(&info[i], &info[j]) < 0) return isl_change_error; @@ -3692,7 +3829,9 @@ if (same) return coalesce_local_pair(i, j, info); - if (info[i].bmap->n_div == info[j].bmap->n_div) { + ctx = isl_basic_map_get_ctx(info[i].bmap); + preserve = isl_options_get_coalesce_preserve_locals(ctx); + if (!preserve && info[i].bmap->n_div == info[j].bmap->n_div) { change = coalesce_local_pair(i, j, info); if (change != isl_change_none) return change; @@ -3796,6 +3935,10 @@ * isl_basic_map_gauss, we need to do it now. * Also call isl_basic_map_simplify if we may have lost the definition * of one or more integer divisions. + * If a basic map is still equal to the one from which the corresponding "info" + * entry was created, then redundant constraint and + * implicit equality constraint detection have been performed + * on the corresponding tableau and the basic map can be marked as such. */ static __isl_give isl_map *update_basic_maps(__isl_take isl_map *map, int n, struct isl_coalesce_info *info) @@ -3822,8 +3965,10 @@ info[i].bmap = isl_basic_map_finalize(info[i].bmap); if (!info[i].bmap) return isl_map_free(map); - ISL_F_SET(info[i].bmap, ISL_BASIC_MAP_NO_IMPLICIT); - ISL_F_SET(info[i].bmap, ISL_BASIC_MAP_NO_REDUNDANT); + if (!info[i].modified) { + ISL_F_SET(info[i].bmap, ISL_BASIC_MAP_NO_IMPLICIT); + ISL_F_SET(info[i].bmap, ISL_BASIC_MAP_NO_REDUNDANT); + } isl_basic_map_free(map->p[i]); map->p[i] = info[i].bmap; info[i].bmap = NULL; @@ -3838,16 +3983,22 @@ * * We factor out any (hidden) common factor from the constraint * coefficients to improve the detection of adjacent constraints. + * Note that this function does not call isl_basic_map_gauss, + * but it does make sure that only a single copy of the basic map + * is affected. This means that isl_basic_map_gauss may have + * to be called at the end of the computation (in update_basic_maps) + * on this single copy to ensure that + * the basic maps are not left in an unexpected state. * * Since we are constructing the tableaus of the basic maps anyway, * we exploit them to detect implicit equalities and redundant constraints. * This also helps the coalescing as it can ignore the redundant constraints. * In order to avoid confusion, we make all implicit equalities explicit - * in the basic maps. We don't call isl_basic_map_gauss, though, - * as that may affect the number of constraints. - * This means that we have to call isl_basic_map_gauss at the end - * of the computation (in update_basic_maps) to ensure that - * the basic maps are not left in an unexpected state. + * in the basic maps. If the basic map only has a single reference + * (this happens in particular if it was modified by + * isl_basic_map_reduce_coefficients), then isl_basic_map_gauss + * does not get called on the result. The call to + * isl_basic_map_gauss in update_basic_maps resolves this as well. * For each basic map, we also compute the hash of the apparent affine hull * for use in coalesce. */ diff --git a/gcc/isl/isl_config.h.in b/gcc/isl/isl_config.h.in index e2ec2ea..0170b31 100644 --- a/gcc/isl/isl_config.h.in +++ a/gcc/isl/isl_config.h.in @@ -18,6 +18,9 @@ /* Define if TargetInfo::CreateTargetInfo takes shared_ptr */ #undef CREATETARGETINFO_TAKES_SHARED_PTR +/* Define if CompilerInvocation::CreateFromArgs takes ArrayRef */ +#undef CREATE_FROM_ARGS_TAKES_ARRAYREF + /* Define if Driver constructor takes default image name */ #undef DRIVER_CTOR_TAKES_DEFAULTIMAGENAME @@ -33,6 +36,9 @@ /* Define if clang/Basic/DiagnosticOptions.h exists */ #undef HAVE_BASIC_DIAGNOSTICOPTIONS_H + +/* define if the compiler supports basic C++11 syntax */ +#undef HAVE_CXX11 /* Define if Driver constructor takes CXXIsProduction argument */ #undef HAVE_CXXISPRODUCTION @@ -91,6 +97,9 @@ /* Define to 1 if you have the `gmp' library (-lgmp). */ #undef HAVE_LIBGMP +/* Define if llvm/Option/Arg.h exists */ +#undef HAVE_LLVM_OPTION_ARG_H + /* Define to 1 if you have the header file. */ #undef HAVE_MEMORY_H @@ -127,7 +136,7 @@ /* Return type of HandleTopLevelDeclReturn */ #undef HandleTopLevelDeclReturn -/* Define to InputKind::C for newer versions of clang */ +/* Define to Language::C or InputKind::C for newer versions of clang */ #undef IK_C /* Define to the sub-directory where libtool stores uninstalled libraries. */ @@ -201,6 +210,9 @@ /* Define to getInstantiationLineNumber for older versions of clang */ #undef getExpansionLineNumber + +/* Define to getImmediateInstantiationRange for older versions of clang */ +#undef getImmediateExpansionRange /* Define to getNumParams for newer versions of clang */ #undef getNumArgs diff --git a/gcc/isl/isl_config_post.h b/gcc/isl/isl_config_post.h index 39373af..4ceb7f0 100644 --- a/gcc/isl/isl_config_post.h +++ a/gcc/isl/isl_config_post.h @@ -27,7 +27,7 @@ #define strncasecmp _strnicmp #endif -#if !HAVE_DECL_SNPRINTF && HAVE_DECL__SNPRINTF +#if HAVE_DECL__SNPRINTF #define snprintf _snprintf #endif diff --git a/gcc/isl/isl_constraint.c b/gcc/isl/isl_constraint.c index f1b0b4e..af1f216 100644 --- a/gcc/isl/isl_constraint.c +++ a/gcc/isl/isl_constraint.c @@ -22,8 +22,8 @@ #include #include -#undef BASE -#define BASE constraint +#undef EL_BASE +#define EL_BASE constraint #include @@ -32,7 +32,7 @@ return c ? isl_local_space_get_ctx(c->ls) : NULL; } -static unsigned n(struct isl_constraint *c, enum isl_dim_type type) +static isl_size n(struct isl_constraint *c, enum isl_dim_type type) { return isl_local_space_dim(c->ls, type); } @@ -42,26 +42,6 @@ return isl_local_space_offset(c->ls, type); } -static unsigned basic_map_offset(__isl_keep isl_basic_map *bmap, - enum isl_dim_type type) -{ - return type == isl_dim_div ? 1 + isl_space_dim(bmap->dim, isl_dim_all) - : 1 + isl_space_offset(bmap->dim, type); -} - -static unsigned basic_set_offset(struct isl_basic_set *bset, - enum isl_dim_type type) -{ - isl_space *dim = bset->dim; - switch (type) { - case isl_dim_param: return 1; - case isl_dim_in: return 1 + dim->nparam; - case isl_dim_out: return 1 + dim->nparam + dim->n_in; - case isl_dim_div: return 1 + dim->nparam + dim->n_in + dim->n_out; - default: return 0; - } -} - __isl_give isl_constraint *isl_constraint_alloc_vec(int eq, __isl_take isl_local_space *ls, __isl_take isl_vec *v) { @@ -89,14 +69,18 @@ __isl_give isl_constraint *isl_constraint_alloc(int eq, __isl_take isl_local_space *ls) { + isl_size dim; isl_ctx *ctx; isl_vec *v; + dim = isl_local_space_dim(ls, isl_dim_all); + if (dim < 0) + ls = isl_local_space_free(ls); if (!ls) return NULL; ctx = isl_local_space_get_ctx(ls); - v = isl_vec_alloc(ctx, 1 + isl_local_space_dim(ls, isl_dim_all)); + v = isl_vec_alloc(ctx, 1 + dim); v = isl_vec_clr(v); return isl_constraint_alloc_vec(eq, ls, v); } @@ -105,6 +89,7 @@ isl_int **line) { int eq; + isl_size dim; isl_ctx *ctx; isl_vec *v; isl_local_space *ls = NULL; @@ -117,7 +102,10 @@ ctx = isl_basic_map_get_ctx(bmap); ls = isl_basic_map_get_local_space(bmap); - v = isl_vec_alloc(ctx, 1 + isl_local_space_dim(ls, isl_dim_all)); + dim = isl_local_space_dim(ls, isl_dim_all); + if (dim < 0) + goto error; + v = isl_vec_alloc(ctx, 1 + dim); if (!v) goto error; isl_seq_cpy(v->el, line[0], v->size); @@ -197,10 +185,10 @@ * number of times isl_basic_map_foreach_constraint will * call the callback. */ -int isl_basic_map_n_constraint(__isl_keep isl_basic_map *bmap) +isl_size isl_basic_map_n_constraint(__isl_keep isl_basic_map *bmap) { if (!bmap) - return -1; + return isl_size_error; return bmap->n_eq + bmap->n_ineq; } @@ -209,7 +197,7 @@ * number of times isl_basic_set_foreach_constraint will * call the callback. */ -int isl_basic_set_n_constraint(__isl_keep isl_basic_set *bset) +isl_size isl_basic_set_n_constraint(__isl_keep isl_basic_set *bset) { return isl_basic_map_n_constraint(bset); } @@ -260,13 +248,15 @@ void *user) { isl_constraint_list **list = user; + isl_bool is_div; - if (isl_constraint_is_div_constraint(constraint)) + is_div = isl_constraint_is_div_constraint(constraint); + if (is_div < 0 || is_div) isl_constraint_free(constraint); else *list = isl_constraint_list_add(*list, constraint); - return isl_stat_ok; + return is_div < 0 ? isl_stat_error : isl_stat_ok; } /* Return a list of constraints that, when combined, are equivalent @@ -278,8 +268,8 @@ __isl_give isl_constraint_list *isl_basic_map_get_constraint_list( __isl_keep isl_basic_map *bmap) { - int n; - int known; + isl_size n; + isl_bool known; isl_ctx *ctx; isl_constraint_list *list; @@ -292,6 +282,8 @@ "input involves unknown divs", return NULL); n = isl_basic_map_n_constraint(bmap); + if (n < 0) + return NULL; list = isl_constraint_list_alloc(ctx, n); if (isl_basic_map_foreach_constraint(bmap, &collect_constraint, &list) < 0) @@ -328,16 +320,16 @@ struct isl_basic_map *bmap, struct isl_constraint *constraint) { isl_ctx *ctx; - isl_space *dim; + isl_space *space; int equal_space; if (!bmap || !constraint) goto error; ctx = isl_constraint_get_ctx(constraint); - dim = isl_constraint_get_space(constraint); - equal_space = isl_space_is_equal(bmap->dim, dim); - isl_space_free(dim); + space = isl_constraint_get_space(constraint); + equal_space = isl_space_is_equal(bmap->dim, space); + isl_space_free(space); isl_assert(ctx, equal_space, goto error); bmap = isl_basic_map_intersect(bmap, @@ -373,6 +365,14 @@ return isl_map_add_constraint(set, constraint); } +/* Return the space of "constraint". + */ +static __isl_keep isl_space *isl_constraint_peek_space( + __isl_keep isl_constraint *constraint) +{ + return constraint ? isl_local_space_peek_space(constraint->ls) : NULL; +} + __isl_give isl_space *isl_constraint_get_space( __isl_keep isl_constraint *constraint) { @@ -385,19 +385,23 @@ return constraint ? isl_local_space_copy(constraint->ls) : NULL; } -int isl_constraint_dim(struct isl_constraint *constraint, +isl_size isl_constraint_dim(__isl_keep isl_constraint *constraint, enum isl_dim_type type) { if (!constraint) - return -1; + return isl_size_error; return n(constraint, type); } +#undef TYPE +#define TYPE isl_constraint +static +#include "check_type_range_templ.c" + isl_bool isl_constraint_involves_dims(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned first, unsigned n) { int i; - isl_ctx *ctx; int *active = NULL; isl_bool involves = isl_bool_false; @@ -406,10 +410,8 @@ if (n == 0) return isl_bool_false; - ctx = isl_constraint_get_ctx(constraint); - if (first + n > isl_constraint_dim(constraint, type)) - isl_die(ctx, isl_error_invalid, - "range out of bounds", return isl_bool_error); + if (isl_constraint_check_range(constraint, type, first, n) < 0) + return isl_bool_error; active = isl_local_space_get_active(constraint->ls, constraint->v->el + 1); @@ -437,15 +439,11 @@ isl_bool isl_constraint_is_lower_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos) { - if (!constraint) + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) return isl_bool_error; - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, - "position out of bounds", return isl_bool_error); - pos += isl_local_space_offset(constraint->ls, type); - return isl_int_is_pos(constraint->v->el[pos]); + return isl_bool_ok(isl_int_is_pos(constraint->v->el[pos])); } /* Does the given constraint represent an upper bound on the given @@ -454,15 +452,11 @@ isl_bool isl_constraint_is_upper_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos) { - if (!constraint) + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) return isl_bool_error; - - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, - "position out of bounds", return isl_bool_error); pos += isl_local_space_offset(constraint->ls, type); - return isl_int_is_neg(constraint->v->el[pos]); + return isl_bool_ok(isl_int_is_neg(constraint->v->el[pos])); } const char *isl_constraint_get_dim_name(__isl_keep isl_constraint *constraint, @@ -497,13 +491,9 @@ void isl_constraint_get_coefficient(struct isl_constraint *constraint, enum isl_dim_type type, int pos, isl_int *v) { - if (!constraint) + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) return; - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(constraint->v->ctx, isl_error_invalid, - "position out of bounds", return); - pos += isl_local_space_offset(constraint->ls, type); isl_int_set(*v, constraint->v->el[pos]); } @@ -516,14 +506,10 @@ { isl_ctx *ctx; - if (!constraint) + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) return NULL; ctx = isl_constraint_get_ctx(constraint); - if (pos < 0 || pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(ctx, isl_error_invalid, - "position out of bounds", return NULL); - pos += isl_local_space_offset(constraint->ls, type); return isl_val_int_from_isl_int(ctx, constraint->v->el[pos]); } @@ -591,18 +577,9 @@ __isl_take isl_constraint *constraint, enum isl_dim_type type, int pos, isl_int v) { - constraint = isl_constraint_cow(constraint); - if (!constraint) - return NULL; - - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(constraint->v->ctx, isl_error_invalid, - "position out of bounds", - return isl_constraint_free(constraint)); - constraint = isl_constraint_cow(constraint); - if (!constraint) - return NULL; + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) + return isl_constraint_free(constraint); constraint->v = isl_vec_cow(constraint->v); if (!constraint->v) @@ -627,10 +604,8 @@ if (!isl_val_is_int(v)) isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, "expecting integer value", goto error); - - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, - "position out of bounds", goto error); + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) + goto error; pos += isl_local_space_offset(constraint->ls, type); constraint->v = isl_vec_set_element_val(constraint->v, pos, v); @@ -647,17 +622,8 @@ enum isl_dim_type type, int pos, int v) { constraint = isl_constraint_cow(constraint); - if (!constraint) - return NULL; - - if (pos >= isl_local_space_dim(constraint->ls, type)) - isl_die(constraint->v->ctx, isl_error_invalid, - "position out of bounds", - return isl_constraint_free(constraint)); - - constraint = isl_constraint_cow(constraint); - if (!constraint) - return NULL; + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) + return isl_constraint_free(constraint); constraint->v = isl_vec_cow(constraint->v); if (!constraint->v) @@ -693,19 +659,21 @@ { if (!constraint) return isl_bool_error; - return constraint->eq; + return isl_bool_ok(constraint->eq); } -int isl_constraint_is_div_constraint(__isl_keep isl_constraint *constraint) +isl_bool isl_constraint_is_div_constraint(__isl_keep isl_constraint *constraint) { int i; - int n_div; + isl_size n_div; if (!constraint) - return -1; + return isl_bool_error; if (isl_constraint_is_equality(constraint)) - return 0; + return isl_bool_false; n_div = isl_constraint_dim(constraint, isl_dim_div); + if (n_div < 0) + return isl_bool_error; for (i = 0; i < n_div; ++i) { isl_bool is_div; is_div = isl_local_space_is_div_constraint(constraint->ls, @@ -713,8 +681,34 @@ if (is_div < 0 || is_div) return is_div; } + + return isl_bool_false; +} + +/* Is "constraint" an equality that corresponds to integer division "div"? + * + * That is, given an integer division of the form + * + * a = floor((f + c)/m) + * + * is the equality of the form + * + * -f + m d + c' = 0 + * ? + * Note that the constant term is not checked explicitly, but given + * that this is a valid equality constraint, the constant c' necessarily + * has a value close to -c. + */ +isl_bool isl_constraint_is_div_equality(__isl_keep isl_constraint *constraint, + unsigned div) +{ + isl_bool equality; - return 0; + equality = isl_constraint_is_equality(constraint); + if (equality < 0 || !equality) + return equality; + return isl_local_space_is_div_equality(constraint->ls, + constraint->v->el, div); } /* We manually set ISL_BASIC_SET_FINAL instead of calling @@ -729,7 +723,7 @@ isl_local_space *ls; struct isl_basic_map *bmap; isl_int *c; - unsigned total; + isl_size total; if (!constraint) return NULL; @@ -749,7 +743,9 @@ goto error; c = bmap->ineq[k]; } - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + goto error; isl_seq_cpy(c, constraint->v->el, 1 + total); isl_constraint_free(constraint); if (bmap) @@ -764,12 +760,11 @@ __isl_give isl_basic_set *isl_basic_set_from_constraint( __isl_take isl_constraint *constraint) { - if (!constraint) - return NULL; + isl_space *space; - if (isl_constraint_dim(constraint, isl_dim_in) != 0) - isl_die(isl_constraint_get_ctx(constraint), isl_error_invalid, - "not a set constraint", goto error); + space = isl_constraint_peek_space(constraint); + if (isl_space_check_is_set(space) < 0) + goto error; return bset_from_bmap(isl_basic_map_from_constraint(constraint)); error: isl_constraint_free(constraint); @@ -787,15 +782,14 @@ { int i; unsigned offset; - unsigned total; + isl_size total; - if (!bmap) + if (isl_basic_map_check_range(bmap, type, pos, 1) < 0) + return isl_bool_error; + offset = isl_basic_map_offset(bmap, type); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return isl_bool_error; - offset = basic_map_offset(bmap, type); - total = isl_basic_map_total_dim(bmap); - if (pos >= isl_basic_map_dim(bmap, type)) - isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, - "invalid position", return isl_bool_error); for (i = 0; i < bmap->n_eq; ++i) { if (isl_int_is_zero(bmap->eq[i][offset + pos]) || isl_seq_first_non_zero(bmap->eq[i]+offset+pos+1, @@ -829,17 +823,16 @@ { int i, j; unsigned offset; - unsigned total; + isl_size total; isl_int m; isl_int **lower_line, **upper_line; - if (!bset) + if (isl_basic_set_check_range(bset, type, pos, 1) < 0) return isl_bool_error; - offset = basic_set_offset(bset, type); - total = isl_basic_set_total_dim(bset); - if (pos >= isl_basic_set_dim(bset, type)) - isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid, - "invalid position", return isl_bool_error); + offset = isl_basic_set_offset(bset, type); + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + return isl_bool_error; isl_int_init(m); for (i = 0; i < bset->n_ineq; ++i) { if (isl_int_is_zero(bset->ineq[i][offset + pos])) @@ -895,14 +888,15 @@ { int k; isl_int t; - unsigned total; + isl_size total; + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + return isl_basic_set_free(bset); k = isl_basic_set_alloc_inequality(bset); if (k < 0) goto error; - total = isl_basic_set_dim(bset, isl_dim_all); - isl_int_init(t); isl_int_neg(t, b[1 + abs_pos]); @@ -1164,17 +1158,17 @@ isl_basic_set *context = NULL; unsigned abs_pos; int n_lower, n_upper; + isl_size off; - if (!bset) + if (isl_basic_set_check_range(bset, type, pos, 1) < 0) return isl_stat_error; - isl_assert(bset->ctx, pos < isl_basic_set_dim(bset, type), - return isl_stat_error); isl_assert(bset->ctx, type == isl_dim_param || type == isl_dim_set, return isl_stat_error); - abs_pos = pos; - if (type == isl_dim_set) - abs_pos += isl_basic_set_dim(bset, isl_dim_param); + off = isl_basic_set_var_offset(bset, type); + if (off < 0) + return isl_stat_error; + abs_pos = off + pos; for (i = 0; i < bset->n_eq; ++i) { if (isl_int_is_zero(bset->eq[i][1 + abs_pos])) @@ -1222,25 +1216,23 @@ isl_constraint_free(lower); isl_constraint_free(upper); isl_basic_set_free(context); - return -1; + return isl_stat_error; } __isl_give isl_aff *isl_constraint_get_bound( __isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos) { + isl_space *space; isl_aff *aff; isl_ctx *ctx; - if (!constraint) + if (isl_constraint_check_range(constraint, type, pos, 1) < 0) return NULL; - ctx = isl_constraint_get_ctx(constraint); - if (pos >= isl_constraint_dim(constraint, type)) - isl_die(ctx, isl_error_invalid, - "index out of bounds", return NULL); - if (isl_constraint_dim(constraint, isl_dim_in) != 0) - isl_die(ctx, isl_error_invalid, - "not a set constraint", return NULL); + space = isl_constraint_peek_space(constraint); + if (isl_space_check_is_set(space) < 0) + return NULL; + ctx = isl_constraint_get_ctx(constraint); pos += offset(constraint, type); if (isl_int_is_zero(constraint->v->el[pos])) isl_die(ctx, isl_error_invalid, diff --git a/gcc/isl/isl_constraint_private.h b/gcc/isl/isl_constraint_private.h index 82f41df..7193987 100644 --- a/gcc/isl/isl_constraint_private.h +++ a/gcc/isl/isl_constraint_private.h @@ -26,4 +26,7 @@ void isl_constraint_get_coefficient(__isl_keep isl_constraint *constraint, enum isl_dim_type type, int pos, isl_int *v); +isl_bool isl_constraint_is_div_equality(__isl_keep isl_constraint *constraint, + unsigned div); + #endif diff --git a/gcc/isl/isl_convex_hull.c b/gcc/isl/isl_convex_hull.c index bedee1b..a6af5ba 100644 --- a/gcc/isl/isl_convex_hull.c +++ a/gcc/isl/isl_convex_hull.c @@ -113,7 +113,7 @@ * constraint c and if so, set the constant term such that the * resulting constraint is a bounding constraint for the set. */ -static int uset_is_bound(__isl_keep isl_set *set, isl_int *c, unsigned len) +static isl_bool uset_is_bound(__isl_keep isl_set *set, isl_int *c, unsigned len) { int first; int j; @@ -150,40 +150,13 @@ } isl_int_clear(opt); isl_int_clear(opt_denom); - return j >= set->n; + return isl_bool_ok(j >= set->n); error: isl_int_clear(opt); isl_int_clear(opt_denom); - return -1; + return isl_bool_error; } -static struct isl_basic_set *isl_basic_set_add_equality( - struct isl_basic_set *bset, isl_int *c) -{ - int i; - unsigned dim; - - if (!bset) - return NULL; - - if (ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY)) - return bset; - - isl_assert(bset->ctx, isl_basic_set_n_param(bset) == 0, goto error); - isl_assert(bset->ctx, bset->n_div == 0, goto error); - dim = isl_basic_set_n_dim(bset); - bset = isl_basic_set_cow(bset); - bset = isl_basic_set_extend(bset, 0, dim, 0, 1, 0); - i = isl_basic_set_alloc_equality(bset); - if (i < 0) - goto error; - isl_seq_cpy(bset->eq[i], c, 1 + dim); - return bset; -error: - isl_basic_set_free(bset); - return NULL; -} - static __isl_give isl_set *isl_set_add_basic_set_equality( __isl_take isl_set *set, isl_int *c) { @@ -193,7 +166,7 @@ if (!set) return NULL; for (i = 0; i < set->n; ++i) { - set->p[i] = isl_basic_set_add_equality(set->p[i], c); + set->p[i] = isl_basic_set_add_eq(set->p[i], c); if (!set->p[i]) goto error; } @@ -226,12 +199,13 @@ unsigned n_eq; unsigned n_ineq; int i, j, k; - unsigned dim, lp_dim; + isl_size dim, lp_dim; - if (!set) + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) return NULL; - dim = 1 + isl_set_n_dim(set); + dim += 1; n_eq = 1; n_ineq = set->n; for (i = 0; i < set->n; ++i) { @@ -242,7 +216,9 @@ lp = isl_basic_set_set_rational(lp); if (!lp) return NULL; - lp_dim = isl_basic_set_n_dim(lp); + lp_dim = isl_basic_set_dim(lp, isl_dim_set); + if (lp_dim < 0) + return isl_basic_set_free(lp); k = isl_basic_set_alloc_equality(lp); isl_int_set_si(lp->eq[k][0], -1); for (i = 0; i < set->n; ++i) { @@ -339,15 +315,16 @@ struct isl_vec *obj; enum isl_lp_result res; isl_int num, den; - unsigned dim; + isl_size dim; - if (!set) + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) return NULL; ctx = set->ctx; set = isl_set_copy(set); set = isl_set_set_rational(set); - dim = 1 + isl_set_n_dim(set); + dim += 1; T = isl_mat_alloc(ctx, 3, dim); if (!T) goto error; @@ -414,10 +391,12 @@ struct isl_set *slice = NULL; struct isl_basic_set *face = NULL; int i; - unsigned dim = isl_set_n_dim(set); - int is_bound; + isl_size dim = isl_set_dim(set, isl_dim_set); + isl_bool is_bound; isl_mat *bounds = NULL; + if (dim < 0) + return NULL; isl_assert(set->ctx, set->n > 0, goto error); bounds = isl_mat_alloc(set->ctx, 1, 1 + dim); if (!bounds) @@ -506,11 +485,13 @@ struct isl_mat *m, *U, *Q; struct isl_basic_set *facet = NULL; struct isl_ctx *ctx; - unsigned dim; + isl_size dim; + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) + return NULL; ctx = set->ctx; set = isl_set_copy(set); - dim = isl_set_n_dim(set); m = isl_mat_alloc(set->ctx, 2, 1 + dim); if (!m) goto error; @@ -562,22 +543,21 @@ int k; struct isl_basic_set *facet = NULL; struct isl_basic_set *hull_facet = NULL; - unsigned dim; + isl_size dim; - if (!hull) - return NULL; + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0 || !hull) + return isl_basic_set_free(hull); isl_assert(set->ctx, set->n > 0, goto error); - dim = isl_set_n_dim(set); - for (i = 0; i < hull->n_ineq; ++i) { facet = compute_facet(set, hull->ineq[i]); - facet = isl_basic_set_add_equality(facet, hull->ineq[i]); + facet = isl_basic_set_add_eq(facet, hull->ineq[i]); facet = isl_basic_set_gauss(facet, NULL); facet = isl_basic_set_normalize_constraints(facet); hull_facet = isl_basic_set_copy(hull); - hull_facet = isl_basic_set_add_equality(hull_facet, hull->ineq[i]); + hull_facet = isl_basic_set_add_eq(hull_facet, hull->ineq[i]); hull_facet = isl_basic_set_gauss(hull_facet, NULL); hull_facet = isl_basic_set_normalize_constraints(hull_facet); if (!facet || !hull_facet) @@ -768,12 +748,12 @@ int i, j, k; struct isl_basic_set *bset[2]; struct isl_basic_set *hull = NULL; - unsigned dim; + isl_size dim; - if (!bset1 || !bset2) + dim = isl_basic_set_dim(bset1, isl_dim_set); + if (dim < 0 || !bset2) goto error; - dim = isl_basic_set_n_dim(bset1); hull = isl_basic_set_alloc(bset1->ctx, 0, 2 + 3 * dim, 0, 1 + dim + bset1->n_eq + bset2->n_eq, 2 + bset1->n_ineq + bset2->n_ineq); @@ -849,9 +829,12 @@ */ isl_bool isl_basic_map_image_is_bounded(__isl_keep isl_basic_map *bmap) { - unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param); - unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in); + isl_size nparam = isl_basic_map_dim(bmap, isl_dim_param); + isl_size n_in = isl_basic_map_dim(bmap, isl_dim_in); isl_bool bounded; + + if (nparam < 0 || n_in < 0) + return isl_bool_error; bmap = isl_basic_map_copy(bmap); bmap = isl_basic_map_cow(bmap); @@ -891,12 +874,12 @@ { int i, k; struct isl_basic_set *lin = NULL; - unsigned dim; + isl_size dim; - if (!bset1 || !bset2) + dim = isl_basic_set_dim(bset1, isl_dim_all); + if (dim < 0 || !bset2) goto error; - dim = isl_basic_set_total_dim(bset1); lin = isl_basic_set_alloc_space(isl_basic_set_get_space(bset1), 0, bset1->n_eq + bset2->n_eq, bset1->n_ineq + bset2->n_ineq); @@ -967,12 +950,12 @@ static __isl_give isl_basic_set *modulo_lineality(__isl_take isl_set *set, __isl_take isl_basic_set *lin) { - unsigned total = isl_basic_set_total_dim(lin); + isl_size total = isl_basic_set_dim(lin, isl_dim_all); unsigned lin_dim; struct isl_basic_set *hull; struct isl_mat *M, *U, *Q; - if (!set || !lin) + if (!set || total < 0) goto error; lin_dim = total - lin->n_eq; M = isl_mat_sub_alloc6(set->ctx, lin->eq, 0, lin->n_eq, 1, total); @@ -1016,10 +999,12 @@ unsigned d; int n; int i, j, k; + isl_size total; - if (!bset1 || !bset2) + total = isl_basic_set_dim(bset1, isl_dim_all); + if (total < 0 || !bset2) goto error; - d = 1 + isl_basic_set_total_dim(bset1); + d = 1 + total; n = 2 + 2 * bset1->n_eq + bset1->n_ineq + 2 * bset2->n_eq + bset2->n_ineq; dim = isl_space_set_alloc(bset1->ctx, 0, n); @@ -1096,7 +1081,7 @@ struct isl_tab *tab; struct isl_vec *sample = NULL; struct isl_vec *dir; - unsigned d; + isl_size d; int i; int n; @@ -1110,7 +1095,9 @@ isl_basic_set_free(lp); if (!sample) goto error; - d = isl_basic_set_total_dim(bset1); + d = isl_basic_set_dim(bset1, isl_dim_all); + if (d < 0) + goto error; dir = isl_vec_alloc(bset1->ctx, 1 + d); if (!dir) goto error; @@ -1156,14 +1143,16 @@ __isl_take isl_mat *T) { int k; + isl_size total; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) goto error; bset = isl_basic_set_extend_constraints(bset, 0, 1); k = isl_basic_set_alloc_inequality(bset); if (k < 0) goto error; - isl_seq_clr(bset->ineq[k] + 1, isl_basic_set_total_dim(bset)); + isl_seq_clr(bset->ineq[k] + 1, total); isl_int_set_si(bset->ineq[k][0], 1); bset = isl_basic_set_preimage(bset, T); return bset; @@ -1295,7 +1284,8 @@ __isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2) { isl_basic_set *lin, *aff; - int bounded1, bounded2; + isl_bool bounded1, bounded2; + isl_size total; if (bset1->ctx->opt->convex == ISL_CONVEX_HULL_FM) return convex_hull_pair_elim(bset1, bset2); @@ -1329,7 +1319,8 @@ isl_basic_set_free(bset2); return lin; } - if (lin->n_eq < isl_basic_set_total_dim(lin)) { + total = isl_basic_set_dim(lin, isl_dim_all); + if (lin->n_eq < total) { struct isl_set *set; set = isl_set_alloc_space(isl_basic_set_get_space(bset1), 2, 0); set = isl_set_add_basic_set(set, bset1); @@ -1337,6 +1328,8 @@ return modulo_lineality(set, lin); } isl_basic_set_free(lin); + if (total < 0) + goto error; return convex_hull_pair_pointed(bset1, bset2); error: @@ -1357,12 +1350,12 @@ { int i, k; struct isl_basic_set *lin = NULL; - unsigned n_div, dim; + isl_size n_div, dim; - if (!bset) - goto error; n_div = isl_basic_set_dim(bset, isl_dim_div); - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (n_div < 0 || dim < 0) + return isl_basic_set_free(bset); lin = isl_basic_set_alloc_space(isl_basic_set_get_space(bset), n_div, dim, 0); @@ -1441,11 +1434,13 @@ isl_set_free(set); while (list) { - int n; + isl_size n, total; struct isl_basic_set *t; isl_basic_set *bset1, *bset2; n = isl_basic_set_list_n_basic_set(list); + if (n < 0) + goto error; if (n < 2) isl_die(isl_basic_set_list_get_ctx(list), isl_error_internal, @@ -1469,11 +1464,14 @@ isl_basic_set_list_free(list); return t; } - if (t->n_eq < isl_basic_set_total_dim(t)) { + total = isl_basic_set_dim(t, isl_dim_all); + if (t->n_eq < total) { set = isl_basic_set_list_union(list); return modulo_lineality(set, t); } isl_basic_set_free(t); + if (total < 0) + goto error; } return NULL; @@ -1490,7 +1488,7 @@ __isl_keep isl_set *set) { struct isl_mat *bounds = NULL; - unsigned dim; + isl_size dim; int k; if (!hull) @@ -1500,8 +1498,10 @@ goto error; k = isl_basic_set_alloc_inequality(hull); if (k < 0) + goto error; + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) goto error; - dim = isl_set_n_dim(set); isl_assert(set->ctx, 1 + dim == bounds->n_col, goto error); isl_seq_cpy(hull->ineq[k], bounds->row[0], bounds->n_col); isl_mat_free(bounds); @@ -1519,15 +1519,16 @@ int ineq; }; -static int max_constraint_equal(const void *entry, const void *val) +static isl_bool max_constraint_equal(const void *entry, const void *val) { struct max_constraint *a = (struct max_constraint *)entry; isl_int *b = (isl_int *)val; - return isl_seq_eq(a->c->row[0] + 1, b, a->c->n_col - 1); + return isl_bool_ok(isl_seq_eq(a->c->row[0] + 1, b, a->c->n_col - 1)); } -static void update_constraint(struct isl_ctx *ctx, struct isl_hash_table *table, +static isl_stat update_constraint(struct isl_ctx *ctx, + struct isl_hash_table *table, isl_int *con, unsigned len, int n, int ineq) { struct isl_hash_table_entry *entry; @@ -1538,30 +1539,34 @@ entry = isl_hash_table_find(ctx, table, c_hash, max_constraint_equal, con + 1, 0); if (!entry) - return; + return isl_stat_error; + if (entry == isl_hash_table_entry_none) + return isl_stat_ok; c = entry->data; if (c->count < n) { isl_hash_table_remove(ctx, table, entry); - return; + return isl_stat_ok; } c->count++; if (isl_int_gt(c->c->row[0][0], con[0])) - return; + return isl_stat_ok; if (isl_int_eq(c->c->row[0][0], con[0])) { if (ineq) c->ineq = ineq; - return; + return isl_stat_ok; } c->c = isl_mat_cow(c->c); isl_int_set(c->c->row[0][0], con[0]); c->ineq = ineq; + + return isl_stat_ok; } -/* Check whether the constraint hash table "table" constains the constraint +/* Check whether the constraint hash table "table" contains the constraint * "con". */ -static int has_constraint(struct isl_ctx *ctx, struct isl_hash_table *table, - isl_int *con, unsigned len, int n) +static isl_bool has_constraint(struct isl_ctx *ctx, + struct isl_hash_table *table, isl_int *con, unsigned len, int n) { struct isl_hash_table_entry *entry; struct max_constraint *c; @@ -1571,14 +1576,34 @@ entry = isl_hash_table_find(ctx, table, c_hash, max_constraint_equal, con + 1, 0); if (!entry) - return 0; + return isl_bool_error; + if (entry == isl_hash_table_entry_none) + return isl_bool_false; c = entry->data; if (c->count < n) - return 0; - return isl_int_eq(c->c->row[0][0], con[0]); + return isl_bool_false; + return isl_bool_ok(isl_int_eq(c->c->row[0][0], con[0])); +} + +/* Are the constraints of "bset" known to be facets? + * If there are any equality constraints, then they are not. + * If there may be redundant constraints, then those + * redundant constraints are not facets. + */ +static isl_bool has_facets(__isl_keep isl_basic_set *bset) +{ + int n_eq; + + n_eq = isl_basic_set_n_equality(bset); + if (n_eq < 0) + return isl_bool_error; + if (n_eq != 0) + return isl_bool_false; + return ISL_F_ISSET(bset, ISL_BASIC_SET_NO_REDUNDANT); } /* Check for inequality constraints of a basic set without equalities + * or redundant constraints * such that the same or more stringent copies of the constraint appear * in all of the basic sets. Such constraints are necessarily facet * constraints of the convex hull. @@ -1596,19 +1621,26 @@ int best; struct max_constraint *constraints = NULL; struct isl_hash_table *table = NULL; - unsigned total; + isl_size total; *is_hull = 0; - for (i = 0; i < set->n; ++i) - if (set->p[i]->n_eq == 0) + for (i = 0; i < set->n; ++i) { + isl_bool facets = has_facets(set->p[i]); + if (facets < 0) + return isl_basic_set_free(hull); + if (facets) break; + } if (i >= set->n) return hull; min_constraints = set->p[i]->n_ineq; best = i; for (i = best + 1; i < set->n; ++i) { - if (set->p[i]->n_eq != 0) + isl_bool facets = has_facets(set->p[i]); + if (facets < 0) + return isl_basic_set_free(hull); + if (!facets) continue; if (set->p[i]->n_ineq >= min_constraints) continue; @@ -1623,7 +1655,9 @@ if (isl_hash_table_init(hull->ctx, table, min_constraints)) goto error; - total = isl_space_dim(set->dim, isl_dim_all); + total = isl_set_dim(set, isl_dim_all); + if (total < 0) + goto error; for (i = 0; i < set->p[best]->n_ineq; ++i) { constraints[i].c = isl_mat_sub_alloc6(hull->ctx, set->p[best]->ineq + i, 0, 1, 0, 1 + total); @@ -1652,14 +1686,16 @@ isl_int *eq = set->p[s]->eq[i]; for (j = 0; j < 2; ++j) { isl_seq_neg(eq, eq, 1 + total); - update_constraint(hull->ctx, table, - eq, total, n, 0); + if (update_constraint(hull->ctx, table, + eq, total, n, 0) < 0) + goto error; } } for (i = 0; i < set->p[s]->n_ineq; ++i) { isl_int *ineq = set->p[s]->ineq[i]; - update_constraint(hull->ctx, table, ineq, total, n, - set->p[s]->n_eq == 0); + if (update_constraint(hull->ctx, table, ineq, total, n, + set->p[s]->n_eq == 0) < 0) + goto error; } ++n; } @@ -1681,8 +1717,12 @@ if (set->p[s]->n_ineq != hull->n_ineq) continue; for (i = 0; i < set->p[s]->n_ineq; ++i) { + isl_bool has; isl_int *ineq = set->p[s]->ineq[i]; - if (!has_constraint(hull->ctx, table, ineq, total, n)) + has = has_constraint(hull->ctx, table, ineq, total, n); + if (has < 0) + goto error; + if (!has) break; } if (i == set->p[s]->n_ineq) @@ -1753,10 +1793,14 @@ static __isl_give isl_basic_set *uset_convex_hull(__isl_take isl_set *set) { isl_bool bounded; + isl_size dim; struct isl_basic_set *convex_hull = NULL; struct isl_basic_set *lin; - if (isl_set_n_dim(set) == 0) + dim = isl_set_dim(set, isl_dim_all); + if (dim < 0) + goto error; + if (dim == 0) return convex_hull_0d(set); set = isl_set_coalesce(set); @@ -1769,7 +1813,7 @@ isl_set_free(set); return convex_hull; } - if (isl_set_n_dim(set) == 1) + if (dim == 1) return convex_hull_1d(set); bounded = isl_set_is_bounded(set); @@ -1785,7 +1829,7 @@ isl_set_free(set); return lin; } - if (lin->n_eq < isl_basic_set_total_dim(lin)) + if (lin->n_eq < dim) return modulo_lineality(set, lin); isl_basic_set_free(lin); @@ -1804,11 +1848,13 @@ __isl_take isl_set *set) { struct isl_basic_set *convex_hull = NULL; + isl_size dim; - if (!set) + dim = isl_set_dim(set, isl_dim_all); + if (dim < 0) goto error; - if (isl_set_n_dim(set) == 0) { + if (dim == 0) { convex_hull = isl_basic_set_universe(isl_space_copy(set->dim)); isl_set_free(set); convex_hull = isl_basic_set_set_rational(convex_hull); @@ -1825,7 +1871,7 @@ convex_hull = isl_basic_map_remove_redundancies(convex_hull); return convex_hull; } - if (isl_set_n_dim(set) == 1) + if (dim == 1) return convex_hull_1d(set); return uset_convex_hull_wrap(set); @@ -1985,13 +2031,13 @@ isl_int *p; }; -static int has_ineq(const void *entry, const void *val) +static isl_bool has_ineq(const void *entry, const void *val) { isl_int *row = (isl_int *)entry; struct ineq_cmp_data *v = (struct ineq_cmp_data *)val; - return isl_seq_eq(row + 1, v->p + 1, v->len) || - isl_seq_is_neg(row + 1, v->p + 1, v->len); + return isl_bool_ok(isl_seq_eq(row + 1, v->p + 1, v->len) || + isl_seq_is_neg(row + 1, v->p + 1, v->len)); } static int hash_ineq(struct isl_ctx *ctx, struct isl_hash_table *table, @@ -2015,24 +2061,26 @@ * Equalities are added as two inequalities. * The value in the hash table is a pointer to the (in)equality of "bset". */ -static int hash_basic_set(struct isl_hash_table *table, +static isl_stat hash_basic_set(struct isl_hash_table *table, __isl_keep isl_basic_set *bset) { int i, j; - unsigned dim = isl_basic_set_total_dim(bset); + isl_size dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + return isl_stat_error; for (i = 0; i < bset->n_eq; ++i) { for (j = 0; j < 2; ++j) { isl_seq_neg(bset->eq[i], bset->eq[i], 1 + dim); if (hash_ineq(bset->ctx, table, bset->eq[i], dim) < 0) - return -1; + return isl_stat_error; } } for (i = 0; i < bset->n_ineq; ++i) { if (hash_ineq(bset->ctx, table, bset->ineq[i], dim) < 0) - return -1; + return isl_stat_error; } - return 0; + return isl_stat_ok; } static struct sh_data *sh_data_alloc(__isl_keep isl_set *set, unsigned n_ineq) @@ -2116,7 +2164,8 @@ * least its constant term) may need to be temporarily negated to get * the actually hashed constraint. */ -static void set_max_constant_term(struct sh_data *data, __isl_keep isl_set *set, +static isl_stat set_max_constant_term(struct sh_data *data, + __isl_keep isl_set *set, int i, isl_int *ineq, uint32_t c_hash, struct ineq_cmp_data *v) { int j; @@ -2131,6 +2180,8 @@ entry = isl_hash_table_find(ctx, data->p[j].table, c_hash, &has_ineq, v, 0); if (!entry) + return isl_stat_error; + if (entry == isl_hash_table_entry_none) continue; ineq_j = entry->data; @@ -2142,6 +2193,8 @@ if (neg) isl_int_neg(ineq_j[0], ineq_j[0]); } + + return isl_stat_ok; } /* Check if inequality "ineq" from basic set "i" is or can be relaxed to @@ -2173,23 +2226,29 @@ struct ineq_cmp_data v; struct isl_hash_table_entry *entry; int j, k; + isl_size total; - if (!hull) - return NULL; + total = isl_basic_set_dim(hull, isl_dim_all); + if (total < 0) + return isl_basic_set_free(hull); - v.len = isl_basic_set_total_dim(hull); + v.len = total; v.p = ineq; c_hash = isl_seq_get_hash(ineq + 1, v.len); entry = isl_hash_table_find(hull->ctx, data->hull_table, c_hash, has_ineq, &v, 0); - if (entry) + if (!entry) + return isl_basic_set_free(hull); + if (entry != isl_hash_table_entry_none) return hull; for (j = 0; j < i; ++j) { entry = isl_hash_table_find(hull->ctx, data->p[j].table, c_hash, has_ineq, &v, 0); - if (entry) + if (!entry) + return isl_basic_set_free(hull); + if (entry != isl_hash_table_entry_none) break; } if (j < i) @@ -2200,7 +2259,8 @@ goto error; isl_seq_cpy(hull->ineq[k], ineq, 1 + v.len); - set_max_constant_term(data, set, i, hull->ineq[k], c_hash, &v); + if (set_max_constant_term(data, set, i, hull->ineq[k], c_hash, &v) < 0) + goto error; for (j = 0; j < i; ++j) { int bound; bound = is_bound(data, set, j, hull->ineq[k], shift); @@ -2208,28 +2268,26 @@ goto error; if (!bound) break; - } - if (j < i) { - isl_basic_set_free_inequality(hull, 1); - return hull; } + if (j < i) + return isl_basic_set_free_inequality(hull, 1); for (j = i + 1; j < set->n; ++j) { int bound; entry = isl_hash_table_find(hull->ctx, data->p[j].table, c_hash, has_ineq, &v, 0); - if (entry) + if (!entry) + return isl_basic_set_free(hull); + if (entry != isl_hash_table_entry_none) continue; bound = is_bound(data, set, j, hull->ineq[k], shift); if (bound < 0) goto error; if (!bound) break; - } - if (j < set->n) { - isl_basic_set_free_inequality(hull, 1); - return hull; } + if (j < set->n) + return isl_basic_set_free_inequality(hull, 1); entry = isl_hash_table_find(hull->ctx, data->hull_table, c_hash, has_ineq, &v, 1); @@ -2251,8 +2309,11 @@ struct sh_data *data, __isl_keep isl_set *set, int i, int shift) { int j, k; - unsigned dim = isl_basic_set_total_dim(bset); + isl_size dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + return isl_basic_set_free(bset); + for (j = 0; j < set->p[i]->n_eq; ++j) { for (k = 0; k < 2; ++k) { isl_seq_neg(set->p[i]->eq[j], set->p[i]->eq[j], 1+dim); @@ -2502,13 +2563,12 @@ __isl_take isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2) { int i1, i2; - unsigned total; + isl_size total; bmap1 = isl_basic_map_cow(bmap1); - if (!bmap1 || !bmap2) + total = isl_basic_map_dim(bmap1, isl_dim_all); + if (total < 0 || !bmap2) return isl_basic_map_free(bmap1); - - total = isl_basic_map_total_dim(bmap1); i1 = bmap1->n_eq - 1; i2 = bmap2->n_eq - 1; @@ -2634,11 +2694,13 @@ isl_ctx *ctx; uint32_t c_hash; struct ineq_cmp_data v; + isl_size total; - if (!hull || !set) + total = isl_basic_set_dim(hull, isl_dim_all); + if (total < 0 || !set) return isl_basic_set_free(hull); - v.len = isl_basic_set_total_dim(hull); + v.len = total; v.p = ineq; c_hash = isl_seq_get_hash(ineq + 1, v.len); @@ -2649,7 +2711,9 @@ entry = isl_hash_table_find(ctx, data->p[i].table, c_hash, &has_ineq, &v, 0); - if (entry) { + if (!entry) + return isl_basic_set_free(hull); + if (entry != isl_hash_table_entry_none) { isl_int *ineq_i = entry->data; int neg, more_relaxed; @@ -2706,7 +2770,7 @@ int last_added = 0; struct sh_data *data = NULL; isl_basic_set *hull = NULL; - unsigned dim; + isl_size dim; hull = isl_basic_set_alloc_space(isl_set_get_space(set), 0, 0, n_ineq); if (!hull) @@ -2717,6 +2781,8 @@ goto error; dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) + goto error; for (i = 0; i < n_ineq; ++i) { int hull_n_ineq = hull->n_ineq; int parallel; @@ -2752,14 +2818,15 @@ static __isl_give isl_mat *collect_inequalities(__isl_take isl_mat *mat, __isl_keep isl_basic_set_list *list, isl_int **ineq) { - int i, j, n, n_eq, n_ineq; + int i, j, n_eq, n_ineq; + isl_size n; - if (!mat) - return NULL; + n = isl_basic_set_list_n_basic_set(list); + if (!mat || n < 0) + return isl_mat_free(mat); n_eq = 0; n_ineq = 0; - n = isl_basic_set_list_n_basic_set(list); for (i = 0; i < n; ++i) { isl_basic_set *bset; bset = isl_basic_set_list_get_basic_set(list, i); @@ -2809,20 +2876,21 @@ static __isl_give isl_basic_set *uset_unshifted_simple_hull_from_basic_set_list( __isl_take isl_set *set, __isl_take isl_basic_set_list *list) { - int i, n, n_eq, n_ineq; - unsigned dim; + int i, n_eq, n_ineq; + isl_size n; + isl_size dim; isl_ctx *ctx; isl_mat *mat = NULL; isl_int **ineq = NULL; isl_basic_set *hull; - if (!set) + n = isl_basic_set_list_n_basic_set(list); + if (!set || n < 0) goto error; ctx = isl_set_get_ctx(set); n_eq = 0; n_ineq = 0; - n = isl_basic_set_list_n_basic_set(list); for (i = 0; i < n; ++i) { isl_basic_set *bset; bset = isl_basic_set_list_get_basic_set(list, i); @@ -2838,6 +2906,8 @@ goto error; dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) + goto error; mat = isl_mat_alloc(ctx, n_eq, 1 + dim); mat = collect_inequalities(mat, list, ineq); if (!mat) @@ -2874,15 +2944,17 @@ static __isl_give isl_basic_map *map_unshifted_simple_hull_from_basic_map_list( __isl_take isl_map *map, __isl_take isl_basic_map_list *list) { + isl_size n; isl_basic_map *model; isl_basic_map *hull; isl_set *set; isl_basic_set_list *bset_list; - if (!map || !list) + n = isl_basic_map_list_n_basic_map(list); + if (!map || n < 0) goto error; - if (isl_basic_map_list_n_basic_map(list) == 0) { + if (n == 0) { isl_space *space; space = isl_map_get_space(map); @@ -2920,7 +2992,8 @@ static __isl_give isl_basic_map_list *collect_basic_maps( __isl_take isl_map_list *list) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_basic_map_list *bmap_list; @@ -2929,6 +3002,8 @@ n = isl_map_list_n_map(list); ctx = isl_map_list_get_ctx(list); bmap_list = isl_basic_map_list_alloc(ctx, 0); + if (n < 0) + bmap_list = isl_basic_map_list_free(bmap_list); for (i = 0; i < n; ++i) { isl_map *map; @@ -2983,9 +3058,11 @@ /* Given a set "set", return parametric bounds on the dimension "dim". */ -static struct isl_basic_set *set_bounds(struct isl_set *set, int dim) +static __isl_give isl_basic_set *set_bounds(__isl_keep isl_set *set, int dim) { - unsigned set_dim = isl_set_dim(set, isl_dim_set); + isl_size set_dim = isl_set_dim(set, isl_dim_set); + if (set_dim < 0) + return NULL; set = isl_set_copy(set); set = isl_set_eliminate_dims(set, dim + 1, set_dim - (dim + 1)); set = isl_set_eliminate_dims(set, 0, dim); @@ -3000,19 +3077,22 @@ { int i, j; struct isl_basic_set *hull; - unsigned nparam, left; + isl_size nparam, dim, total; + unsigned left; int removed_divs = 0; hull = isl_set_simple_hull(isl_set_copy(set)); - if (!hull) + nparam = isl_basic_set_dim(hull, isl_dim_param); + dim = isl_basic_set_dim(hull, isl_dim_set); + total = isl_basic_set_dim(hull, isl_dim_all); + if (nparam < 0 || dim < 0 || total < 0) goto error; - nparam = isl_basic_set_dim(hull, isl_dim_param); - for (i = 0; i < isl_basic_set_dim(hull, isl_dim_set); ++i) { + for (i = 0; i < dim; ++i) { int lower = 0, upper = 0; struct isl_basic_set *bounds; - left = isl_basic_set_total_dim(hull) - nparam - i - 1; + left = total - nparam - i - 1; for (j = 0; j < hull->n_eq; ++j) { if (isl_int_is_zero(hull->eq[j][1 + nparam + i])) continue; diff --git a/gcc/isl/isl_ctx.c b/gcc/isl/isl_ctx.c index 1a57da7..176fd6f 100644 --- a/gcc/isl/isl_ctx.c +++ a/gcc/isl/isl_ctx.c @@ -14,12 +14,40 @@ #define __isl_calloc(type,size) ((type *)calloc(1, size)) #define __isl_calloc_type(type) __isl_calloc(type,sizeof(type)) +/* Construct an isl_stat indicating whether "obj" is non-NULL. + * + * That is, return isl_stat_ok if "obj" is non_NULL and + * isl_stat_error otherwise. + */ +isl_stat isl_stat_non_null(void *obj) +{ + if (obj != NULL) + return isl_stat_ok; + return isl_stat_error; +} + /* Return the negation of "b", where the negation of isl_bool_error * is isl_bool_error again. */ isl_bool isl_bool_not(isl_bool b) +{ + if (b < 0) + return isl_bool_error; + if (b == isl_bool_false) + return isl_bool_true; + return isl_bool_false; +} + +/* Create an isl_bool from an integer. + * + * Return isl_bool_false if b is zero, otherwise return isl_bool_true. + * This function never returns isl_bool_error. + */ +isl_bool isl_bool_ok(int b) { - return b < 0 ? isl_bool_error : !b; + if (b) + return isl_bool_true; + return isl_bool_false; } /* Check that the result of an allocation ("p") is not NULL and @@ -136,7 +164,7 @@ if (arg->type != isl_arg_child) continue; - if (arg->offset == (size_t) -1) + if (arg->offset == ISL_ARG_OFFSET_NONE) child = opt; else child = *(void **)(((char *)opt) + arg->offset); diff --git a/gcc/isl/isl_dim_map.c b/gcc/isl/isl_dim_map.c index cc104c6..b0b067d 100644 --- a/gcc/isl/isl_dim_map.c +++ a/gcc/isl/isl_dim_map.c @@ -42,6 +42,14 @@ return dim_map; } +/* Free "dim_map" and return NULL. + */ +__isl_null isl_dim_map *isl_dim_map_free(__isl_take isl_dim_map *dim_map) +{ + free(dim_map); + return NULL; +} + void isl_dim_map_range(__isl_keep isl_dim_map *dim_map, unsigned dst_pos, int dst_stride, unsigned src_pos, int src_stride, unsigned n, int sign) @@ -60,27 +68,30 @@ } void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map, - __isl_keep isl_space *dim, enum isl_dim_type type, + __isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n, unsigned dst_pos) { int i; unsigned src_pos; - if (!dim_map || !dim) + if (!dim_map || !space) return; - src_pos = 1 + isl_space_offset(dim, type); + src_pos = 1 + isl_space_offset(space, type); for (i = 0; i < n; ++i) { dim_map->m[1 + dst_pos + i].pos = src_pos + first + i; dim_map->m[1 + dst_pos + i].sgn = 1; } } -void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim, - enum isl_dim_type type, unsigned dst_pos) +void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, + __isl_keep isl_space *space, enum isl_dim_type type, unsigned dst_pos) { - isl_dim_map_dim_range(dim_map, dim, type, - 0, isl_space_dim(dim, type), dst_pos); + isl_size dim = isl_space_dim(space, type); + + if (dim < 0) + return; + isl_dim_map_dim_range(dim_map, space, type, 0, dim, dst_pos); } void isl_dim_map_div(__isl_keep isl_dim_map *dim_map, @@ -92,7 +103,7 @@ if (!dim_map || !bmap) return; - src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all); + src_pos = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < bmap->n_div; ++i) { dim_map->m[1 + dst_pos + i].pos = src_pos + i; dim_map->m[1 + dst_pos + i].sgn = 1; @@ -161,12 +172,12 @@ copy_div_dim_map(dst->div[i1], src->div[i], dim_map); } - free(dim_map); + isl_dim_map_free(dim_map); isl_basic_map_free(src); return dst; error: - free(dim_map); + isl_dim_map_free(dim_map); isl_basic_map_free(src); isl_basic_map_free(dst); return NULL; @@ -216,13 +227,19 @@ { int i; isl_ctx *ctx; + isl_size dim; + isl_space *space; struct isl_dim_map *dim_map; if (!exp) return NULL; - ctx = isl_space_get_ctx(exp->dim); - dim_map = isl_dim_map_alloc(ctx, isl_space_dim(exp->dim, isl_dim_all)); + ctx = isl_reordering_get_ctx(exp); + space = isl_reordering_peek_space(exp); + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + return NULL; + dim_map = isl_dim_map_alloc(ctx, dim); if (!dim_map) return NULL; diff --git a/gcc/isl/isl_dim_map.h b/gcc/isl/isl_dim_map.h index 0c39b49..5e45fe0 100644 --- a/gcc/isl/isl_dim_map.h +++ a/gcc/isl/isl_dim_map.h @@ -10,14 +10,15 @@ typedef struct isl_dim_map isl_dim_map; __isl_give isl_dim_map *isl_dim_map_alloc(isl_ctx *ctx, unsigned len); +__isl_null isl_dim_map *isl_dim_map_free(__isl_take isl_dim_map *dim_map); void isl_dim_map_range(__isl_keep isl_dim_map *dim_map, unsigned dst_pos, int dst_stride, unsigned src_pos, int src_stride, unsigned n, int sign); void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map, - isl_space *dim, enum isl_dim_type type, + __isl_keep isl_space *space, enum isl_dim_type type, unsigned first, unsigned n, unsigned dst_pos); -void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim, - enum isl_dim_type type, unsigned dst_pos); +void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, + __isl_keep isl_space *space, enum isl_dim_type type, unsigned dst_pos); void isl_dim_map_div(__isl_keep isl_dim_map *dim_map, __isl_keep isl_basic_map *bmap, unsigned dst_pos); __isl_give isl_basic_set *isl_basic_set_add_constraints_dim_map( diff --git a/gcc/isl/isl_equalities.c b/gcc/isl/isl_equalities.c index 0501cd9..f3d4846 100644 --- a/gcc/isl/isl_equalities.c +++ a/gcc/isl/isl_equalities.c @@ -634,15 +634,15 @@ __isl_take isl_basic_set *bset, __isl_give isl_mat **T, __isl_give isl_mat **T2) { - unsigned dim; + isl_size dim; isl_mat *id; - if (!bset) - return NULL; + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + return isl_basic_set_free(bset); if (!T && !T2) return bset; - dim = isl_basic_set_dim(bset, isl_dim_set); id = isl_mat_identity(isl_basic_map_get_ctx(bset), 1 + dim); if (T) *T = isl_mat_copy(id); @@ -660,21 +660,23 @@ * the new variables x2' back to the original variables x, while T2 * maps the original variables to the new variables. */ -static struct isl_basic_set *compress_variables( - struct isl_basic_set *bset, struct isl_mat **T, struct isl_mat **T2) +static __isl_give isl_basic_set *compress_variables( + __isl_take isl_basic_set *bset, + __isl_give isl_mat **T, __isl_give isl_mat **T2) { struct isl_mat *B, *TC; - unsigned dim; + isl_size dim; if (T) *T = NULL; if (T2) *T2 = NULL; - if (!bset) - goto error; - isl_assert(bset->ctx, isl_basic_set_n_param(bset) == 0, goto error); - isl_assert(bset->ctx, bset->n_div == 0, goto error); - dim = isl_basic_set_n_dim(bset); + if (isl_basic_set_check_no_params(bset) < 0 || + isl_basic_set_check_no_locals(bset) < 0) + return isl_basic_set_free(bset); + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + return isl_basic_set_free(bset); isl_assert(bset->ctx, bset->n_eq <= dim, goto error); if (bset->n_eq == 0) return return_with_identity(bset, T, T2); @@ -709,18 +711,13 @@ *T = NULL; if (T2) *T2 = NULL; - if (!bset) - return NULL; - isl_assert(bset->ctx, isl_basic_set_n_param(bset) == 0, goto error); + if (isl_basic_set_check_no_params(bset) < 0) + return isl_basic_set_free(bset); bset = isl_basic_set_gauss(bset, NULL); if (ISL_F_ISSET(bset, ISL_BASIC_SET_EMPTY)) return return_with_identity(bset, T, T2); bset = compress_variables(bset, T, T2); return bset; -error: - isl_basic_set_free(bset); - *T = NULL; - return NULL; } /* Check if dimension dim belongs to a residue class @@ -738,8 +735,8 @@ isl_bool fixed; struct isl_ctx *ctx; struct isl_mat *H = NULL, *U = NULL, *C, *H1, *U1; - unsigned total; - unsigned nparam; + isl_size total; + isl_size nparam; if (!bset || !modulo || !residue) return isl_stat_error; @@ -753,8 +750,10 @@ } ctx = isl_basic_set_get_ctx(bset); - total = isl_basic_set_total_dim(bset); - nparam = isl_basic_set_n_param(bset); + total = isl_basic_set_dim(bset, isl_dim_all); + nparam = isl_basic_set_dim(bset, isl_dim_param); + if (total < 0 || nparam < 0) + return isl_stat_error; H = isl_mat_sub_alloc6(ctx, bset->eq, 0, bset->n_eq, 1, total); H = isl_mat_left_hermite(H, 0, &U, NULL); if (!H) diff --git a/gcc/isl/isl_factorization.c b/gcc/isl/isl_factorization.c index f692cdb..e6036c3 100644 --- a/gcc/isl/isl_factorization.c +++ a/gcc/isl/isl_factorization.c @@ -84,16 +84,17 @@ __isl_take isl_mat *Q, __isl_take isl_mat *U, int n, int *len) { int i; - unsigned nvar; + isl_size nvar; unsigned ovar; - isl_space *dim; + isl_space *space; isl_basic_set *dom; isl_basic_set *ran; isl_morph *morph; isl_factorizer *f; isl_mat *id; - if (!bset || !Q || !U) + nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0 || !Q || !U) goto error; ovar = 1 + isl_space_offset(bset->dim, isl_dim_set); @@ -101,12 +102,11 @@ Q = isl_mat_diagonal(isl_mat_copy(id), Q); U = isl_mat_diagonal(id, U); - nvar = isl_basic_set_dim(bset, isl_dim_set); - dim = isl_basic_set_get_space(bset); - dom = isl_basic_set_universe(isl_space_copy(dim)); - dim = isl_space_drop_dims(dim, isl_dim_set, 0, nvar); - dim = isl_space_add_dims(dim, isl_dim_set, nvar); - ran = isl_basic_set_universe(dim); + space = isl_basic_set_get_space(bset); + dom = isl_basic_set_universe(isl_space_copy(space)); + space = isl_space_drop_dims(space, isl_dim_set, 0, nvar); + space = isl_space_add_dims(space, isl_dim_set, nvar); + ran = isl_basic_set_universe(space); morph = isl_morph_alloc(dom, ran, Q, U); f = isl_factorizer_alloc(morph, n); if (!f) @@ -258,17 +258,14 @@ { int i, j, n, done; isl_mat *H, *U, *Q; - unsigned nvar; + isl_size nvar; struct isl_factor_groups g = { 0 }; isl_factorizer *f; - if (!bset) + nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0 || isl_basic_set_check_no_locals(bset) < 0) return NULL; - isl_assert(bset->ctx, isl_basic_set_dim(bset, isl_dim_div) == 0, - return NULL); - - nvar = isl_basic_set_dim(bset, isl_dim_set); if (nvar <= 1) return isl_factorizer_identity(bset); diff --git a/gcc/isl/isl_farkas.c b/gcc/isl/isl_farkas.c index cb45a63..af982e6 100644 --- a/gcc/isl/isl_farkas.c +++ a/gcc/isl/isl_farkas.c @@ -61,27 +61,29 @@ * to the left, with the leftmost ending up in the constant position. */ -/* Add the given prefix to all named isl_dim_set dimensions in "dim". +/* Add the given prefix to all named isl_dim_set dimensions in "space". */ -static __isl_give isl_space *isl_space_prefix(__isl_take isl_space *dim, +static __isl_give isl_space *isl_space_prefix(__isl_take isl_space *space, const char *prefix) { int i; isl_ctx *ctx; - unsigned nvar; + isl_size nvar; size_t prefix_len = strlen(prefix); - if (!dim) + if (!space) return NULL; - ctx = isl_space_get_ctx(dim); - nvar = isl_space_dim(dim, isl_dim_set); + ctx = isl_space_get_ctx(space); + nvar = isl_space_dim(space, isl_dim_set); + if (nvar < 0) + return isl_space_free(space); for (i = 0; i < nvar; ++i) { const char *name; char *prefix_name; - name = isl_space_get_dim_name(dim, isl_dim_set, i); + name = isl_space_get_dim_name(space, isl_dim_set, i); if (!name) continue; @@ -92,13 +94,14 @@ memcpy(prefix_name, prefix, prefix_len); strcpy(prefix_name + prefix_len, name); - dim = isl_space_set_dim_name(dim, isl_dim_set, i, prefix_name); + space = isl_space_set_dim_name(space, + isl_dim_set, i, prefix_name); free(prefix_name); } - return dim; + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -115,55 +118,61 @@ * * and prefix each dimension name with "c_". */ -static __isl_give isl_space *isl_space_coefficients(__isl_take isl_space *dim) +static __isl_give isl_space *isl_space_coefficients(__isl_take isl_space *space) { - isl_space *dim_param; - unsigned nvar; - unsigned nparam; - - nvar = isl_space_dim(dim, isl_dim_set); - nparam = isl_space_dim(dim, isl_dim_param); - dim_param = isl_space_copy(dim); - dim_param = isl_space_drop_dims(dim_param, isl_dim_set, 0, nvar); - dim_param = isl_space_move_dims(dim_param, isl_dim_set, 0, + isl_space *space_param; + isl_size nvar; + isl_size nparam; + + nvar = isl_space_dim(space, isl_dim_set); + nparam = isl_space_dim(space, isl_dim_param); + if (nvar < 0 || nparam < 0) + return isl_space_free(space); + space_param = isl_space_copy(space); + space_param = isl_space_drop_dims(space_param, isl_dim_set, 0, nvar); + space_param = isl_space_move_dims(space_param, isl_dim_set, 0, isl_dim_param, 0, nparam); - dim_param = isl_space_prefix(dim_param, "c_"); - dim_param = isl_space_insert_dims(dim_param, isl_dim_set, 0, 1); - dim_param = isl_space_set_dim_name(dim_param, isl_dim_set, 0, "c_cst"); - dim = isl_space_drop_dims(dim, isl_dim_param, 0, nparam); - dim = isl_space_prefix(dim, "c_"); - dim = isl_space_join(isl_space_from_domain(dim_param), - isl_space_from_range(dim)); - dim = isl_space_wrap(dim); - dim = isl_space_set_tuple_name(dim, isl_dim_set, "coefficients"); - - return dim; + space_param = isl_space_prefix(space_param, "c_"); + space_param = isl_space_insert_dims(space_param, isl_dim_set, 0, 1); + space_param = isl_space_set_dim_name(space_param, + isl_dim_set, 0, "c_cst"); + space = isl_space_drop_dims(space, isl_dim_param, 0, nparam); + space = isl_space_prefix(space, "c_"); + space = isl_space_join(isl_space_from_domain(space_param), + isl_space_from_range(space)); + space = isl_space_wrap(space); + space = isl_space_set_tuple_name(space, isl_dim_set, "coefficients"); + + return space; } -/* Drop the given prefix from all named dimensions of type "type" in "dim". +/* Drop the given prefix from all named dimensions of type "type" in "space". */ -static __isl_give isl_space *isl_space_unprefix(__isl_take isl_space *dim, +static __isl_give isl_space *isl_space_unprefix(__isl_take isl_space *space, enum isl_dim_type type, const char *prefix) { int i; - unsigned n; + isl_size n; size_t prefix_len = strlen(prefix); - n = isl_space_dim(dim, type); + n = isl_space_dim(space, type); + if (n < 0) + return isl_space_free(space); for (i = 0; i < n; ++i) { const char *name; - name = isl_space_get_dim_name(dim, type, i); + name = isl_space_get_dim_name(space, type, i); if (!name) continue; if (strncmp(name, prefix, prefix_len)) continue; - dim = isl_space_set_dim_name(dim, type, i, name + prefix_len); + space = isl_space_set_dim_name(space, + type, i, name + prefix_len); } - return dim; + return space; } /* Given a dimension specification of the space of coefficients, construct @@ -179,19 +188,22 @@ * * and drop the "c_" prefix from the dimension names. */ -static __isl_give isl_space *isl_space_solutions(__isl_take isl_space *dim) +static __isl_give isl_space *isl_space_solutions(__isl_take isl_space *space) { - unsigned nparam; - - dim = isl_space_unwrap(dim); - dim = isl_space_drop_dims(dim, isl_dim_in, 0, 1); - dim = isl_space_unprefix(dim, isl_dim_in, "c_"); - dim = isl_space_unprefix(dim, isl_dim_out, "c_"); - nparam = isl_space_dim(dim, isl_dim_in); - dim = isl_space_move_dims(dim, isl_dim_param, 0, isl_dim_in, 0, nparam); - dim = isl_space_range(dim); - - return dim; + isl_size nparam; + + space = isl_space_unwrap(space); + space = isl_space_drop_dims(space, isl_dim_in, 0, 1); + space = isl_space_unprefix(space, isl_dim_in, "c_"); + space = isl_space_unprefix(space, isl_dim_out, "c_"); + nparam = isl_space_dim(space, isl_dim_in); + if (nparam < 0) + return isl_space_free(space); + space = isl_space_move_dims(space, + isl_dim_param, 0, isl_dim_in, 0, nparam); + space = isl_space_range(space); + + return space; } /* Return the rational universe basic set in the given space. @@ -210,7 +222,7 @@ * As explained above, we add an extra dimension to represent * the coefficient of the constant term when going from solutions * to coefficients (shift == 1) and we drop the extra dimension when going - * in the opposite direction (shift == -1). "dim" is the space in which + * in the opposite direction (shift == -1). "space" is the space in which * the dual should be created. * * If "bset" is (obviously) empty, then the way this emptiness @@ -223,14 +235,16 @@ { int i, j, k; isl_basic_set *dual = NULL; - unsigned total; + isl_size total; if (isl_basic_set_plain_is_empty(bset)) { isl_basic_set_free(bset); return rational_universe(space); } - total = isl_basic_set_total_dim(bset); + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + space = isl_space_free(space); dual = isl_basic_set_alloc_space(space, bset->n_eq + bset->n_ineq, total, bset->n_ineq + (shift > 0)); @@ -298,7 +312,7 @@ __isl_give isl_basic_set *isl_basic_set_coefficients( __isl_take isl_basic_set *bset) { - isl_space *dim; + isl_space *space; if (!bset) return NULL; @@ -307,10 +321,10 @@ "input set not allowed to have local variables", goto error); - dim = isl_basic_set_get_space(bset); - dim = isl_space_coefficients(dim); + space = isl_basic_set_get_space(bset); + space = isl_space_coefficients(space); - return farkas(dim, bset, 1); + return farkas(space, bset, 1); error: isl_basic_set_free(bset); return NULL; @@ -323,7 +337,7 @@ __isl_give isl_basic_set *isl_basic_set_solutions( __isl_take isl_basic_set *bset) { - isl_space *dim; + isl_space *space; if (!bset) return NULL; @@ -332,10 +346,10 @@ "input set not allowed to have local variables", goto error); - dim = isl_basic_set_get_space(bset); - dim = isl_space_solutions(dim); + space = isl_basic_set_get_space(bset); + space = isl_space_solutions(space); - return farkas(dim, bset, -1); + return farkas(space, bset, -1); error: isl_basic_set_free(bset); return NULL; diff --git a/gcc/isl/isl_flow.c b/gcc/isl/isl_flow.c index 946be84..1b88c23 100644 --- a/gcc/isl/isl_flow.c +++ a/gcc/isl/isl_flow.c @@ -162,7 +162,7 @@ int must; }; -typedef int (*isl_access_coscheduled)(void *first, void *second); +typedef isl_bool (*isl_access_coscheduled)(void *first, void *second); /* A structure containing the input for dependence analysis: * - a sink @@ -519,12 +519,12 @@ return isl_set_unwrap(isl_set_copy(deps->may_no_source)); } -void isl_flow_free(__isl_take isl_flow *deps) +__isl_null isl_flow *isl_flow_free(__isl_take isl_flow *deps) { int i; if (!deps) - return; + return NULL; isl_set_free(deps->must_no_source); isl_set_free(deps->may_no_source); if (deps->dep) { @@ -533,6 +533,8 @@ free(deps->dep); } free(deps); + + return NULL; } isl_ctx *isl_flow_get_ctx(__isl_keep isl_flow *deps) @@ -729,8 +731,11 @@ struct isl_map **temp_rel, int j, int sink_level) { int k, level; - int depth = 2 * isl_map_dim(acc->source[j].map, isl_dim_in) + 1; + isl_size n_in = isl_map_dim(acc->source[j].map, isl_dim_in); + int depth = 2 * n_in + 1; + if (n_in < 0) + return isl_stat_error; if (isl_map_plain_is_empty(temp_rel[j])) return isl_stat_ok; @@ -842,9 +847,12 @@ int j, int sink_level) { int k, level; - int depth = 2 * isl_map_dim(acc->source[acc->n_must + j].map, - isl_dim_in) + 1; - + isl_size n_in = isl_map_dim(acc->source[acc->n_must + j].map, + isl_dim_in); + int depth = 2 * n_in + 1; + + if (n_in < 0) + return isl_map_free(map); for (k = 0; k < acc->n_must; ++k) { int plevel; @@ -988,10 +996,16 @@ move = isl_map_empty(isl_map_get_space(must_rel[i])); for (j = i - 1; j >= 0; --j) { int depth; + isl_bool coscheduled; isl_map *map, *factor; - if (!acc->coscheduled(acc->source[i].data, - acc->source[j].data)) + coscheduled = acc->coscheduled(acc->source[i].data, + acc->source[j].data); + if (coscheduled < 0) { + isl_map_free(move); + return isl_flow_free(flow); + } + if (!coscheduled) continue; depth = acc->level_before(acc->source[i].data, acc->source[j].data) / 2; @@ -1003,11 +1017,17 @@ } for (j = 0; j < acc->n_may; ++j) { int depth, pos; + isl_bool coscheduled; isl_map *map, *factor; pos = acc->n_must + j; - if (!acc->coscheduled(acc->source[i].data, - acc->source[pos].data)) + coscheduled = acc->coscheduled(acc->source[i].data, + acc->source[pos].data); + if (coscheduled < 0) { + isl_map_free(move); + return isl_flow_free(flow); + } + if (!coscheduled) continue; depth = acc->level_before(acc->source[i].data, acc->source[pos].data) / 2; @@ -1132,6 +1152,7 @@ isl_set *mustdo = NULL; isl_set *maydo = NULL; int level, j; + isl_size n_in; int depth; isl_map **must_rel = NULL; isl_map **may_rel = NULL; @@ -1144,7 +1165,10 @@ goto error; ctx = isl_map_get_ctx(acc->sink.map); - depth = 2 * isl_map_dim(acc->sink.map, isl_dim_in) + 1; + n_in = isl_map_dim(acc->sink.map, isl_dim_in); + if (n_in < 0) + goto error; + depth = 2 * n_in + 1; mustdo = isl_map_domain(isl_map_copy(acc->sink.map)); maydo = isl_set_empty(isl_set_get_space(mustdo)); if (!mustdo || !maydo) @@ -1211,7 +1235,9 @@ goto error; } - handle_coscheduled(acc, must_rel, may_rel, res); + res = handle_coscheduled(acc, must_rel, may_rel, res); + if (!res) + goto error; for (j = 0; j < acc->n_may; ++j) { int plevel; @@ -1395,18 +1421,21 @@ __isl_keep isl_map *map) { isl_ctx *ctx; - isl_space *dim; + isl_space *space; struct isl_sched_info *info; - int i, n; + int i; + isl_size n; if (!map) return NULL; - dim = isl_space_unwrap(isl_space_domain(isl_map_get_space(map))); - if (!dim) + space = isl_space_unwrap(isl_space_domain(isl_map_get_space(map))); + if (!space) return NULL; - n = isl_space_dim(dim, isl_dim_in); - isl_space_free(dim); + n = isl_space_dim(space, isl_dim_in); + isl_space_free(space); + if (n < 0) + return NULL; ctx = isl_map_get_ctx(map); info = isl_alloc_type(ctx, struct isl_sched_info); @@ -1733,22 +1762,10 @@ return copy; } - -/* Print a key-value pair of a YAML mapping to "p", - * with key "name" and value "umap". - */ -static __isl_give isl_printer *print_union_map_field(__isl_take isl_printer *p, - const char *name, __isl_keep isl_union_map *umap) -{ - p = isl_printer_print_str(p, name); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_map(p, umap); - p = isl_printer_print_str(p, "\""); - p = isl_printer_yaml_next(p); - return p; -} +#undef BASE +#define BASE union_map +#include "print_yaml_field_templ.c" /* An enumeration of the various keys that may appear in a YAML mapping * of an isl_union_access_info object. @@ -1796,7 +1813,7 @@ if (empty) return p; } - return print_union_map_field(p, key_str[type], info->access[type]); + return print_yaml_field_union_map(p, key_str[type], info->access[type]); } /* Print the information contained in "access" to "p". @@ -1819,8 +1836,8 @@ p = isl_printer_print_schedule(p, access->schedule); p = isl_printer_yaml_next(p); } else { - p = print_union_map_field(p, key_str[isl_ai_key_schedule_map], - access->schedule_map); + p = print_yaml_field_union_map(p, + key_str[isl_ai_key_schedule_map], access->schedule_map); } p = isl_printer_yaml_end_mapping(p); @@ -2395,11 +2412,13 @@ { struct isl_sched_info *info1 = first; struct isl_sched_info *info2 = second; - int n1, n2; + isl_size n1, n2; int i; n1 = isl_vec_size(info1->cst); n2 = isl_vec_size(info2->cst); + if (n1 < 0 || n2 < 0) + return -1; if (n2 < n1) n1 = n2; @@ -2425,20 +2444,22 @@ } /* Check if the given two accesses may be coscheduled. - * If so, return 1. Otherwise return 0. + * If so, return isl_bool_true. Otherwise return isl_bool_false. * * Two accesses may only be coscheduled if the fixed schedule * coordinates have the same values. */ -static int coscheduled(void *first, void *second) +static isl_bool coscheduled(void *first, void *second) { struct isl_sched_info *info1 = first; struct isl_sched_info *info2 = second; - int n1, n2; + isl_size n1, n2; int i; n1 = isl_vec_size(info1->cst); n2 = isl_vec_size(info2->cst); + if (n1 < 0 || n2 < 0) + return isl_bool_error; if (n2 < n1) n1 = n2; @@ -2452,10 +2473,10 @@ continue; cmp = isl_vec_cmp_element(info1->cst, info2->cst, i); if (cmp != 0) - return 0; + return isl_bool_false; } - return 1; + return isl_bool_true; } /* Given a sink access, look for all the source accesses that access @@ -2798,6 +2819,7 @@ isl_union_set *domain; isl_union_map *umap; isl_bool r = isl_bool_false; + isl_size n; if (isl_schedule_node_get_type(node) != isl_schedule_node_leaf) return isl_bool_true; @@ -2806,23 +2828,23 @@ umap = isl_union_map_copy(data->access->access[isl_access_sink]); umap = isl_union_map_intersect_domain(umap, isl_union_set_copy(domain)); - data->n_sink += isl_union_map_n_map(umap); + data->n_sink += n = isl_union_map_n_map(umap); isl_union_map_free(umap); - if (!umap) + if (n < 0) r = isl_bool_error; umap = isl_union_map_copy(data->access->access[isl_access_must_source]); umap = isl_union_map_intersect_domain(umap, isl_union_set_copy(domain)); - data->n_source += isl_union_map_n_map(umap); + data->n_source += n = isl_union_map_n_map(umap); isl_union_map_free(umap); - if (!umap) + if (n < 0) r = isl_bool_error; umap = isl_union_map_copy(data->access->access[isl_access_may_source]); umap = isl_union_map_intersect_domain(umap, isl_union_set_copy(domain)); - data->n_source += isl_union_map_n_map(umap); + data->n_source += n = isl_union_map_n_map(umap); isl_union_map_free(umap); - if (!umap) + if (n < 0) r = isl_bool_error; isl_union_set_free(domain); @@ -2941,21 +2963,27 @@ isl_schedule_node *node1 = first; isl_schedule_node *node2 = second; isl_schedule_node *shared; - int depth; + isl_size depth; int before = 0; shared = isl_schedule_node_get_shared_ancestor(node1, node2); - if (!shared) + depth = isl_schedule_node_get_schedule_depth(shared); + if (depth < 0) { + isl_schedule_node_free(shared); return -1; + } - depth = isl_schedule_node_get_schedule_depth(shared); if (isl_schedule_node_get_type(shared) == isl_schedule_node_sequence) { - int pos1, pos2; + isl_size pos1, pos2; pos1 = isl_schedule_node_get_ancestor_child_position(node1, shared); pos2 = isl_schedule_node_get_ancestor_child_position(node2, shared); + if (pos1 < 0 || pos2 < 0) { + isl_schedule_node_free(shared); + return -1; + } before = pos1 < pos2; } @@ -2965,16 +2993,16 @@ } /* Check if the given two accesses may be coscheduled. - * If so, return 1. Otherwise return 0. + * If so, return isl_bool_true. Otherwise return isl_bool_false. * * Two accesses may only be coscheduled if they appear in the same leaf. */ -static int coscheduled_node(void *first, void *second) +static isl_bool coscheduled_node(void *first, void *second) { isl_schedule_node *node1 = first; isl_schedule_node *node2 = second; - return node1 == node2; + return isl_bool_ok(node1 == node2); } /* Add the scheduled sources from "data" that access @@ -3212,14 +3240,15 @@ p = isl_printer_yaml_start_mapping(p); umap = isl_union_flow_get_full_must_dependence(flow); - p = print_union_map_field(p, "must_dependence", umap); + p = print_yaml_field_union_map(p, "must_dependence", umap); isl_union_map_free(umap); umap = isl_union_flow_get_full_may_dependence(flow); - p = print_union_map_field(p, "may_dependence", umap); + p = print_yaml_field_union_map(p, "may_dependence", umap); isl_union_map_free(umap); - p = print_union_map_field(p, "must_no_source", flow->must_no_source); + p = print_yaml_field_union_map(p, "must_no_source", + flow->must_no_source); umap = isl_union_flow_get_may_no_source(flow); - p = print_union_map_field(p, "may_no_source", umap); + p = print_yaml_field_union_map(p, "may_no_source", umap); isl_union_map_free(umap); p = isl_printer_yaml_end_mapping(p); diff --git a/gcc/isl/isl_fold.c b/gcc/isl/isl_fold.c index be5c7f7..4c1e626 100644 --- a/gcc/isl/isl_fold.c +++ a/gcc/isl/isl_fold.c @@ -8,7 +8,6 @@ * 91893 Orsay, France */ -#define ISL_DIM_H #include #include #include @@ -21,9 +20,16 @@ #include #include +#undef EL_BASE +#define EL_BASE pw_qpolynomial_fold + +#include + enum isl_fold isl_fold_type_negate(enum isl_fold type) { switch (type) { + case isl_fold_error: + return isl_fold_error; case isl_fold_min: return isl_fold_max; case isl_fold_max: @@ -36,15 +42,15 @@ } static __isl_give isl_qpolynomial_fold *qpolynomial_fold_alloc( - enum isl_fold type, __isl_take isl_space *dim, int n) + enum isl_fold type, __isl_take isl_space *space, int n) { isl_qpolynomial_fold *fold; - if (!dim) + if (!space) goto error; - isl_assert(dim->ctx, n >= 0, goto error); - fold = isl_calloc(dim->ctx, struct isl_qpolynomial_fold, + isl_assert(space->ctx, n >= 0, goto error); + fold = isl_calloc(space->ctx, struct isl_qpolynomial_fold, sizeof(struct isl_qpolynomial_fold) + (n - 1) * sizeof(struct isl_qpolynomial *)); if (!fold) @@ -54,11 +60,11 @@ fold->size = n; fold->n = 0; fold->type = type; - fold->dim = dim; + fold->dim = space; return fold; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -255,12 +261,12 @@ */ static int isl_qpolynomial_cst_sign(__isl_keep isl_qpolynomial *qp) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; if (isl_qpolynomial_is_nan(qp)) return 0; - cst = isl_upoly_as_cst(qp->upoly); + cst = isl_poly_as_cst(qp->poly); if (!cst) return 0; @@ -325,10 +331,10 @@ static int isl_qpolynomial_sign(__isl_keep isl_set *set, __isl_keep isl_qpolynomial *qp) { - int d; + isl_size d; int i; - int is; - struct isl_upoly_rec *rec; + isl_bool is; + isl_poly_rec *rec; isl_vec *v; isl_int l; enum isl_lp_result res; @@ -349,18 +355,20 @@ if (qp->div->n_row > 0) return 0; - rec = isl_upoly_as_rec(qp->upoly); + rec = isl_poly_as_rec(qp->poly); if (!rec) return 0; d = isl_space_dim(qp->dim, isl_dim_all); + if (d < 0) + return 0; v = isl_vec_alloc(set->ctx, 2 + d); if (!v) return 0; isl_seq_clr(v->el + 1, 1 + d); isl_int_set_si(v->el[0], 1); - isl_int_set_si(v->el[2 + qp->upoly->var], 1); + isl_int_set_si(v->el[2 + qp->poly->var], 1); isl_int_init(l); @@ -373,16 +381,16 @@ min = isl_qpolynomial_cst_on_domain(isl_space_copy(qp->dim), l); base = isl_qpolynomial_var_pow_on_domain(isl_space_copy(qp->dim), - qp->upoly->var, 1); + qp->poly->var, 1); r = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0, - isl_upoly_copy(rec->p[rec->n - 1])); + isl_poly_copy(rec->p[rec->n - 1])); q = isl_qpolynomial_copy(r); for (i = rec->n - 2; i >= 0; --i) { r = isl_qpolynomial_mul(r, isl_qpolynomial_copy(min)); t = isl_qpolynomial_alloc(isl_space_copy(qp->dim), 0, - isl_upoly_copy(rec->p[i])); + isl_poly_copy(rec->p[i])); r = isl_qpolynomial_add(r, t); if (i == 0) break; @@ -659,6 +667,17 @@ isl_set *dom_context = isl_set_universe(space); dom_context = isl_set_intersect_params(dom_context, context); return isl_qpolynomial_fold_gist(fold, dom_context); +} + +/* Return a zero (i.e., empty) isl_qpolynomial_fold in the given space. + * + * This is a helper function for isl_pw_*_as_* that ensures a uniform + * interface over all piecewise types. + */ +static __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_zero_in_space( + __isl_take isl_space *space, enum isl_fold type) +{ + return isl_qpolynomial_fold_empty(type, isl_space_domain(space)); } #define isl_qpolynomial_fold_involves_nan isl_qpolynomial_fold_is_nan @@ -667,8 +686,8 @@ #undef PW #define PW isl_pw_qpolynomial_fold -#undef EL -#define EL isl_qpolynomial_fold +#undef BASE +#define BASE qpolynomial_fold #undef EL_IS_ZERO #define EL_IS_ZERO is_empty #undef ZERO @@ -685,13 +704,10 @@ #define NO_PULLBACK #include +#include -#undef UNION -#define UNION isl_union_pw_qpolynomial_fold -#undef PART -#define PART isl_pw_qpolynomial_fold -#undef PARTS -#define PARTS pw_qpolynomial_fold +#undef BASE +#define BASE pw_qpolynomial_fold #define NO_SUB @@ -774,27 +790,30 @@ return isl_qpolynomial_fold_dup(fold); } -void isl_qpolynomial_fold_free(__isl_take isl_qpolynomial_fold *fold) +__isl_null isl_qpolynomial_fold *isl_qpolynomial_fold_free( + __isl_take isl_qpolynomial_fold *fold) { int i; if (!fold) - return; + return NULL; if (--fold->ref > 0) - return; + return NULL; for (i = 0; i < fold->n; ++i) isl_qpolynomial_free(fold->qp[i]); isl_space_free(fold->dim); free(fold); + + return NULL; } -int isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold *fold) +isl_bool isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold *fold) { if (!fold) - return -1; + return isl_bool_error; - return fold->n == 0; + return isl_bool_ok(fold->n == 0); } /* Does "fold" represent max(NaN) or min(NaN)? @@ -1177,7 +1196,7 @@ /* Check whether for each quasi-polynomial in "fold2" there is * a quasi-polynomial in "fold1" that dominates it on "set". */ -static int qpolynomial_fold_covers_on_domain(__isl_keep isl_set *set, +static isl_bool qpolynomial_fold_covers_on_domain(__isl_keep isl_set *set, __isl_keep isl_qpolynomial_fold *fold1, __isl_keep isl_qpolynomial_fold *fold2) { @@ -1185,7 +1204,7 @@ int covers; if (!set || !fold1 || !fold2) - return -1; + return isl_bool_error; covers = fold1->type == isl_fold_max ? 1 : -1; @@ -1203,30 +1222,31 @@ break; } if (j >= fold1->n) - return 0; + return isl_bool_false; } - return 1; + return isl_bool_true; } /* Check whether "pwf1" dominated "pwf2", i.e., the domain of "pwf1" contains * that of "pwf2" and on each cell, the corresponding fold from pwf1 dominates * that of pwf2. */ -int isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold *pwf1, +isl_bool isl_pw_qpolynomial_fold_covers( + __isl_keep isl_pw_qpolynomial_fold *pwf1, __isl_keep isl_pw_qpolynomial_fold *pwf2) { int i, j; isl_set *dom1, *dom2; - int is_subset; + isl_bool is_subset; if (!pwf1 || !pwf2) - return -1; + return isl_bool_error; if (pwf2->n == 0) - return 1; + return isl_bool_true; if (pwf1->n == 0) - return 0; + return isl_bool_false; dom1 = isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf1)); dom2 = isl_pw_qpolynomial_fold_domain(isl_pw_qpolynomial_fold_copy(pwf2)); @@ -1239,9 +1259,9 @@ for (i = 0; i < pwf2->n; ++i) { for (j = 0; j < pwf1->n; ++j) { - int is_empty; + isl_bool is_empty; isl_set *common; - int covers; + isl_bool covers; common = isl_set_intersect(isl_set_copy(pwf1->p[j].set), isl_set_copy(pwf2->p[i].set)); @@ -1249,7 +1269,7 @@ if (is_empty < 0 || is_empty) { isl_set_free(common); if (is_empty < 0) - return -1; + return isl_bool_error; continue; } covers = qpolynomial_fold_covers_on_domain(common, @@ -1260,7 +1280,7 @@ } } - return 1; + return isl_bool_true; } __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_morph_domain( @@ -1303,15 +1323,25 @@ enum isl_fold isl_qpolynomial_fold_get_type(__isl_keep isl_qpolynomial_fold *fold) { if (!fold) - return isl_fold_list; + return isl_fold_error; return fold->type; +} + +/* Return the type of this piecewise quasipolynomial reduction. + */ +enum isl_fold isl_pw_qpolynomial_fold_get_type( + __isl_keep isl_pw_qpolynomial_fold *pwf) +{ + if (!pwf) + return isl_fold_error; + return pwf->type; } enum isl_fold isl_union_pw_qpolynomial_fold_get_type( __isl_keep isl_union_pw_qpolynomial_fold *upwf) { if (!upwf) - return isl_fold_list; + return isl_fold_error; return upwf->type; } @@ -1514,24 +1544,24 @@ */ __isl_give isl_pw_qpolynomial_fold *isl_map_apply_pw_qpolynomial_fold( __isl_take isl_map *map, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight) + isl_bool *tight) { isl_ctx *ctx; isl_set *dom; - isl_space *map_dim; - isl_space *pwf_dim; - unsigned n_in; + isl_space *map_space; + isl_space *pwf_space; + isl_size n_in; isl_bool ok; ctx = isl_map_get_ctx(map); if (!ctx) goto error; - map_dim = isl_map_get_space(map); - pwf_dim = isl_pw_qpolynomial_fold_get_space(pwf); - ok = join_compatible(map_dim, pwf_dim); - isl_space_free(map_dim); - isl_space_free(pwf_dim); + map_space = isl_map_get_space(map); + pwf_space = isl_pw_qpolynomial_fold_get_space(pwf); + ok = join_compatible(map_space, pwf_space); + isl_space_free(map_space); + isl_space_free(pwf_space); if (ok < 0) goto error; if (!ok) @@ -1539,6 +1569,8 @@ goto error); n_in = isl_map_dim(map, isl_dim_in); + if (n_in < 0) + goto error; pwf = isl_pw_qpolynomial_fold_insert_dims(pwf, isl_dim_in, 0, n_in); dom = isl_map_wrap(map); @@ -1557,7 +1589,7 @@ __isl_give isl_pw_qpolynomial_fold *isl_set_apply_pw_qpolynomial_fold( __isl_take isl_set *set, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight) + isl_bool *tight) { return isl_map_apply_pw_qpolynomial_fold(set, pwf, tight); } @@ -1566,7 +1598,7 @@ isl_union_pw_qpolynomial_fold *upwf; isl_union_pw_qpolynomial_fold *res; isl_map *map; - int tight; + isl_bool tight; }; static isl_stat pw_qpolynomial_fold_apply( @@ -1611,7 +1643,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_map_apply_union_pw_qpolynomial_fold( __isl_take isl_union_map *umap, - __isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight) + __isl_take isl_union_pw_qpolynomial_fold *upwf, isl_bool *tight) { isl_space *dim; enum isl_fold type; @@ -1623,7 +1655,7 @@ isl_union_pw_qpolynomial_fold_get_space(upwf)); data.upwf = upwf; - data.tight = tight ? 1 : 0; + data.tight = tight ? isl_bool_true : isl_bool_false; dim = isl_union_pw_qpolynomial_fold_get_space(upwf); type = isl_union_pw_qpolynomial_fold_get_type(upwf); data.res = isl_union_pw_qpolynomial_fold_zero(dim, type); @@ -1646,7 +1678,7 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_set_apply_union_pw_qpolynomial_fold( __isl_take isl_union_set *uset, - __isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight) + __isl_take isl_union_pw_qpolynomial_fold *upwf, isl_bool *tight) { return isl_union_map_apply_union_pw_qpolynomial_fold(uset, upwf, tight); } @@ -1657,6 +1689,7 @@ __isl_take isl_qpolynomial_fold *fold, __isl_take isl_reordering *r) { int i; + isl_space *space; fold = isl_qpolynomial_fold_cow(fold); if (!fold || !r) @@ -1669,8 +1702,8 @@ goto error; } - fold = isl_qpolynomial_fold_reset_domain_space(fold, - isl_space_copy(r->dim)); + space = isl_reordering_get_space(r); + fold = isl_qpolynomial_fold_reset_domain_space(fold, space); isl_reordering_free(r); diff --git a/gcc/isl/isl_hash.c b/gcc/isl/isl_hash.c index ca25d0d..59cb06e 100644 --- a/gcc/isl/isl_hash.c +++ a/gcc/isl/isl_hash.c @@ -8,7 +8,7 @@ */ #include -#include +#include #include #include "isl_config.h" @@ -63,9 +63,9 @@ /* Dummy comparison function that always returns false. */ -static int no(const void *entry, const void *val) +static isl_bool no(const void *entry, const void *val) { - return 0; + return isl_bool_false; } /* Extend "table" to twice its size. @@ -148,31 +148,37 @@ free(table); } -/* A dummy entry that can be used to make a distinction between - * a missing entry and an error condition. - * It is used by isl_union_*_find_part_entry. +/* A dummy entry that is used by isl_hash_table_find + * to make a distinction between a missing entry and an error condition. */ static struct isl_hash_table_entry none = { 0, NULL }; struct isl_hash_table_entry *isl_hash_table_entry_none = &none; struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx, - struct isl_hash_table *table, - uint32_t key_hash, - int (*eq)(const void *entry, const void *val), - const void *val, int reserve) + struct isl_hash_table *table, + uint32_t key_hash, + isl_bool (*eq)(const void *entry, const void *val), + const void *val, int reserve) { size_t size; uint32_t h, key_bits; key_bits = isl_hash_bits(key_hash, table->bits); size = 1 << table->bits; - for (h = key_bits; table->entries[h].data; h = (h+1) % size) - if (table->entries[h].hash == key_hash && - eq(table->entries[h].data, val)) + for (h = key_bits; table->entries[h].data; h = (h+1) % size) { + isl_bool equal; + + if (table->entries[h].hash != key_hash) + continue; + equal = eq(table->entries[h].data, val); + if (equal < 0) + return NULL; + if (equal) return &table->entries[h]; + } if (!reserve) - return NULL; + return isl_hash_table_entry_none; if (4 * table->n >= 3 * size) { if (grow_table(ctx, table) < 0) diff --git a/gcc/isl/isl_hash_private.h b/gcc/isl/isl_hash_private.h deleted file mode 100644 index c6b272a..0000000 100644 --- a/gcc/isl/isl_hash_private.h +++ /dev/null @@ -1,8 +1,0 @@ -#ifndef ISL_HASH_PRIVATE -#define ISL_HASH_PRIVATE - -#include - -extern struct isl_hash_table_entry *isl_hash_table_entry_none; - -#endif diff --git a/gcc/isl/isl_id.c b/gcc/isl/isl_id.c index d5c7c71..982d9eb 100644 --- a/gcc/isl/isl_id.c +++ a/gcc/isl/isl_id.c @@ -11,8 +11,8 @@ #include #include -#undef BASE -#define BASE id +#undef EL_BASE +#define EL_BASE id #include @@ -81,19 +81,19 @@ void *user; }; -static int isl_id_has_name_and_user(const void *entry, const void *val) +static isl_bool isl_id_has_name_and_user(const void *entry, const void *val) { isl_id *id = (isl_id *)entry; struct isl_name_and_user *nu = (struct isl_name_and_user *) val; if (id->user != nu->user) - return 0; + return isl_bool_false; if (id->name == nu->name) - return 1; + return isl_bool_true; if (!id->name || !nu->name) - return 0; + return isl_bool_false; - return !strcmp(id->name, nu->name); + return isl_bool_ok(!strcmp(id->name, nu->name)); } __isl_give isl_id *isl_id_alloc(isl_ctx *ctx, const char *name, void *user) @@ -164,9 +164,9 @@ return 1; } -static int isl_id_eq(const void *entry, const void *name) +static isl_bool isl_id_eq(const void *entry, const void *name) { - return entry == name; + return isl_bool_ok(entry == name); } uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id) @@ -209,6 +209,8 @@ entry = isl_hash_table_find(id->ctx, &id->ctx->id_table, id->hash, isl_id_eq, id, 0); if (!entry) + return NULL; + if (entry == isl_hash_table_entry_none) isl_die(id->ctx, isl_error_unknown, "unable to find id", (void)0); else @@ -241,4 +243,64 @@ error: isl_printer_free(p); return NULL; +} + +/* Read an isl_id from "s" based on its name. + */ +__isl_give isl_id *isl_stream_read_id(__isl_keep isl_stream *s) +{ + struct isl_token *tok; + char *str; + isl_ctx *ctx; + isl_id *id; + + if (!s) + return NULL; + tok = isl_stream_next_token(s); + if (!tok) { + isl_stream_error(s, NULL, "unexpected EOF"); + return NULL; + } + ctx = isl_stream_get_ctx(s); + str = isl_token_get_str(ctx, tok); + isl_token_free(tok); + if (!str) + return NULL; + id = isl_id_alloc(ctx, str, NULL); + free(str); + + return id; +} + +/* Read an isl_id object from the string "str". + */ +__isl_give isl_id *isl_id_read_from_str(isl_ctx *ctx, const char *str) +{ + isl_id *id; + isl_stream *s = isl_stream_new_str(ctx, str); + if (!s) + return NULL; + id = isl_stream_read_id(s); + 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 +#include +#include diff --git a/gcc/isl/isl_id_private.h b/gcc/isl/isl_id_private.h index 1d903c8..3b053e8 100644 --- a/gcc/isl/isl_id_private.h +++ a/gcc/isl/isl_id_private.h @@ -11,6 +11,7 @@ #define ISL_ID_PRIVATE_H #include +#include /* Represent a name and/or user pointer. * @@ -35,7 +36,13 @@ uint32_t isl_hash_id(uint32_t hash, __isl_keep isl_id *id); int isl_id_cmp(__isl_keep isl_id *id1, __isl_keep isl_id *id2); +__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 #endif diff --git a/gcc/isl/isl_id_to_ast_expr.c b/gcc/isl/isl_id_to_ast_expr.c index e088565..4bfa953 100644 --- a/gcc/isl/isl_id_to_ast_expr.c +++ a/gcc/isl/isl_id_to_ast_expr.c @@ -1,7 +1,8 @@ #include +#include #include -#define isl_id_is_equal(id1,id2) id1 == id2 +#define isl_id_is_equal(id1,id2) isl_bool_ok(id1 == id2) #define ISL_KEY isl_id #define ISL_VAL isl_ast_expr diff --git a/gcc/isl/isl_id_to_id.c b/gcc/isl/isl_id_to_id.c index dba2cf3..e92e8f6 100644 --- a/gcc/isl/isl_id_to_id.c +++ a/gcc/isl/isl_id_to_id.c @@ -1,6 +1,8 @@ +#include #include +#include -#define isl_id_is_equal(id1,id2) id1 == id2 +#define isl_id_is_equal(id1,id2) isl_bool_ok(id1 == id2) #define ISL_KEY isl_id #define ISL_VAL isl_id diff --git a/gcc/isl/isl_id_to_pw_aff.c b/gcc/isl/isl_id_to_pw_aff.c index 6ea6fea..1ef27b5 100644 --- a/gcc/isl/isl_id_to_pw_aff.c +++ a/gcc/isl/isl_id_to_pw_aff.c @@ -1,7 +1,8 @@ #include +#include #include -#define isl_id_is_equal(id1,id2) id1 == id2 +#define isl_id_is_equal(id1,id2) isl_bool_ok(id1 == id2) #define ISL_KEY isl_id #define ISL_VAL isl_pw_aff diff --git a/gcc/isl/isl_ilp.c b/gcc/isl/isl_ilp.c index d517290..bad23fb 100644 --- a/gcc/isl/isl_ilp.c +++ a/gcc/isl/isl_ilp.c @@ -36,7 +36,7 @@ { int i, j, k; struct isl_basic_set *unit_box = NULL; - unsigned total; + isl_size total; if (!bset) goto error; @@ -47,7 +47,9 @@ return isl_basic_set_empty(space); } - total = isl_basic_set_total_dim(bset); + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + goto error; unit_box = isl_basic_set_alloc_space(isl_basic_set_get_space(bset), 0, 0, bset->n_ineq); @@ -107,9 +109,11 @@ isl_int *f, isl_int l, isl_int u) { int k; - unsigned total; - - total = isl_basic_set_total_dim(bset); + isl_size total; + + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + return isl_basic_set_free(bset); bset = isl_basic_set_extend_constraints(bset, 0, 2); k = isl_basic_set_alloc_inequality(bset); @@ -263,13 +267,15 @@ static enum isl_lp_result solve_ilp_with_eq(__isl_keep isl_basic_set *bset, int max, isl_int *f, isl_int *opt, __isl_give isl_vec **sol_p) { - unsigned dim; + isl_size dim; enum isl_lp_result res; struct isl_mat *T = NULL; struct isl_vec *v; bset = isl_basic_set_copy(bset); - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + goto error; v = isl_vec_alloc(bset->ctx, 1 + dim); if (!v) goto error; @@ -305,16 +311,14 @@ enum isl_lp_result isl_basic_set_solve_ilp(__isl_keep isl_basic_set *bset, int max, isl_int *f, isl_int *opt, __isl_give isl_vec **sol_p) { - unsigned dim; + isl_size dim; enum isl_lp_result res; - if (!bset) - return isl_lp_error; if (sol_p) *sol_p = NULL; - isl_assert(bset->ctx, isl_basic_set_n_param(bset) == 0, - return isl_lp_error); + if (isl_basic_set_check_no_params(bset) < 0) + return isl_lp_error; if (isl_basic_set_plain_is_empty(bset)) return isl_lp_empty; @@ -322,7 +326,9 @@ if (bset->n_eq) return solve_ilp_with_eq(bset, max, f, opt, sol_p); - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + return isl_lp_error; if (max) isl_seq_neg(f, f, 1 + dim); @@ -349,23 +355,6 @@ res = isl_basic_set_solve_ilp(bset, max, obj->v->el + 1, opt, NULL); isl_basic_set_free(bset); return res; -} - -static __isl_give isl_mat *extract_divs(__isl_keep isl_basic_set *bset) -{ - int i; - isl_ctx *ctx = isl_basic_set_get_ctx(bset); - isl_mat *div; - - div = isl_mat_alloc(ctx, bset->n_div, - 1 + 1 + isl_basic_set_total_dim(bset)); - if (!div) - return NULL; - - for (i = 0; i < bset->n_div; ++i) - isl_seq_cpy(div->row[i], bset->div[i], div->n_col); - - return div; } enum isl_lp_result isl_basic_set_opt(__isl_keep isl_basic_set *bset, int max, @@ -377,7 +366,7 @@ isl_mat *bset_div = NULL; isl_mat *div = NULL; enum isl_lp_result res; - int bset_n_div, obj_n_div; + isl_size bset_n_div, obj_n_div; if (!bset || !obj) return isl_lp_error; @@ -393,13 +382,15 @@ bset_n_div = isl_basic_set_dim(bset, isl_dim_div); obj_n_div = isl_aff_dim(obj, isl_dim_div); + if (bset_n_div < 0 || obj_n_div < 0) + return isl_lp_error; if (bset_n_div == 0 && obj_n_div == 0) return basic_set_opt(bset, max, obj, opt); bset = isl_basic_set_copy(bset); obj = isl_aff_copy(obj); - bset_div = extract_divs(bset); + bset_div = isl_basic_set_get_divs(bset); exp1 = isl_alloc_array(ctx, int, bset_n_div); exp2 = isl_alloc_array(ctx, int, obj_n_div); if (!bset_div || (bset_n_div && !exp1) || (obj_n_div && !exp2)) @@ -651,15 +642,13 @@ return NULL; } -/* Internal data structure for isl_set_opt_pw_aff. +/* Internal data structure for isl_pw_aff_opt_val. * * "max" is set if the maximum should be computed. - * "set" is the set over which the optimum should be computed. * "res" contains the current optimum and is initialized to NaN. */ -struct isl_set_opt_data { +struct isl_pw_aff_opt_data { int max; - isl_set *set; isl_val *res; }; @@ -670,10 +659,9 @@ static isl_stat piece_opt(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user) { - struct isl_set_opt_data *data = user; + struct isl_pw_aff_opt_data *data = user; isl_val *opt; - set = isl_set_intersect(set, isl_set_copy(data->set)); opt = isl_set_opt_val(set, data->max, aff); isl_set_free(set); isl_aff_free(aff); @@ -686,57 +674,46 @@ } /* Return the minimum (maximum if "max" is set) of the integer piecewise affine - * expression "obj" over the points in "set". + * expression "pa" over its definition domain. * * Return infinity or negative infinity if the optimal value is unbounded and - * NaN if the intersection of "set" with the domain of "obj" is empty. + * NaN if the domain of "pa" is empty. * * Initialize the result to NaN and then update it for each of the pieces - * in "obj". + * in "pa". */ -static __isl_give isl_val *isl_set_opt_pw_aff(__isl_keep isl_set *set, int max, - __isl_keep isl_pw_aff *obj) +static __isl_give isl_val *isl_pw_aff_opt_val(__isl_take isl_pw_aff *pa, + int max) { - struct isl_set_opt_data data = { max, set }; + struct isl_pw_aff_opt_data data = { max }; - data.res = isl_val_nan(isl_set_get_ctx(set)); - if (isl_pw_aff_foreach_piece(obj, &piece_opt, &data) < 0) - return isl_val_free(data.res); + data.res = isl_val_nan(isl_pw_aff_get_ctx(pa)); + if (isl_pw_aff_foreach_piece(pa, &piece_opt, &data) < 0) + data.res = isl_val_free(data.res); + isl_pw_aff_free(pa); return data.res; } -/* Internal data structure for isl_union_set_opt_union_pw_aff. +/* Internal data structure for isl_union_pw_aff_opt_val. * * "max" is set if the maximum should be computed. - * "obj" is the objective function that needs to be optimized. * "res" contains the current optimum and is initialized to NaN. */ -struct isl_union_set_opt_data { +struct isl_union_pw_aff_opt_data { int max; - isl_union_pw_aff *obj; isl_val *res; }; -/* Update the optimum in data->res with the optimum over "set". - * Do so by first extracting the matching objective function - * from data->obj. +/* Update the optimum in data->res with the optimum of "pa". */ -static isl_stat set_opt(__isl_take isl_set *set, void *user) +static isl_stat pw_aff_opt(__isl_take isl_pw_aff *pa, void *user) { - struct isl_union_set_opt_data *data = user; - isl_space *space; - isl_pw_aff *pa; + struct isl_union_pw_aff_opt_data *data = user; isl_val *opt; - space = isl_set_get_space(set); - space = isl_space_from_domain(space); - space = isl_space_add_dims(space, isl_dim_out, 1); - pa = isl_union_pw_aff_extract_pw_aff(data->obj, space); - opt = isl_set_opt_pw_aff(set, data->max, pa); - isl_pw_aff_free(pa); - isl_set_free(set); + opt = isl_pw_aff_opt_val(pa, data->max); data->res = val_opt(data->res, opt, data->max); if (!data->res) @@ -746,61 +723,102 @@ } /* Return the minimum (maximum if "max" is set) of the integer piecewise affine - * expression "obj" over the points in "uset". + * expression "upa" over its definition domain. * * Return infinity or negative infinity if the optimal value is unbounded and - * NaN if the intersection of "uset" with the domain of "obj" is empty. + * NaN if the domain of the expression is empty. * - * Initialize the result to NaN and then update it for each of the sets - * in "uset". + * Initialize the result to NaN and then update it + * for each of the piecewise affine expressions in "upa". */ -static __isl_give isl_val *isl_union_set_opt_union_pw_aff( - __isl_keep isl_union_set *uset, int max, - __isl_keep isl_union_pw_aff *obj) +static __isl_give isl_val *isl_union_pw_aff_opt_val( + __isl_take isl_union_pw_aff *upa, int max) { - struct isl_union_set_opt_data data = { max, obj }; + struct isl_union_pw_aff_opt_data data = { max }; - data.res = isl_val_nan(isl_union_set_get_ctx(uset)); - if (isl_union_set_foreach_set(uset, &set_opt, &data) < 0) - return isl_val_free(data.res); + data.res = isl_val_nan(isl_union_pw_aff_get_ctx(upa)); + if (isl_union_pw_aff_foreach_pw_aff(upa, &pw_aff_opt, &data) < 0) + data.res = isl_val_free(data.res); + isl_union_pw_aff_free(upa); return data.res; } -/* Return a list of minima (maxima if "max" is set) over the points in "uset" - * for each of the expressions in "obj". +/* Return the minimum of the integer piecewise affine + * expression "upa" over its definition domain. + * + * Return negative infinity if the optimal value is unbounded and + * NaN if the domain of the expression is empty. + */ +__isl_give isl_val *isl_union_pw_aff_min_val(__isl_take isl_union_pw_aff *upa) +{ + return isl_union_pw_aff_opt_val(upa, 0); +} + +/* Return the maximum of the integer piecewise affine + * expression "upa" over its definition domain. + * + * Return infinity if the optimal value is unbounded and + * NaN if the domain of the expression is empty. + */ +__isl_give isl_val *isl_union_pw_aff_max_val(__isl_take isl_union_pw_aff *upa) +{ + return isl_union_pw_aff_opt_val(upa, 1); +} + +/* Return a list of minima (maxima if "max" is set) + * for each of the expressions in "mupa" over their domains. * * An element in the list is infinity or negative infinity if the optimal * value of the corresponding expression is unbounded and - * NaN if the intersection of "uset" with the domain of the expression - * is empty. + * NaN if the domain of the expression is empty. * - * Iterate over all the expressions in "obj" and collect the results. + * Iterate over all the expressions in "mupa" and collect the results. */ -static __isl_give isl_multi_val *isl_union_set_opt_multi_union_pw_aff( - __isl_keep isl_union_set *uset, int max, - __isl_keep isl_multi_union_pw_aff *obj) +static __isl_give isl_multi_val *isl_multi_union_pw_aff_opt_multi_val( + __isl_take isl_multi_union_pw_aff *mupa, int max) { - int i, n; + int i; + isl_size n; isl_multi_val *mv; - if (!uset || !obj) + n = isl_multi_union_pw_aff_size(mupa); + if (n < 0) + mupa = isl_multi_union_pw_aff_free(mupa); + if (!mupa) return NULL; - n = isl_multi_union_pw_aff_dim(obj, isl_dim_set); - mv = isl_multi_val_zero(isl_multi_union_pw_aff_get_space(obj)); + mv = isl_multi_val_zero(isl_multi_union_pw_aff_get_space(mupa)); for (i = 0; i < n; ++i) { isl_val *v; isl_union_pw_aff *upa; - upa = isl_multi_union_pw_aff_get_union_pw_aff(obj, i); - v = isl_union_set_opt_union_pw_aff(uset, max, upa); - isl_union_pw_aff_free(upa); + upa = isl_multi_union_pw_aff_get_union_pw_aff(mupa, i); + v = isl_union_pw_aff_opt_val(upa, max); mv = isl_multi_val_set_val(mv, i, v); } + isl_multi_union_pw_aff_free(mupa); return mv; +} + +/* Return a list of minima (maxima if "max" is set) over the points in "uset" + * for each of the expressions in "obj". + * + * An element in the list is infinity or negative infinity if the optimal + * value of the corresponding expression is unbounded and + * NaN if the intersection of "uset" with the domain of the expression + * is empty. + */ +static __isl_give isl_multi_val *isl_union_set_opt_multi_union_pw_aff( + __isl_keep isl_union_set *uset, int max, + __isl_keep isl_multi_union_pw_aff *obj) +{ + uset = isl_union_set_copy(uset); + obj = isl_multi_union_pw_aff_copy(obj); + obj = isl_multi_union_pw_aff_intersect_domain(obj, uset); + return isl_multi_union_pw_aff_opt_multi_val(obj, max); } /* Return a list of minima over the points in "uset" @@ -815,8 +833,34 @@ __isl_keep isl_union_set *uset, __isl_keep isl_multi_union_pw_aff *obj) { return isl_union_set_opt_multi_union_pw_aff(uset, 0, obj); +} + +/* Return a list of minima + * for each of the expressions in "mupa" over their domains. + * + * An element in the list is negative infinity if the optimal + * value of the corresponding expression is unbounded and + * NaN if the domain of the expression is empty. + */ +__isl_give isl_multi_val *isl_multi_union_pw_aff_min_multi_val( + __isl_take isl_multi_union_pw_aff *mupa) +{ + return isl_multi_union_pw_aff_opt_multi_val(mupa, 0); } +/* Return a list of maxima + * for each of the expressions in "mupa" over their domains. + * + * An element in the list is infinity if the optimal + * value of the corresponding expression is unbounded and + * NaN if the domain of the expression is empty. + */ +__isl_give isl_multi_val *isl_multi_union_pw_aff_max_multi_val( + __isl_take isl_multi_union_pw_aff *mupa) +{ + return isl_multi_union_pw_aff_opt_multi_val(mupa, 1); +} + /* Return the maximal value attained by the given set dimension, * independently of the parameter values and of any other dimensions. * @@ -830,11 +874,8 @@ isl_aff *obj; isl_val *v; - if (!bset) - return NULL; - if (pos < 0 || pos >= isl_basic_set_dim(bset, isl_dim_set)) - isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid, - "position out of bounds", goto error); + if (isl_basic_set_check_range(bset, isl_dim_set, pos, 1) < 0) + goto error; ls = isl_local_space_from_space(isl_basic_set_get_space(bset)); obj = isl_aff_var_on_domain(ls, isl_dim_set, pos); v = isl_basic_set_max_val(bset, obj); diff --git a/gcc/isl/isl_input.c b/gcc/isl/isl_input.c index d460b06..02af61d 100644 --- a/gcc/isl/isl_input.c +++ a/gcc/isl/isl_input.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -704,7 +705,7 @@ static __isl_give isl_pw_aff *accept_ternary(__isl_keep isl_stream *s, __isl_take isl_map *cond, struct vars *v, int rational) { - isl_space *dim; + isl_space *space; isl_pw_aff *pwaff1 = NULL, *pwaff2 = NULL, *pa_cond; if (!cond) @@ -713,17 +714,17 @@ if (isl_stream_eat(s, '?')) goto error; - dim = isl_space_wrap(isl_map_get_space(cond)); - pwaff1 = accept_extended_affine(s, dim, v, rational); + space = isl_space_wrap(isl_map_get_space(cond)); + pwaff1 = accept_extended_affine(s, space, v, rational); if (!pwaff1) goto error; if (isl_stream_eat(s, ':')) goto error; - dim = isl_pw_aff_get_domain_space(pwaff1); - pwaff2 = accept_extended_affine(s, dim, v, rational); - if (!pwaff1) + space = isl_pw_aff_get_domain_space(pwaff1); + pwaff2 = accept_extended_affine(s, space, v, rational); + if (!pwaff2) goto error; pa_cond = isl_set_indicator_function(isl_map_wrap(cond)); @@ -753,7 +754,7 @@ /* Push a token encapsulating "pa" onto "s", with the given * line and column. */ -static int push_aff(__isl_keep isl_stream *s, int line, int col, +static isl_stat push_aff(__isl_keep isl_stream *s, int line, int col, __isl_take isl_pw_aff *pa) { struct isl_token *tok; @@ -765,10 +766,27 @@ tok->u.pwaff = pa; isl_stream_push_token(s, tok); - return 0; + return isl_stat_ok; error: isl_pw_aff_free(pa); - return -1; + return isl_stat_error; +} + +/* Is the next token a comparison operator? + */ +static int next_is_comparator(__isl_keep isl_stream *s) +{ + int is_comp; + struct isl_token *tok; + + tok = isl_stream_next_token(s); + if (!tok) + return 0; + + is_comp = is_comparator(tok); + isl_stream_push_token(s, tok); + + return is_comp; } /* Accept an affine expression that may involve ternary operators. @@ -783,9 +801,7 @@ isl_space *space; isl_map *cond; isl_pw_aff *pwaff; - struct isl_token *tok; int line = -1, col = -1; - int is_comp; set_current_line_col(s, &line, &col); @@ -794,14 +810,7 @@ pwaff = isl_pw_aff_set_rational(pwaff); if (!pwaff) return NULL; - - tok = isl_stream_next_token(s); - if (!tok) - return isl_pw_aff_free(pwaff); - - is_comp = is_comparator(tok); - isl_stream_push_token(s, tok); - if (!is_comp) + if (!next_is_comparator(s)) return pwaff; space = isl_pw_aff_get_domain_space(pwaff); @@ -822,17 +831,23 @@ int rational) { isl_pw_aff *def; - int pos; + isl_size pos; isl_map *def_map; if (type == isl_dim_param) pos = isl_map_dim(map, isl_dim_param); else { pos = isl_map_dim(map, isl_dim_in); - if (type == isl_dim_out) - pos += isl_map_dim(map, isl_dim_out); + if (type == isl_dim_out) { + isl_size n_out = isl_map_dim(map, isl_dim_out); + if (pos < 0 || n_out < 0) + return isl_map_free(map); + pos += n_out; + } type = isl_dim_in; } + if (pos < 0) + return isl_map_free(map); --pos; def = accept_extended_affine(s, isl_space_wrap(isl_map_get_space(map)), @@ -952,6 +967,17 @@ isl_stream_push_token(s, tok); return is_tuple; +} + +/* Is the next token one that necessarily forms the start of a condition? + */ +static int next_is_condition_start(__isl_keep isl_stream *s) +{ + return isl_stream_next_token_is(s, ISL_TOKEN_EXISTS) || + isl_stream_next_token_is(s, ISL_TOKEN_NOT) || + isl_stream_next_token_is(s, ISL_TOKEN_TRUE) || + isl_stream_next_token_is(s, ISL_TOKEN_FALSE) || + isl_stream_next_token_is(s, ISL_TOKEN_MAP); } /* Is "pa" an expression in term of earlier dimensions? @@ -961,35 +987,36 @@ * of "n" expressions. The final dimensions of "pa" correspond to * these "n" expressions. */ -static int pw_aff_is_expr(__isl_keep isl_pw_aff *pa, int i, int n) +static isl_bool pw_aff_is_expr(__isl_keep isl_pw_aff *pa, int i, int n) { isl_aff *aff; if (!pa) - return -1; + return isl_bool_error; if (pa->n != 1) - return 1; + return isl_bool_true; if (!isl_set_plain_is_universe(pa->p[0].set)) - return 1; + return isl_bool_true; aff = pa->p[0].aff; if (isl_int_is_zero(aff->v->el[aff->v->size - n + i])) - return 1; - return 0; + return isl_bool_true; + return isl_bool_false; } /* Does the tuple contain any dimensions that are defined * in terms of earlier dimensions? */ -static int tuple_has_expr(__isl_keep isl_multi_pw_aff *tuple) +static isl_bool tuple_has_expr(__isl_keep isl_multi_pw_aff *tuple) { - int i, n; - int has_expr = 0; + int i; + isl_size n; + isl_bool has_expr = isl_bool_false; isl_pw_aff *pa; - if (!tuple) - return -1; n = isl_multi_pw_aff_dim(tuple, isl_dim_out); + if (n < 0) + return isl_bool_error; for (i = 0; i < n; ++i) { pa = isl_multi_pw_aff_get_pw_aff(tuple, i); has_expr = pw_aff_is_expr(pa, i, n); @@ -1022,6 +1049,110 @@ *prime = '\''; return space; +} + +/* Construct an isl_pw_aff defined on a "space" (with v->n variables) + * that is equal to the last of those variables. + */ +static __isl_give isl_pw_aff *identity_tuple_el_on_space( + __isl_take isl_space *space, struct vars *v) +{ + isl_aff *aff; + + aff = isl_aff_zero_on_domain(isl_local_space_from_space(space)); + aff = isl_aff_add_coefficient_si(aff, isl_dim_in, v->n - 1, 1); + return isl_pw_aff_from_aff(aff); +} + +/* Construct a piecewise affine expression corresponding + * to the last variable in "v" that ranges between "pa" and "pa2". + * + * In particular, if D is the domain space of "pa" (and "pa2"), + * then construct the expression + * + * D[..., i] -> i, + * + * construct the conditions + * + * D[..., i] : i >= pa + * D[..., i] : i <= pa2 + * + * and return + * + * D[..., i] -> i : pa <= i <= pa2 + */ +static __isl_give isl_pw_aff *construct_range(__isl_take isl_pw_aff *pa, + __isl_take isl_pw_aff *pa2, struct vars *v) +{ + isl_set *range1, *range2; + isl_space *space; + isl_pw_aff *range_pa; + + space = isl_pw_aff_get_domain_space(pa); + range_pa = identity_tuple_el_on_space(space, v); + range1 = isl_pw_aff_ge_set(isl_pw_aff_copy(range_pa), pa); + range2 = isl_pw_aff_le_set(isl_pw_aff_copy(range_pa), pa2); + range_pa = isl_pw_aff_intersect_domain(range_pa, range1); + range_pa = isl_pw_aff_intersect_domain(range_pa, range2); + + return range_pa; +} + +static int resolve_paren_expr(__isl_keep isl_stream *s, + struct vars *v, __isl_take isl_map *map, int rational); + +/* Given that the (piecewise) affine expression "pa" + * has just been parsed, followed by a colon, + * continue parsing as part of a piecewise affine expression. + * + * In particular, check if the colon is followed by a condition. + * If so, parse the conditions(a) on "pa" and include them in the domain. + * Otherwise, if the colon is followed by another (piecewise) affine expression + * then consider the two expressions as endpoints of a range of values and + * return a piecewise affine expression that takes values in that range. + * Note that an affine expression followed by a comparison operator + * is considered to be part of a condition. + */ +static __isl_give isl_pw_aff *update_piecewise_affine_colon( + __isl_take isl_pw_aff *pa, __isl_keep isl_stream *s, + struct vars *v, int rational) +{ + isl_space *dom_space; + isl_map *map; + + dom_space = isl_pw_aff_get_domain_space(pa); + map = isl_map_universe(isl_space_from_domain(dom_space)); + + if (isl_stream_next_token_is(s, '(')) + if (resolve_paren_expr(s, v, isl_map_copy(map), rational)) + goto error; + if (!next_is_condition_start(s)) { + int line = -1, col = -1; + isl_space *space; + isl_pw_aff *pa2; + + set_current_line_col(s, &line, &col); + space = isl_space_wrap(isl_map_get_space(map)); + pa2 = accept_affine(s, space, v); + if (rational) + pa2 = isl_pw_aff_set_rational(pa2); + if (!next_is_comparator(s)) { + isl_map_free(map); + pa2 = isl_pw_aff_domain_factor_domain(pa2); + return construct_range(pa, pa2, v); + } + if (push_aff(s, line, col, pa2) < 0) + goto error; + } + + map = read_formula(s, v, map, rational); + pa = isl_pw_aff_intersect_domain(pa, isl_map_domain(map)); + + return pa; +error: + isl_map_free(map); + isl_pw_aff_free(pa); + return NULL; } /* Accept a piecewise affine expression. @@ -1073,16 +1204,9 @@ goto error; pa = accept_extended_affine(s, isl_space_copy(space), v, rational); - } - if (isl_stream_eat_if_available(s, ':')) { - isl_space *dom_space; - isl_set *dom; - - dom_space = isl_pw_aff_get_domain_space(pa); - dom = isl_set_universe(dom_space); - dom = read_formula(s, v, dom, rational); - pa = isl_pw_aff_intersect_domain(pa, dom); } + if (isl_stream_eat_if_available(s, ':')) + pa = update_piecewise_affine_colon(pa, s, v, rational); res = isl_pw_aff_union_add(res, pa); @@ -1114,10 +1238,8 @@ space = isl_space_wrap(isl_space_alloc(s->ctx, 0, v->n, 0)); def = accept_piecewise_affine(s, space, v, rational); + def = isl_pw_aff_domain_factor_domain(def); - space = isl_space_set_alloc(s->ctx, 0, v->n); - def = isl_pw_aff_reset_domain_space(def, space); - return def; } @@ -1229,12 +1351,9 @@ static __isl_give isl_pw_aff *identity_tuple_el(struct vars *v) { isl_space *space; - isl_aff *aff; space = isl_space_set_alloc(v->ctx, 0, v->n); - aff = isl_aff_zero_on_domain(isl_local_space_from_space(space)); - aff = isl_aff_add_coefficient_si(aff, isl_dim_in, v->n - 1, 1); - return isl_pw_aff_from_aff(aff); + return identity_tuple_el_on_space(space, v); } /* This function is called for each element in a tuple inside read_tuple. @@ -1275,7 +1394,10 @@ isl_token_free(tok); pa = identity_tuple_el(v); } else if (new_name) { - int pos = isl_space_dim(space, isl_dim_out) - 1; + isl_size pos = isl_space_dim(space, isl_dim_out); + if (pos < 0) + goto error; + pos -= 1; space = space_set_dim_name(space, pos, v->v->name); isl_token_free(tok); if (isl_stream_eat_if_available(s, '=')) @@ -1318,7 +1440,8 @@ static __isl_give isl_multi_pw_aff *read_tuple(__isl_keep isl_stream *s, struct vars *v, int rational, int comma) { - int i, n; + int i; + isl_size n; isl_space *space; isl_pw_aff_list *list; @@ -1327,6 +1450,8 @@ space = read_tuple_space(s, v, space, rational, comma, &read_tuple_pw_aff_el, &list); n = isl_space_dim(space, isl_dim_set); + if (n < 0) + space = isl_space_free(space); for (i = 0; i + 1 < n; ++i) { isl_pw_aff *pa; @@ -1350,14 +1475,15 @@ __isl_take isl_map *map, enum isl_dim_type type, struct vars *v, int rational) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_space *space = NULL; - if (!map || !tuple) + n = isl_multi_pw_aff_dim(tuple, isl_dim_out); + if (!map || n < 0) goto error; ctx = isl_multi_pw_aff_get_ctx(tuple); - n = isl_multi_pw_aff_dim(tuple, isl_dim_out); space = isl_space_range(isl_multi_pw_aff_get_space(tuple)); if (!space) goto error; @@ -1463,14 +1589,14 @@ __isl_take isl_pw_aff_list *left, __isl_take isl_pw_aff_list *right) { isl_space *space; - int n; + isl_size n; isl_multi_pw_aff *mpa1, *mpa2; - if (!set || !left || !right) + n = isl_pw_aff_list_n_pw_aff(left); + if (!set || n < 0 || !right) goto error; space = isl_set_get_space(set); - n = isl_pw_aff_list_n_pw_aff(left); space = isl_space_from_domain(space); space = isl_space_add_dims(space, isl_dim_out, n); mpa1 = isl_multi_pw_aff_from_pw_aff_list(isl_space_copy(space), left); @@ -1575,7 +1701,7 @@ struct isl_token *tok; int type; isl_pw_aff_list *list1 = NULL, *list2 = NULL; - int n1, n2; + isl_size n1, n2; isl_set *set; set = isl_map_wrap(map); @@ -1593,10 +1719,10 @@ isl_token_free(tok); for (;;) { list2 = accept_affine_list(s, isl_set_get_space(set), v); - if (!list2) - goto error; n1 = isl_pw_aff_list_n_pw_aff(list1); n2 = isl_pw_aff_list_n_pw_aff(list2); + if (n1 < 0 || n2 < 0) + goto error; if (is_list_comparator_type(type) && n1 != n2) { isl_stream_error(s, NULL, "list arguments not of same size"); @@ -1607,12 +1733,9 @@ isl_pw_aff_list_free(list1); list1 = list2; - tok = isl_stream_next_token(s); - if (!is_comparator(tok)) { - if (tok) - isl_stream_push_token(s, tok); + if (!next_is_comparator(s)) break; - } + tok = isl_stream_next_token(s); type = tok->type; isl_token_free(tok); } @@ -1670,6 +1793,7 @@ struct vars *v, __isl_take isl_map *map, int rational) { struct isl_token *tok, *tok2; + int has_paren; int line, col; isl_pw_aff *pwaff; @@ -1681,11 +1805,7 @@ if (resolve_paren_expr(s, v, isl_map_copy(map), rational)) goto error; - if (isl_stream_next_token_is(s, ISL_TOKEN_EXISTS) || - isl_stream_next_token_is(s, ISL_TOKEN_NOT) || - isl_stream_next_token_is(s, ISL_TOKEN_TRUE) || - isl_stream_next_token_is(s, ISL_TOKEN_FALSE) || - isl_stream_next_token_is(s, ISL_TOKEN_MAP)) { + if (next_is_condition_start(s)) { map = read_formula(s, v, map, rational); if (isl_stream_eat(s, ')')) goto error; @@ -1706,20 +1826,16 @@ if (!pwaff) goto error; - tok2 = isl_token_new(s->ctx, line, col, 0); - if (!tok2) - goto error2; - tok2->type = ISL_TOKEN_AFF; - tok2->u.pwaff = pwaff; - - if (isl_stream_eat_if_available(s, ')')) { - isl_stream_push_token(s, tok2); + has_paren = isl_stream_eat_if_available(s, ')'); + + if (push_aff(s, line, col, pwaff) < 0) + goto error; + + if (has_paren) { isl_token_free(tok); isl_map_free(map); return 0; } - - isl_stream_push_token(s, tok2); map = read_formula(s, v, map, rational); if (isl_stream_eat(s, ')')) @@ -1730,8 +1846,6 @@ isl_stream_push_token(s, tok); return 0; -error2: - isl_pw_aff_free(pwaff); error: isl_token_free(tok); isl_map_free(map); @@ -1860,24 +1974,30 @@ return res; } -static int polylib_pos_to_isl_pos(__isl_keep isl_basic_map *bmap, int pos) +static isl_size polylib_pos_to_isl_pos(__isl_keep isl_basic_map *bmap, int pos) { - if (pos < isl_basic_map_dim(bmap, isl_dim_out)) - return 1 + isl_basic_map_dim(bmap, isl_dim_param) + - isl_basic_map_dim(bmap, isl_dim_in) + pos; - pos -= isl_basic_map_dim(bmap, isl_dim_out); + isl_size n_out, n_in, n_param, n_div; - if (pos < isl_basic_map_dim(bmap, isl_dim_in)) - return 1 + isl_basic_map_dim(bmap, isl_dim_param) + pos; - pos -= isl_basic_map_dim(bmap, isl_dim_in); + n_param = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + n_out = isl_basic_map_dim(bmap, isl_dim_out); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_param < 0 || n_in < 0 || n_out < 0 || n_div < 0) + return isl_size_error; - if (pos < isl_basic_map_dim(bmap, isl_dim_div)) - return 1 + isl_basic_map_dim(bmap, isl_dim_param) + - isl_basic_map_dim(bmap, isl_dim_in) + - isl_basic_map_dim(bmap, isl_dim_out) + pos; - pos -= isl_basic_map_dim(bmap, isl_dim_div); + if (pos < n_out) + return 1 + n_param + n_in + pos; + pos -= n_out; - if (pos < isl_basic_map_dim(bmap, isl_dim_param)) + if (pos < n_in) + return 1 + n_param + pos; + pos -= n_in; + + if (pos < n_div) + return 1 + n_param + n_in + n_out + pos; + pos -= n_div; + + if (pos < n_param) return 1 + pos; return 0; @@ -1891,6 +2011,7 @@ int type; int k; isl_int *c; + isl_size total; if (!bmap) return NULL; @@ -1922,8 +2043,11 @@ if (k < 0) goto error; - for (j = 0; j < 1 + isl_basic_map_total_dim(bmap); ++j) { - int pos; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); + for (j = 0; j < 1 + total; ++j) { + isl_size pos; tok = isl_stream_next_token(s); if (!tok || tok->type != ISL_TOKEN_VALUE) { isl_stream_error(s, tok, "expecting coefficient"); @@ -1938,8 +2062,11 @@ goto error; } pos = polylib_pos_to_isl_pos(bmap, j); - isl_int_set(c[pos], tok->u.v); + if (pos >= 0) + isl_int_set(c[pos], tok->u.v); isl_token_free(tok); + if (pos < 0) + return isl_basic_map_free(bmap); } return bmap; @@ -2461,6 +2588,8 @@ static struct isl_obj obj_add(__isl_keep isl_stream *s, struct isl_obj obj1, struct isl_obj obj2) { + if (obj2.type == isl_obj_none || !obj2.v) + goto error; if (obj1.type == isl_obj_set && obj2.type == isl_obj_union_set) obj1 = to_union(s->ctx, obj1); if (obj1.type == isl_obj_union_set && obj2.type == isl_obj_set) @@ -2577,7 +2706,41 @@ obj.type = isl_obj_schedule; obj.v = isl_stream_read_schedule(s); + + return obj; +} + +/* Read a disjunction of object bodies from "s". + * That is, read the inside of the braces, but not the braces themselves. + * "v" contains a description of the identifiers parsed so far. + * "map" contains information about the parameters. + */ +static struct isl_obj obj_read_disjuncts(__isl_keep isl_stream *s, + struct vars *v, __isl_keep isl_map *map) +{ + struct isl_obj obj = { isl_obj_set, NULL }; + + if (isl_stream_next_token_is(s, '}')) { + obj.type = isl_obj_union_set; + obj.v = isl_union_set_empty(isl_map_get_space(map)); + return obj; + } + for (;;) { + struct isl_obj o; + o = obj_read_body(s, isl_map_copy(map), v); + if (!obj.v) + obj = o; + else + obj = obj_add(s, obj, o); + if (obj.type == isl_obj_none || !obj.v) + return obj; + if (!isl_stream_eat_if_available(s, ';')) + break; + if (isl_stream_next_token_is(s, '}')) + break; + } + return obj; } @@ -2662,37 +2825,14 @@ map = read_map_tuple(s, map, isl_dim_param, v, 0, 1); if (!map) goto error; - } else if (tok->type == '}') { - obj.type = isl_obj_union_set; - obj.v = isl_union_set_empty(isl_map_get_space(map)); - isl_token_free(tok); - goto done; } else isl_stream_push_token(s, tok); - for (;;) { - struct isl_obj o; - tok = NULL; - o = obj_read_body(s, isl_map_copy(map), v); - if (o.type == isl_obj_none || !o.v) - goto error; - if (!obj.v) - obj = o; - else { - obj = obj_add(s, obj, o); - if (obj.type == isl_obj_none || !obj.v) - goto error; - } - tok = isl_stream_next_token(s); - if (!tok || tok->type != ';') - break; - isl_token_free(tok); - if (isl_stream_next_token_is(s, '}')) { - tok = isl_stream_next_token(s); - break; - } - } + obj = obj_read_disjuncts(s, v, map); + if (obj.type == isl_obj_none || !obj.v) + goto error; + tok = isl_stream_next_token(s); if (tok && tok->type == '}') { isl_token_free(tok); } else { @@ -2701,7 +2841,7 @@ isl_token_free(tok); goto error; } -done: + vars_free(v); isl_map_free(map); @@ -2782,22 +2922,36 @@ return NULL; } -__isl_give isl_union_set *isl_stream_read_union_set(__isl_keep isl_stream *s) +/* Extract an isl_union_set from "obj". + * This only works if the object was detected as either a set + * (in which case it is converted to a union set) or a union set. + */ +static __isl_give isl_union_set *extract_union_set(isl_ctx *ctx, + struct isl_obj obj) { - struct isl_obj obj; - - obj = obj_read(s); if (obj.type == isl_obj_set) { obj.type = isl_obj_union_set; obj.v = isl_union_set_from_set(obj.v); } if (obj.v) - isl_assert(s->ctx, obj.type == isl_obj_union_set, goto error); + isl_assert(ctx, obj.type == isl_obj_union_set, goto error); return obj.v; error: obj.type->free(obj.v); return NULL; +} + +/* Read an isl_union_set from "s". + * First read a generic object and then try and extract + * an isl_union_set from that. + */ +__isl_give isl_union_set *isl_stream_read_union_set(__isl_keep isl_stream *s) +{ + struct isl_obj obj; + + obj = obj_read(s); + return extract_union_set(s->ctx, obj); } static __isl_give isl_basic_map *basic_map_read(__isl_keep isl_stream *s) @@ -3152,11 +3306,13 @@ { isl_aff *aff; isl_multi_aff *ma; + isl_size dim; ma = isl_stream_read_multi_aff(s); - if (!ma) - return NULL; - if (isl_multi_aff_dim(ma, isl_dim_out) != 1) + dim = isl_multi_aff_dim(ma, isl_dim_out); + if (dim < 0) + goto error; + if (dim != 1) isl_die(s->ctx, isl_error_invalid, "expecting single affine expression", goto error); @@ -3287,12 +3443,15 @@ static __isl_give isl_multi_pw_aff *extract_mpa_from_tuple( __isl_take isl_space *dom_space, __isl_keep isl_multi_pw_aff *tuple) { - int dim, i, n; + int i; + isl_size dim, n; isl_space *space; isl_multi_pw_aff *mpa; n = isl_multi_pw_aff_dim(tuple, isl_dim_out); dim = isl_space_dim(dom_space, isl_dim_all); + if (n < 0 || dim < 0) + dom_space = isl_space_free(dom_space); space = isl_space_range(isl_multi_pw_aff_get_space(tuple)); space = isl_space_align_params(space, isl_space_copy(dom_space)); if (!isl_space_is_params(dom_space)) @@ -3353,13 +3512,15 @@ if (!tuple) goto error; } + mpa = extract_mpa_from_tuple(isl_set_get_space(dom), tuple); + isl_multi_pw_aff_free(tuple); + if (!mpa) + dom = isl_set_free(dom); dom = read_optional_formula(s, dom, v, 0); vars_drop(v, v->n - n); - mpa = extract_mpa_from_tuple(isl_set_get_space(dom), tuple); - isl_multi_pw_aff_free(tuple); pma = isl_pw_multi_aff_from_multi_pw_aff(mpa); pma = isl_pw_multi_aff_intersect_domain(pma, dom); @@ -3496,87 +3657,17 @@ error: isl_pw_aff_free(pa); return NULL; -} - -/* This function is called for each element in a tuple inside - * isl_stream_read_multi_val. - * Read an isl_val from "s" and add it to *list. - */ -static __isl_give isl_space *read_val_el(__isl_keep isl_stream *s, - struct vars *v, __isl_take isl_space *space, int rational, void *user) -{ - isl_val_list **list = (isl_val_list **) user; - isl_val *val; - - val = isl_stream_read_val(s); - *list = isl_val_list_add(*list, val); - if (!*list) - return isl_space_free(space); - - return space; } - -/* Read an isl_multi_val from "s". - * - * We first read a tuple space, collecting the element values in a list. - * Then we create an isl_multi_val from the space and the isl_val_list. - */ -__isl_give isl_multi_val *isl_stream_read_multi_val(__isl_keep isl_stream *s) -{ - struct vars *v; - isl_set *dom = NULL; - isl_space *space; - isl_multi_val *mv = NULL; - isl_val_list *list; - - v = vars_new(s->ctx); - if (!v) - return NULL; - - dom = isl_set_universe(isl_space_params_alloc(s->ctx, 0)); - if (next_is_tuple(s)) { - dom = read_map_tuple(s, dom, isl_dim_param, v, 1, 0); - if (isl_stream_eat(s, ISL_TOKEN_TO)) - goto error; - } - if (!isl_set_plain_is_universe(dom)) - isl_die(s->ctx, isl_error_invalid, - "expecting universe parameter domain", goto error); - if (isl_stream_eat(s, '{')) - goto error; - space = isl_set_get_space(dom); +#undef BASE +#define BASE val - list = isl_val_list_alloc(s->ctx, 0); - space = read_tuple_space(s, v, space, 1, 0, &read_val_el, &list); - mv = isl_multi_val_from_val_list(space, list); - - if (isl_stream_eat(s, '}')) - goto error; +#include - vars_free(v); - isl_set_free(dom); - return mv; -error: - vars_free(v); - isl_set_free(dom); - isl_multi_val_free(mv); - return NULL; -} +#undef BASE +#define BASE id -/* Read an isl_multi_val from "str". - */ -__isl_give isl_multi_val *isl_multi_val_read_from_str(isl_ctx *ctx, - const char *str) -{ - isl_multi_val *mv; - isl_stream *s = isl_stream_new_str(ctx, str); - if (!s) - return NULL; - mv = isl_stream_read_multi_val(s); - isl_stream_free(s); - return mv; -} +#include /* Read a multi-affine expression from "s". * If the multi-affine expression has a domain, then the tuple @@ -3591,7 +3682,8 @@ struct vars *v; isl_set *dom = NULL; isl_multi_pw_aff *tuple = NULL; - int dim, i, n; + int i; + isl_size dim, n; isl_space *space, *dom_space; isl_multi_aff *ma = NULL; @@ -3617,7 +3709,7 @@ if (isl_stream_eat_if_available(s, ISL_TOKEN_TO)) { isl_set *set; isl_space *space; - int has_expr; + isl_bool has_expr; has_expr = tuple_has_expr(tuple); if (has_expr < 0) @@ -3639,6 +3731,8 @@ n = isl_multi_pw_aff_dim(tuple, isl_dim_out); dim = isl_set_dim(dom, isl_dim_all); + if (n < 0 || dim < 0) + goto error; dom_space = isl_set_get_space(dom); space = isl_space_range(isl_multi_pw_aff_get_space(tuple)); space = isl_space_align_params(space, isl_space_copy(dom_space)); @@ -3695,6 +3789,9 @@ * The input format is similar to that of map, except that any conditions * on the domains should be specified inside the tuple since each * piecewise affine expression may have a different domain. + * However, additional, shared conditions can also be specified. + * This is especially useful for setting the explicit domain + * of a zero-dimensional isl_multi_pw_aff. * * Since we do not know in advance if the isl_multi_pw_aff lives * in a set or a map space, we first read the first tuple and check @@ -3736,6 +3833,9 @@ if (!tuple) goto error; } + + if (isl_stream_eat_if_available(s, ':')) + dom = read_formula(s, v, dom, 0); if (isl_stream_eat(s, '}')) goto error; @@ -3940,6 +4040,106 @@ isl_stream_push_token(s, tok); return is_tuple; +} + +/* Read the core of a body of an isl_multi_union_pw_aff from "s", + * i.e., everything except the parameter specification and + * without shared domain constraints. + * "v" contains a description of the identifiers parsed so far. + * The parameters, if any, are specified by "space". + * + * The body is of the form + * + * [{ [..] : ... ; [..] : ... }, { [..] : ... ; [..] : ... }] + * + * Read the tuple, collecting the individual isl_union_pw_aff + * elements in a list and construct the result from the tuple space and + * the list. + */ +static __isl_give isl_multi_union_pw_aff *read_multi_union_pw_aff_body_core( + __isl_keep isl_stream *s, struct vars *v, __isl_take isl_space *space) +{ + isl_union_pw_aff_list *list; + isl_multi_union_pw_aff *mupa; + + list = isl_union_pw_aff_list_alloc(s->ctx, 0); + space = read_tuple_space(s, v, space, 1, 0, + &read_union_pw_aff_el, &list); + mupa = isl_multi_union_pw_aff_from_union_pw_aff_list(space, list); + + return mupa; +} + +/* Read the body of an isl_union_set from "s", + * i.e., everything except the parameter specification. + * "v" contains a description of the identifiers parsed so far. + * The parameters, if any, are specified by "space". + * + * First read a generic disjunction of object bodies and then try and extract + * an isl_union_set from that. + */ +static __isl_give isl_union_set *read_union_set_body(__isl_keep isl_stream *s, + struct vars *v, __isl_take isl_space *space) +{ + struct isl_obj obj = { isl_obj_set, NULL }; + isl_map *map; + + map = isl_set_universe(space); + if (isl_stream_eat(s, '{') < 0) + goto error; + obj = obj_read_disjuncts(s, v, map); + if (isl_stream_eat(s, '}') < 0) + goto error; + isl_map_free(map); + + return extract_union_set(s->ctx, obj); +error: + obj.type->free(obj.v); + isl_map_free(map); + return NULL; +} + +/* Read the body of an isl_multi_union_pw_aff from "s", + * i.e., everything except the parameter specification. + * "v" contains a description of the identifiers parsed so far. + * The parameters, if any, are specified by "space". + * + * In particular, handle the special case with shared domain constraints. + * These are specified as + * + * ([...] : ...) + * + * and are especially useful for setting the explicit domain + * of a zero-dimensional isl_multi_union_pw_aff. + * The core isl_multi_union_pw_aff body ([...]) is read by + * read_multi_union_pw_aff_body_core. + */ +static __isl_give isl_multi_union_pw_aff *read_multi_union_pw_aff_body( + __isl_keep isl_stream *s, struct vars *v, __isl_take isl_space *space) +{ + isl_multi_union_pw_aff *mupa; + + if (!isl_stream_next_token_is(s, '(')) + return read_multi_union_pw_aff_body_core(s, v, space); + + if (isl_stream_eat(s, '(') < 0) + goto error; + mupa = read_multi_union_pw_aff_body_core(s, v, isl_space_copy(space)); + if (isl_stream_eat_if_available(s, ':')) { + isl_union_set *dom; + + dom = read_union_set_body(s, v, space); + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, dom); + } else { + isl_space_free(space); + } + if (isl_stream_eat(s, ')') < 0) + return isl_multi_union_pw_aff_free(mupa); + + return mupa; +error: + isl_space_free(space); + return NULL; } /* Read an isl_multi_union_pw_aff from "s". @@ -3951,21 +4151,29 @@ * or * * [..] -> [{ [..] : ... ; [..] : ... }, { [..] : ... ; [..] : ... }] + * + * Additionally, a shared domain may be specified as + * + * ([..] : ...) + * + * or + * + * [..] -> ([..] : ...) + * + * The first case is handled by the caller, the second case + * is handled by read_multi_union_pw_aff_body. * * We first check for the special case of an empty tuple "[]". * Then we check if there are any parameters. - * Finally, we read the tuple, collecting the individual isl_union_pw_aff - * elements in a list and construct the result from the tuple space and - * the list. + * Finally, read the tuple and construct the result. */ -__isl_give isl_multi_union_pw_aff *isl_stream_read_multi_union_pw_aff( +static __isl_give isl_multi_union_pw_aff *read_multi_union_pw_aff_core( __isl_keep isl_stream *s) { struct vars *v; isl_set *dom = NULL; isl_space *space; isl_multi_union_pw_aff *mupa = NULL; - isl_union_pw_aff_list *list; if (next_is_empty_tuple(s)) { if (isl_stream_eat(s, '[')) @@ -3988,10 +4196,7 @@ } space = isl_set_get_space(dom); isl_set_free(dom); - list = isl_union_pw_aff_list_alloc(s->ctx, 0); - space = read_tuple_space(s, v, space, 1, 0, - &read_union_pw_aff_el, &list); - mupa = isl_multi_union_pw_aff_from_union_pw_aff_list(space, list); + mupa = read_multi_union_pw_aff_body(s, v, space); vars_free(v); @@ -4001,6 +4206,40 @@ isl_set_free(dom); isl_multi_union_pw_aff_free(mupa); return NULL; +} + +/* Read an isl_multi_union_pw_aff from "s". + * + * In particular, handle the special case with shared domain constraints. + * These are specified as + * + * ([...] : ...) + * + * and are especially useful for setting the explicit domain + * of a zero-dimensional isl_multi_union_pw_aff. + * The core isl_multi_union_pw_aff ([...]) is read by + * read_multi_union_pw_aff_core. + */ +__isl_give isl_multi_union_pw_aff *isl_stream_read_multi_union_pw_aff( + __isl_keep isl_stream *s) +{ + isl_multi_union_pw_aff *mupa; + + if (!isl_stream_next_token_is(s, '(')) + return read_multi_union_pw_aff_core(s); + + if (isl_stream_eat(s, '(') < 0) + return NULL; + mupa = read_multi_union_pw_aff_core(s); + if (isl_stream_eat_if_available(s, ':')) { + isl_union_set *dom; + + dom = isl_stream_read_union_set(s); + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, dom); + } + if (isl_stream_eat(s, ')') < 0) + return isl_multi_union_pw_aff_free(mupa); + return mupa; } /* Read an isl_multi_union_pw_aff from "str". diff --git a/gcc/isl/isl_list_templ.c b/gcc/isl/isl_list_templ.c index b9b582e..7a3c424 100644 --- a/gcc/isl/isl_list_templ.c +++ a/gcc/isl/isl_list_templ.c @@ -17,14 +17,8 @@ #include #include -#define xCAT(A,B) A ## B -#define CAT(A,B) xCAT(A,B) -#undef EL -#define EL CAT(isl_,BASE) -#define xFN(TYPE,NAME) TYPE ## _ ## NAME -#define FN(TYPE,NAME) xFN(TYPE,NAME) -#define xLIST(EL) EL ## _list -#define LIST(EL) xLIST(EL) +#include + #define xS(TYPE,NAME) struct TYPE ## _ ## NAME #define S(TYPE,NAME) xS(TYPE,NAME) @@ -182,6 +176,15 @@ list->p[i] = list->p[i + n]; list->n -= n; return list; +} + +/* Remove all elements from "list". + */ +__isl_give LIST(EL) *FN(LIST(EL),clear)(__isl_take LIST(EL) *list) +{ + if (!list) + return NULL; + return FN(LIST(EL),drop)(list, 0, list->n); } /* Insert "el" at position "pos" in "list". @@ -244,23 +247,49 @@ free(list); return NULL; +} + +/* Return the number of elements in "list". + */ +isl_size FN(LIST(EL),size)(__isl_keep LIST(EL) *list) +{ + return list ? list->n : isl_size_error; } -int FN(FN(LIST(EL),n),BASE)(__isl_keep LIST(EL) *list) +/* This is an alternative name for the function above. + */ +isl_size FN(FN(LIST(EL),n),EL_BASE)(__isl_keep LIST(EL) *list) { - return list ? list->n : 0; + return FN(LIST(EL),size)(list); } -__isl_give EL *FN(FN(LIST(EL),get),BASE)(__isl_keep LIST(EL) *list, int index) +/* Return the element at position "index" in "list". + */ +static __isl_keep EL *FN(LIST(EL),peek)(__isl_keep LIST(EL) *list, int index) { if (FN(LIST(EL),check_index)(list, index) < 0) return NULL; - return FN(EL,copy)(list->p[index]); + return list->p[index]; +} + +/* Return a copy of the element at position "index" in "list". + */ +__isl_give EL *FN(LIST(EL),get_at)(__isl_keep LIST(EL) *list, int index) +{ + return FN(EL,copy)(FN(LIST(EL),peek)(list, index)); +} + +/* This is an alternative name for the function above. + */ +__isl_give EL *FN(FN(LIST(EL),get),EL_BASE)(__isl_keep LIST(EL) *list, + int index) +{ + return FN(LIST(EL),get_at)(list, index); } /* Replace the element at position "index" in "list" by "el". */ -__isl_give LIST(EL) *FN(FN(LIST(EL),set),BASE)(__isl_take LIST(EL) *list, +__isl_give LIST(EL) *FN(FN(LIST(EL),set),EL_BASE)(__isl_take LIST(EL) *list, int index, __isl_take EL *el) { if (!list || !el) @@ -293,7 +322,7 @@ * to isl_list_*_restore_*. * The only exception is that isl_list_*_free can be called instead. */ -static __isl_give EL *FN(FN(LIST(EL),take),BASE)(__isl_keep LIST(EL) *list, +static __isl_give EL *FN(FN(LIST(EL),take),EL_BASE)(__isl_keep LIST(EL) *list, int index) { EL *el; @@ -301,7 +330,7 @@ if (FN(LIST(EL),check_index)(list, index) < 0) return NULL; if (list->ref != 1) - return FN(FN(LIST(EL),get),BASE)(list, index); + return FN(FN(LIST(EL),get),EL_BASE)(list, index); el = list->p[index]; list->p[index] = NULL; return el; @@ -311,10 +340,38 @@ * where the position may be empty due to a previous call * to isl_list_*_take_*. */ -static __isl_give LIST(EL) *FN(FN(LIST(EL),restore),BASE)( +static __isl_give LIST(EL) *FN(FN(LIST(EL),restore),EL_BASE)( __isl_take LIST(EL) *list, int index, __isl_take EL *el) +{ + return FN(FN(LIST(EL),set),EL_BASE)(list, index, el); +} + +/* Swap the elements of "list" in positions "pos1" and "pos2". + */ +__isl_give LIST(EL) *FN(LIST(EL),swap)(__isl_take LIST(EL) *list, + unsigned pos1, unsigned pos2) +{ + EL *el1, *el2; + + if (pos1 == pos2) + return list; + el1 = FN(FN(LIST(EL),take),EL_BASE)(list, pos1); + el2 = FN(FN(LIST(EL),take),EL_BASE)(list, pos2); + list = FN(FN(LIST(EL),restore),EL_BASE)(list, pos1, el2); + list = FN(FN(LIST(EL),restore),EL_BASE)(list, pos2, el1); + return list; +} + +/* Reverse the elements of "list". + */ +__isl_give LIST(EL) *FN(LIST(EL),reverse)(__isl_take LIST(EL) *list) { - return FN(FN(LIST(EL),set),BASE)(list, index, el); + int i, n; + + n = FN(LIST(EL),size)(list); + for (i = 0; i < n - 1 - i; ++i) + list = FN(LIST(EL),swap)(list, i, n - 1 - i); + return list; } isl_stat FN(LIST(EL),foreach)(__isl_keep LIST(EL) *list, @@ -349,11 +406,11 @@ n = list->n; for (i = 0; i < n; ++i) { - EL *el = FN(FN(LIST(EL),take),BASE)(list, i); + EL *el = FN(FN(LIST(EL),take),EL_BASE)(list, i); if (!el) return FN(LIST(EL),free)(list); el = fn(el, user); - list = FN(FN(LIST(EL),restore),BASE)(list, i, el); + list = FN(FN(LIST(EL),restore),EL_BASE)(list, i, el); } return list; @@ -510,7 +567,7 @@ return n > 0 ? isl_stat_error : isl_stat_ok; } -__isl_give LIST(EL) *FN(FN(LIST(EL),from),BASE)(__isl_take EL *el) +__isl_give LIST(EL) *FN(FN(LIST(EL),from),EL_BASE)(__isl_take EL *el) { isl_ctx *ctx; LIST(EL) *list; @@ -577,7 +634,7 @@ return NULL; } -__isl_give isl_printer *CAT(isl_printer_print_,LIST(BASE))( +__isl_give isl_printer *CAT(isl_printer_print_,LIST(EL_BASE))( __isl_take isl_printer *p, __isl_keep LIST(EL) *list) { int i; @@ -588,7 +645,7 @@ for (i = 0; i < list->n; ++i) { if (i) p = isl_printer_print_str(p, ","); - p = CAT(isl_printer_print_,BASE)(p, list->p[i]); + p = CAT(isl_printer_print_,EL_BASE)(p, list->p[i]); } p = isl_printer_print_str(p, ")"); return p; @@ -596,17 +653,10 @@ isl_printer_free(p); return NULL; } - -void FN(LIST(EL),dump)(__isl_keep LIST(EL) *list) -{ - isl_printer *printer; - if (!list) - return; +#undef BASE +#define BASE LIST(EL_BASE) - printer = isl_printer_to_file(FN(LIST(EL),get_ctx)(list), stderr); - printer = CAT(isl_printer_print_,LIST(BASE))(printer, list); - printer = isl_printer_end_line(printer); - - isl_printer_free(printer); -} +#define PRINT_DUMP_DEFAULT 0 +#include "print_templ.c" +#undef PRINT_DUMP_DEFAULT diff --git a/gcc/isl/isl_local.c b/gcc/isl/isl_local.c index c8240b9..e409359 100644 --- a/gcc/isl/isl_local.c +++ a/gcc/isl/isl_local.c @@ -1,16 +1,97 @@ /* + * Copyright 2011 INRIA Saclay * Copyright 2014 Ecole Normale Superieure * * Use of this software is governed by the MIT license * - * Written by Sven Verdoolaege, - * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France + * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France, + * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod, + * 91893 Orsay, France + * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France */ +#include +#include #include +#include #include +#include -/* Given a matrix "div" representing local variables, +/* Return the isl_ctx to which "local" belongs. + */ +isl_ctx *isl_local_get_ctx(__isl_keep isl_local *local) +{ + if (!local) + return NULL; + + return isl_mat_get_ctx(local); +} + +/* Create an isl_local object from a matrix describing + * integer divisions. + * + * An isl_local object is current defined as exactly such a matrix, + * so simply return the input. + */ +__isl_give isl_local *isl_local_alloc_from_mat(__isl_take isl_mat *mat) +{ + return mat; +} + +/* Free "local" and return NULL. + */ +__isl_null isl_local *isl_local_free(__isl_take isl_local *local) +{ + isl_mat_free(local); + return NULL; +} + +/* Return the number of local variables (isl_dim_div), + * the number of other variables (isl_dim_set) or + * the total number of variables (isl_dim_all) in "local". + * + * Other types do not have any meaning for an isl_local object. + */ +isl_size isl_local_dim(__isl_keep isl_local *local, enum isl_dim_type type) +{ + isl_mat *mat = local; + + if (!local) + return isl_size_error; + if (type == isl_dim_div) + return isl_mat_rows(mat); + if (type == isl_dim_all) { + isl_size cols = isl_mat_cols(mat); + if (cols < 0) + return isl_size_error; + return cols - 2; + } + if (type == isl_dim_set) { + isl_size total, n_div; + + total = isl_local_dim(local, isl_dim_all); + n_div = isl_local_dim(local, isl_dim_div); + if (total < 0 || n_div < 0) + return isl_size_error; + return total - n_div; + } + isl_die(isl_local_get_ctx(local), isl_error_unsupported, + "unsupported dimension type", return isl_size_error); +} + +#undef TYPE +#define TYPE isl_local +static +#include "check_type_range_templ.c" + +/* Check that "pos" is a valid position for a variable in "local". + */ +static isl_stat isl_local_check_pos(__isl_keep isl_local *local, int pos) +{ + return isl_local_check_range(local, isl_dim_div, pos, 1); +} + +/* Given local variables "local", * is the variable at position "pos" marked as not having * an explicit representation? * Note that even if this variable is not marked in this way and therefore @@ -18,100 +99,220 @@ * depend (indirectly) on other local variables that do not * have an explicit representation. */ -isl_bool isl_local_div_is_marked_unknown(__isl_keep isl_mat *div, int pos) +isl_bool isl_local_div_is_marked_unknown(__isl_keep isl_local *local, int pos) { - if (!div) + isl_mat *mat = local; + + if (isl_local_check_pos(local, pos) < 0) return isl_bool_error; - if (pos < 0 || pos >= div->n_row) - isl_die(isl_mat_get_ctx(div), isl_error_invalid, - "position out of bounds", return isl_bool_error); - return isl_int_is_zero(div->row[pos][0]); + return isl_bool_ok(isl_int_is_zero(mat->row[pos][0])); } -/* Given a matrix "div" representing local variables, +/* Given local variables "local", * does the variable at position "pos" have a complete explicit representation? * Having a complete explicit representation requires not only * an explicit representation, but also that all local variables * that appear in this explicit representation in turn have * a complete explicit representation. */ -isl_bool isl_local_div_is_known(__isl_keep isl_mat *div, int pos) +isl_bool isl_local_div_is_known(__isl_keep isl_local *local, int pos) { isl_bool marked; - int i, n, off; + int i, off; + isl_size n, cols; + isl_mat *mat = local; - if (!div) + if (isl_local_check_pos(local, pos) < 0) return isl_bool_error; - if (pos < 0 || pos >= div->n_row) - isl_die(isl_mat_get_ctx(div), isl_error_invalid, - "position out of bounds", return isl_bool_error); - - marked = isl_local_div_is_marked_unknown(div, pos); + + marked = isl_local_div_is_marked_unknown(local, pos); if (marked < 0 || marked) return isl_bool_not(marked); - n = isl_mat_rows(div); - off = isl_mat_cols(div) - n; + n = isl_local_dim(local, isl_dim_div); + cols = isl_mat_cols(mat); + if (n < 0 || cols < 0) + return isl_bool_error; + off = cols - n; for (i = n - 1; i >= 0; --i) { isl_bool known; - if (isl_int_is_zero(div->row[pos][off + i])) + if (isl_int_is_zero(mat->row[pos][off + i])) continue; - known = isl_local_div_is_known(div, i); + known = isl_local_div_is_known(local, i); if (known < 0 || !known) return known; + } + + return isl_bool_true; +} + +/* Does "local" have an explicit representation for all local variables? + */ +isl_bool isl_local_divs_known(__isl_keep isl_local *local) +{ + int i; + isl_size n; + + n = isl_local_dim(local, isl_dim_div); + if (n < 0) + return isl_bool_error; + + for (i = 0; i < n; ++i) { + isl_bool unknown = isl_local_div_is_marked_unknown(local, i); + if (unknown < 0 || unknown) + return isl_bool_not(unknown); } return isl_bool_true; } -/* Compare two matrices representing local variables, defined over +/* Compare two sets of local variables, defined over * the same space. * - * Return -1 if "div1" is "smaller" than "div2", 1 if "div1" is "greater" - * than "div2" and 0 if they are equal. + * Return -1 if "local1" is "smaller" than "local2", 1 if "local1" is "greater" + * than "local2" and 0 if they are equal. * * The order is fairly arbitrary. We do "prefer" divs that only involve * earlier dimensions in the sense that we consider matrices where * the first differing div involves earlier dimensions to be smaller. */ -int isl_local_cmp(__isl_keep isl_mat *div1, __isl_keep isl_mat *div2) +int isl_local_cmp(__isl_keep isl_local *local1, __isl_keep isl_local *local2) { int i; int cmp; isl_bool unknown1, unknown2; int last1, last2; - int n_col; + isl_size n_col; + isl_mat *mat1 = local1; + isl_mat *mat2 = local2; - if (div1 == div2) + if (local1 == local2) return 0; - if (!div1) + if (!local1) return -1; - if (!div2) + if (!local2) return 1; - if (div1->n_row != div2->n_row) - return div1->n_row - div2->n_row; + if (mat1->n_row != mat2->n_row) + return mat1->n_row - mat2->n_row; - n_col = isl_mat_cols(div1); - for (i = 0; i < div1->n_row; ++i) { - unknown1 = isl_local_div_is_marked_unknown(div1, i); - unknown2 = isl_local_div_is_marked_unknown(div2, i); + n_col = isl_mat_cols(mat1); + if (n_col < 0) + return -1; + for (i = 0; i < mat1->n_row; ++i) { + unknown1 = isl_local_div_is_marked_unknown(local1, i); + unknown2 = isl_local_div_is_marked_unknown(local2, i); if (unknown1 && unknown2) continue; if (unknown1) return 1; if (unknown2) return -1; - last1 = isl_seq_last_non_zero(div1->row[i] + 1, n_col - 1); - last2 = isl_seq_last_non_zero(div2->row[i] + 1, n_col - 1); + last1 = isl_seq_last_non_zero(mat1->row[i] + 1, n_col - 1); + last2 = isl_seq_last_non_zero(mat2->row[i] + 1, n_col - 1); if (last1 != last2) return last1 - last2; - cmp = isl_seq_cmp(div1->row[i], div2->row[i], n_col); + cmp = isl_seq_cmp(mat1->row[i], mat2->row[i], n_col); if (cmp != 0) return cmp; } return 0; +} + +/* Reorder the columns of the given local variables according to the + * given reordering. + * The order of the local variables themselves is assumed not to change. + */ +__isl_give isl_local *isl_local_reorder(__isl_take isl_local *local, + __isl_take isl_reordering *r) +{ + isl_mat *div = local; + int i, j; + isl_size dim; + isl_space *space; + isl_mat *mat; + int extra; + + if (!local || !r) + goto error; + + space = isl_reordering_peek_space(r); + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + goto error; + extra = dim + div->n_row - r->len; + mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra); + if (!mat) + goto error; + + for (i = 0; i < div->n_row; ++i) { + isl_seq_cpy(mat->row[i], div->row[i], 2); + isl_seq_clr(mat->row[i] + 2, mat->n_col - 2); + for (j = 0; j < r->len; ++j) + isl_int_set(mat->row[i][2 + r->pos[j]], + div->row[i][2 + j]); + } + + isl_reordering_free(r); + isl_local_free(local); + return isl_local_alloc_from_mat(mat); +error: + isl_reordering_free(r); + isl_local_free(local); + return NULL; +} + +/* Extend a vector "v" representing an integer point + * in the domain space of "local" + * to one that also includes values for the local variables. + * All local variables are required to have an explicit representation. + * If there are no local variables, then the point is not required + * to be integral. + */ +__isl_give isl_vec *isl_local_extend_point_vec(__isl_keep isl_local *local, + __isl_take isl_vec *v) +{ + isl_size dim, n_div, size; + isl_bool known; + isl_mat *mat = local; + + if (!local || !v) + return isl_vec_free(v); + known = isl_local_divs_known(local); + if (known < 0) + return isl_vec_free(v); + if (!known) + isl_die(isl_local_get_ctx(local), isl_error_invalid, + "unknown local variables", return isl_vec_free(v)); + dim = isl_local_dim(local, isl_dim_set); + n_div = isl_local_dim(local, isl_dim_div); + size = isl_vec_size(v); + if (dim < 0 || n_div < 0 || size < 0) + return isl_vec_free(v); + if (size != 1 + dim) + isl_die(isl_local_get_ctx(local), isl_error_invalid, + "incorrect size", return isl_vec_free(v)); + if (n_div == 0) + return v; + if (!isl_int_is_one(v->el[0])) + isl_die(isl_local_get_ctx(local), isl_error_invalid, + "expecting integer point", return isl_vec_free(v)); + { + int i; + v = isl_vec_add_els(v, n_div); + if (!v) + return NULL; + + for (i = 0; i < n_div; ++i) { + isl_seq_inner_product(mat->row[i] + 1, v->el, + 1 + dim + i, &v->el[1+dim+i]); + isl_int_fdiv_q(v->el[1+dim+i], v->el[1+dim+i], + mat->row[i][0]); + } + } + + return v; } diff --git a/gcc/isl/isl_local.h b/gcc/isl/isl_local.h index 0970509..a52622e 100644 --- a/gcc/isl/isl_local.h +++ a/gcc/isl/isl_local.h @@ -1,10 +1,23 @@ #ifndef ISL_LOCAL_H #define ISL_LOCAL_H #include +#include -isl_bool isl_local_div_is_marked_unknown(__isl_keep isl_mat *div, int pos); -isl_bool isl_local_div_is_known(__isl_keep isl_mat *div, int pos); -int isl_local_cmp(__isl_keep isl_mat *div1, __isl_keep isl_mat *div2); +typedef isl_mat isl_local; + +__isl_null isl_local *isl_local_free(__isl_take isl_local *local); + +isl_bool isl_local_div_is_marked_unknown(__isl_keep isl_local *local, int pos); +isl_bool isl_local_div_is_known(__isl_keep isl_local *local, int pos); +isl_bool isl_local_divs_known(__isl_keep isl_local *local); + +int isl_local_cmp(__isl_keep isl_local *local1, __isl_keep isl_local *local2); + +__isl_give isl_local *isl_local_reorder(__isl_take isl_local *local, + __isl_take isl_reordering *r); + +__isl_give isl_vec *isl_local_extend_point_vec(__isl_keep isl_local *local, + __isl_take isl_vec *v); #endif diff --git a/gcc/isl/isl_local_space.c b/gcc/isl/isl_local_space.c index bc5861f..5248d63 100644 --- a/gcc/isl/isl_local_space.c +++ a/gcc/isl/isl_local_space.c @@ -11,12 +11,14 @@ */ #include +#include #include #include #include #include #include #include +#include #include #include @@ -43,47 +45,49 @@ return hash; } -__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_space *dim, - __isl_take isl_mat *div) +__isl_give isl_local_space *isl_local_space_alloc_div( + __isl_take isl_space *space, __isl_take isl_mat *div) { isl_ctx *ctx; isl_local_space *ls = NULL; - if (!dim || !div) + if (!space || !div) goto error; - ctx = isl_space_get_ctx(dim); + ctx = isl_space_get_ctx(space); ls = isl_calloc_type(ctx, struct isl_local_space); if (!ls) goto error; ls->ref = 1; - ls->dim = dim; + ls->dim = space; ls->div = div; return ls; error: isl_mat_free(div); - isl_space_free(dim); + isl_space_free(space); isl_local_space_free(ls); return NULL; } -__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *dim, +__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *space, unsigned n_div) { isl_ctx *ctx; isl_mat *div; - unsigned total; + isl_size total; - if (!dim) + if (!space) return NULL; - total = isl_space_dim(dim, isl_dim_all); + total = isl_space_dim(space, isl_dim_all); + if (total < 0) + return isl_local_space_from_space(isl_space_free(space)); - ctx = isl_space_get_ctx(dim); + ctx = isl_space_get_ctx(space); div = isl_mat_alloc(ctx, n_div, 1 + 1 + total + n_div); - return isl_local_space_alloc_div(dim, div); + return isl_local_space_alloc_div(space, div); } __isl_give isl_local_space *isl_local_space_from_space(__isl_take isl_space *dim) @@ -163,6 +167,30 @@ return isl_bool_error; return isl_space_is_equal(ls1->dim, ls2->dim); +} + +/* Is the space of "ls" equal to "space"? + */ +isl_bool isl_local_space_has_space(__isl_keep isl_local_space *ls, + __isl_keep isl_space *space) +{ + return isl_space_is_equal(isl_local_space_peek_space(ls), space); +} + +/* Check that the space of "ls" is equal to "space". + */ +static isl_stat isl_local_space_check_has_space(__isl_keep isl_local_space *ls, + __isl_keep isl_space *space) +{ + isl_bool ok; + + ok = isl_local_space_has_space(ls, space); + if (ok < 0) + return isl_stat_error; + if (!ok) + isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, + "spaces don't match", return isl_stat_error); + return isl_stat_ok; } /* Return true if the two local spaces are identical, with identical @@ -209,33 +237,42 @@ return isl_local_cmp(ls1->div, ls2->div); } -int isl_local_space_dim(__isl_keep isl_local_space *ls, +isl_size isl_local_space_dim(__isl_keep isl_local_space *ls, enum isl_dim_type type) { if (!ls) - return 0; + return isl_size_error; if (type == isl_dim_div) return ls->div->n_row; - if (type == isl_dim_all) - return isl_space_dim(ls->dim, isl_dim_all) + ls->div->n_row; + if (type == isl_dim_all) { + isl_size dim = isl_space_dim(ls->dim, isl_dim_all); + if (dim < 0) + return isl_size_error; + return dim + ls->div->n_row; + } return isl_space_dim(ls->dim, type); } + +#undef TYPE +#define TYPE isl_local_space +#include "check_type_range_templ.c" unsigned isl_local_space_offset(__isl_keep isl_local_space *ls, enum isl_dim_type type) { - isl_space *dim; + isl_space *space; if (!ls) return 0; - dim = ls->dim; + space = ls->dim; switch (type) { case isl_dim_cst: return 0; case isl_dim_param: return 1; - case isl_dim_in: return 1 + dim->nparam; - case isl_dim_out: return 1 + dim->nparam + dim->n_in; - case isl_dim_div: return 1 + dim->nparam + dim->n_in + dim->n_out; + case isl_dim_in: return 1 + space->nparam; + case isl_dim_out: return 1 + space->nparam + space->n_in; + case isl_dim_div: + return 1 + space->nparam + space->n_in + space->n_out; default: return 0; } } @@ -304,12 +341,15 @@ static __isl_give isl_aff *drop_unknown_divs_and_extract_div( __isl_keep isl_local_space *ls, int pos) { - int i, n; + int i; + isl_size n; isl_bool unknown; isl_aff *aff; - ls = isl_local_space_copy(ls); n = isl_local_space_dim(ls, isl_dim_div); + if (n < 0) + return NULL; + ls = isl_local_space_copy(ls); for (i = n - 1; i >= 0; --i) { unknown = isl_local_space_div_is_marked_unknown(ls, i); if (unknown < 0) @@ -363,12 +403,19 @@ return drop_unknown_divs_and_extract_div(ls, pos); } -__isl_give isl_space *isl_local_space_get_space(__isl_keep isl_local_space *ls) +/* Return the space of "ls". + */ +__isl_keep isl_space *isl_local_space_peek_space(__isl_keep isl_local_space *ls) { if (!ls) return NULL; + + return ls->dim; +} - return isl_space_copy(ls->dim); +__isl_give isl_space *isl_local_space_get_space(__isl_keep isl_local_space *ls) +{ + return isl_space_copy(isl_local_space_peek_space(ls)); } /* Return the space of "ls". @@ -420,6 +467,13 @@ isl_local_space_free(ls); isl_space_free(space); return NULL; +} + +/* Return the local variables of "ls". + */ +__isl_keep isl_local *isl_local_space_peek_local(__isl_keep isl_local_space *ls) +{ + return ls ? ls->div : NULL; } /* Replace the identifier of the tuple of type "type" by "id". @@ -499,42 +553,6 @@ error: isl_local_space_free(ls); isl_space_free(dim); - return NULL; -} - -/* Reorder the columns of the given div definitions according to the - * given reordering. - * The order of the divs themselves is assumed not to change. - */ -static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div, - __isl_take isl_reordering *r) -{ - int i, j; - isl_mat *mat; - int extra; - - if (!div || !r) - goto error; - - extra = isl_space_dim(r->dim, isl_dim_all) + div->n_row - r->len; - mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra); - if (!mat) - goto error; - - for (i = 0; i < div->n_row; ++i) { - isl_seq_cpy(mat->row[i], div->row[i], 2); - isl_seq_clr(mat->row[i] + 2, mat->n_col - 2); - for (j = 0; j < r->len; ++j) - isl_int_set(mat->row[i][2 + r->pos[j]], - div->row[i][2 + j]); - } - - isl_reordering_free(r); - isl_mat_free(div); - return mat; -error: - isl_reordering_free(r); - isl_mat_free(div); return NULL; } @@ -549,11 +567,11 @@ if (!ls || !r) goto error; - ls->div = reorder_divs(ls->div, isl_reordering_copy(r)); + ls->div = isl_local_reorder(ls->div, isl_reordering_copy(r)); if (!ls->div) goto error; - ls = isl_local_space_reset_space(ls, isl_space_copy(r->dim)); + ls = isl_local_space_reset_space(ls, isl_reordering_get_space(r)); isl_reordering_free(r); return ls; @@ -681,7 +699,7 @@ __isl_take isl_basic_map *bmap) { int i, j; - unsigned total; + isl_size total; bmap = isl_basic_map_order_divs(bmap); if (!bmap) @@ -689,12 +707,16 @@ if (bmap->n_div <= 1) return bmap; - total = 2 + isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); for (i = 1; i < bmap->n_div; ++i) { for (j = i - 1; j >= 0; --j) { - if (bmap_cmp_row(bmap, j, j + 1, total) <= 0) + if (bmap_cmp_row(bmap, j, j + 1, 2 + total) <= 0) break; - isl_basic_map_swap_div(bmap, j, j + 1); + bmap = isl_basic_map_swap_div(bmap, j, j + 1); + if (!bmap) + return NULL; } } @@ -876,25 +898,20 @@ */ isl_bool isl_local_space_divs_known(__isl_keep isl_local_space *ls) { - int i; - if (!ls) return isl_bool_error; - - for (i = 0; i < ls->div->n_row; ++i) { - isl_bool unknown = isl_local_space_div_is_marked_unknown(ls, i); - if (unknown < 0 || unknown) - return isl_bool_not(unknown); - } - - return isl_bool_true; + return isl_local_divs_known(ls->div); } __isl_give isl_local_space *isl_local_space_domain( __isl_take isl_local_space *ls) { - ls = isl_local_space_drop_dims(ls, isl_dim_out, - 0, isl_local_space_dim(ls, isl_dim_out)); + isl_size n_out; + + n_out = isl_local_space_dim(ls, isl_dim_out); + if (n_out < 0) + return isl_local_space_free(ls); + ls = isl_local_space_drop_dims(ls, isl_dim_out, 0, n_out); ls = isl_local_space_cow(ls); if (!ls) return NULL; @@ -907,8 +924,12 @@ __isl_give isl_local_space *isl_local_space_range( __isl_take isl_local_space *ls) { - ls = isl_local_space_drop_dims(ls, isl_dim_in, - 0, isl_local_space_dim(ls, isl_dim_in)); + isl_size n_in; + + n_in = isl_local_space_dim(ls, isl_dim_in); + if (n_in < 0) + return isl_local_space_free(ls); + ls = isl_local_space_drop_dims(ls, isl_dim_in, 0, n_in); ls = isl_local_space_cow(ls); if (!ls) return NULL; @@ -937,17 +958,86 @@ __isl_give isl_local_space *isl_local_space_add_dims( __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned n) { - int pos; + isl_size pos; - if (!ls) - return NULL; pos = isl_local_space_dim(ls, type); + if (pos < 0) + return isl_local_space_free(ls); return isl_local_space_insert_dims(ls, type, pos, n); +} + +/* Lift the basic set "bset", living in the space of "ls" + * to live in a space with extra coordinates corresponding + * to the local variables of "ls". + */ +__isl_give isl_basic_set *isl_local_space_lift_basic_set( + __isl_take isl_local_space *ls, __isl_take isl_basic_set *bset) +{ + isl_size n_local; + isl_space *space; + isl_basic_set *ls_bset; + + n_local = isl_local_space_dim(ls, isl_dim_div); + space = isl_basic_set_peek_space(bset); + if (n_local < 0 || + isl_local_space_check_has_space(ls, space) < 0) + goto error; + + if (n_local == 0) { + isl_local_space_free(ls); + return bset; + } + + bset = isl_basic_set_add_dims(bset, isl_dim_set, n_local); + ls_bset = isl_basic_set_from_local_space(ls); + ls_bset = isl_basic_set_lift(ls_bset); + ls_bset = isl_basic_set_flatten(ls_bset); + bset = isl_basic_set_intersect(bset, ls_bset); + + return bset; +error: + isl_local_space_free(ls); + isl_basic_set_free(bset); + return NULL; +} + +/* Lift the set "set", living in the space of "ls" + * to live in a space with extra coordinates corresponding + * to the local variables of "ls". + */ +__isl_give isl_set *isl_local_space_lift_set(__isl_take isl_local_space *ls, + __isl_take isl_set *set) +{ + isl_size n_local; + isl_basic_set *bset; + + n_local = isl_local_space_dim(ls, isl_dim_div); + if (n_local < 0 || + isl_local_space_check_has_space(ls, isl_set_peek_space(set)) < 0) + goto error; + + if (n_local == 0) { + isl_local_space_free(ls); + return set; + } + + set = isl_set_add_dims(set, isl_dim_set, n_local); + bset = isl_basic_set_from_local_space(ls); + bset = isl_basic_set_lift(bset); + bset = isl_basic_set_flatten(bset); + set = isl_set_intersect(set, isl_set_from_basic_set(bset)); + + return set; +error: + isl_local_space_free(ls); + isl_set_free(set); + return NULL; } /* Remove common factor of non-constant terms and denominator. */ -static void normalize_div(__isl_keep isl_local_space *ls, int div) +static __isl_give isl_local_space *normalize_div( + __isl_take isl_local_space *ls, int div) { isl_ctx *ctx = ls->div->ctx; unsigned total = ls->div->n_col - 2; @@ -956,7 +1046,7 @@ isl_int_gcd(ctx->normalize_gcd, ctx->normalize_gcd, ls->div->row[div][0]); if (isl_int_is_one(ctx->normalize_gcd)) - return; + return ls; isl_seq_scale_down(ls->div->row[div] + 2, ls->div->row[div] + 2, ctx->normalize_gcd, total); @@ -964,6 +1054,8 @@ ctx->normalize_gcd); isl_int_fdiv_q(ls->div->row[div][1], ls->div->row[div][1], ctx->normalize_gcd); + + return ls; } /* Exploit the equalities in "eq" to simplify the expressions of @@ -975,14 +1067,17 @@ __isl_take isl_local_space *ls, __isl_take isl_basic_set *eq) { int i, j, k; - unsigned total; + isl_size total, dim; unsigned n_div; if (!ls || !eq) goto error; total = isl_space_dim(eq->dim, isl_dim_all); - if (isl_local_space_dim(ls, isl_dim_all) != total) + dim = isl_local_space_dim(ls, isl_dim_all); + if (dim < 0 || total < 0) + goto error; + if (dim != total) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, "spaces don't match", goto error); total++; @@ -1003,7 +1098,9 @@ goto error; isl_seq_elim(ls->div->row[k] + 1, eq->eq[i], j, total, &ls->div->row[k][0]); - normalize_div(ls, k); + ls = normalize_div(ls, k); + if (!ls) + goto error; } } @@ -1060,7 +1157,9 @@ continue; isl_seq_substitute(ls->div->row[i], pos, subs, ls->div->n_col, subs_len, v); - normalize_div(ls, i); + ls = normalize_div(ls, i); + if (!ls) + break; } isl_int_clear(v); @@ -1086,6 +1185,8 @@ __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned pos, __isl_keep isl_aff *subs) { + isl_size n_div; + ls = isl_local_space_cow(ls); if (!ls || !subs) return isl_local_space_free(ls); @@ -1093,7 +1194,10 @@ if (!isl_space_is_equal(ls->dim, subs->ls->dim)) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, "spaces don't match", return isl_local_space_free(ls)); - if (isl_local_space_dim(subs->ls, isl_dim_div) != 0) + n_div = isl_local_space_dim(subs->ls, isl_dim_div); + if (n_div < 0) + return isl_local_space_free(ls); + if (n_div != 0) isl_die(isl_local_space_get_ctx(ls), isl_error_unsupported, "cannot handle divs yet", return isl_local_space_free(ls)); @@ -1114,17 +1218,13 @@ __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n) { - isl_ctx *ctx; - if (!ls) return NULL; if (n == 0 && !isl_local_space_is_named_or_nested(ls, type)) return ls; - ctx = isl_local_space_get_ctx(ls); - if (first + n > isl_local_space_dim(ls, type)) - isl_die(ctx, isl_error_invalid, "range out of bounds", - return isl_local_space_free(ls)); + if (isl_local_space_check_range(ls, type, first, n) < 0) + return isl_local_space_free(ls); ls = isl_local_space_cow(ls); if (!ls) @@ -1150,17 +1250,13 @@ __isl_take isl_local_space *ls, enum isl_dim_type type, unsigned first, unsigned n) { - isl_ctx *ctx; - if (!ls) return NULL; if (n == 0 && !isl_local_space_is_named_or_nested(ls, type)) return ls; - ctx = isl_local_space_get_ctx(ls); - if (first > isl_local_space_dim(ls, type)) - isl_die(ctx, isl_error_invalid, "position out of bounds", - return isl_local_space_free(ls)); + if (isl_local_space_check_range(ls, type, first, 0) < 0) + return isl_local_space_free(ls); ls = isl_local_space_cow(ls); if (!ls) @@ -1180,6 +1276,49 @@ return isl_local_space_free(ls); return ls; +} + +/* Does the linear part of "constraint" correspond to + * integer division "div" in "ls"? + * + * That is, given div = floor((c + f)/m), is the constraint of the form + * + * f - m d + c' >= 0 [sign = 1] + * or + * -f + m d + c'' >= 0 [sign = -1] + * ? + * If so, set *sign to the corresponding value. + */ +static isl_bool is_linear_div_constraint(__isl_keep isl_local_space *ls, + isl_int *constraint, unsigned div, int *sign) +{ + isl_bool unknown; + unsigned pos; + + unknown = isl_local_space_div_is_marked_unknown(ls, div); + if (unknown < 0) + return isl_bool_error; + if (unknown) + return isl_bool_false; + + pos = isl_local_space_offset(ls, isl_dim_div) + div; + + if (isl_int_eq(constraint[pos], ls->div->row[div][0])) { + *sign = -1; + if (!isl_seq_is_neg(constraint + 1, + ls->div->row[div] + 2, pos - 1)) + return isl_bool_false; + } else if (isl_int_abs_eq(constraint[pos], ls->div->row[div][0])) { + *sign = 1; + if (!isl_seq_eq(constraint + 1, ls->div->row[div] + 2, pos - 1)) + return isl_bool_false; + } else { + return isl_bool_false; + } + if (isl_seq_first_non_zero(constraint + pos + 1, + ls->div->n_row - div - 1) != -1) + return isl_bool_false; + return isl_bool_true; } /* Check if the constraints pointed to by "constraint" is a div @@ -1190,44 +1329,65 @@ * f - m d >= 0 * or * -(f-(m-1)) + m d >= 0 + * + * First check if the linear part is of the right form and + * then check the constant term. */ isl_bool isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls, isl_int *constraint, unsigned div) { - unsigned pos; - - if (!ls) - return isl_bool_error; + int sign; + isl_bool linear; - if (isl_int_is_zero(ls->div->row[div][0])) - return isl_bool_false; - - pos = isl_local_space_offset(ls, isl_dim_div) + div; + linear = is_linear_div_constraint(ls, constraint, div, &sign); + if (linear < 0 || !linear) + return linear; - if (isl_int_eq(constraint[pos], ls->div->row[div][0])) { + if (sign < 0) { int neg; isl_int_sub(ls->div->row[div][1], ls->div->row[div][1], ls->div->row[div][0]); isl_int_add_ui(ls->div->row[div][1], ls->div->row[div][1], 1); - neg = isl_seq_is_neg(constraint, ls->div->row[div]+1, pos); + neg = isl_seq_is_neg(constraint, ls->div->row[div] + 1, 1); isl_int_sub_ui(ls->div->row[div][1], ls->div->row[div][1], 1); isl_int_add(ls->div->row[div][1], ls->div->row[div][1], ls->div->row[div][0]); if (!neg) - return isl_bool_false; - if (isl_seq_first_non_zero(constraint+pos+1, - ls->div->n_row-div-1) != -1) - return isl_bool_false; - } else if (isl_int_abs_eq(constraint[pos], ls->div->row[div][0])) { - if (!isl_seq_eq(constraint, ls->div->row[div]+1, pos)) return isl_bool_false; - if (isl_seq_first_non_zero(constraint+pos+1, - ls->div->n_row-div-1) != -1) + } else { + if (!isl_int_eq(constraint[0], ls->div->row[div][1])) return isl_bool_false; - } else - return isl_bool_false; + } return isl_bool_true; +} + +/* Is the constraint pointed to by "constraint" one + * of an equality that corresponds to integer division "div" in "ls"? + * + * That is, given an integer division of the form + * + * a = floor((f + c)/m) + * + * is the equality of the form + * + * -f + m d + c' = 0 + * ? + * Note that the constant term is not checked explicitly, but given + * that this is a valid equality constraint, the constant c' necessarily + * has a value close to -c. + */ +isl_bool isl_local_space_is_div_equality(__isl_keep isl_local_space *ls, + isl_int *constraint, unsigned div) +{ + int sign; + isl_bool linear; + + linear = is_linear_div_constraint(ls, constraint, div, &sign); + if (linear < 0 || !linear) + return linear; + + return isl_bool_ok(sign < 0); } /* @@ -1239,11 +1399,13 @@ int i, j; isl_ctx *ctx; int *active = NULL; - unsigned total; + isl_size total; unsigned offset; ctx = isl_local_space_get_ctx(ls); total = isl_local_space_dim(ls, isl_dim_all); + if (total < 0) + return NULL; active = isl_calloc_array(ctx, int, total); if (total && !active) return NULL; @@ -1333,7 +1495,7 @@ int i; isl_space *space; isl_local_space *res = NULL; - int n_div_ls, n_div_ma; + isl_size n_div_ls, n_div_ma; isl_int f, c1, c2, g; ma = isl_multi_aff_align_divs(ma); @@ -1344,7 +1506,9 @@ "spaces don't match", goto error); n_div_ls = isl_local_space_dim(ls, isl_dim_div); - n_div_ma = ma->n ? isl_aff_dim(ma->p[0], isl_dim_div) : 0; + n_div_ma = ma->n ? isl_aff_dim(ma->u.p[0], isl_dim_div) : 0; + if (n_div_ls < 0 || n_div_ma < 0) + goto error; space = isl_space_domain(isl_multi_aff_get_space(ma)); res = isl_local_space_alloc(space, n_div_ma + n_div_ls); @@ -1353,7 +1517,7 @@ if (n_div_ma) { isl_mat_free(res->div); - res->div = isl_mat_copy(ma->p[0]->ls->div); + res->div = isl_mat_copy(ma->u.p[0]->ls->div); res->div = isl_mat_add_zero_cols(res->div, n_div_ls); res->div = isl_mat_add_rows(res->div, n_div_ls); if (!res->div) @@ -1370,9 +1534,13 @@ isl_int_set_si(res->div->row[n_div_ma + i][0], 0); continue; } - isl_seq_preimage(res->div->row[n_div_ma + i], ls->div->row[i], - ma, 0, 0, n_div_ma, n_div_ls, f, c1, c2, g, 1); - normalize_div(res, n_div_ma + i); + if (isl_seq_preimage(res->div->row[n_div_ma + i], + ls->div->row[i], + ma, 0, 0, n_div_ma, n_div_ls, f, c1, c2, g, 1) < 0) + res = isl_local_space_free(res); + res = normalize_div(res, n_div_ma + i); + if (!res) + break; } isl_int_clear(f); @@ -1411,13 +1579,10 @@ !isl_local_space_is_named_or_nested(ls, dst_type)) return ls; - if (src_pos + n > isl_local_space_dim(ls, src_type)) - isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, - "range out of bounds", return isl_local_space_free(ls)); - if (dst_pos > isl_local_space_dim(ls, dst_type)) - isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, - "position out of bounds", - return isl_local_space_free(ls)); + if (isl_local_space_check_range(ls, src_type, src_pos, n) < 0) + return isl_local_space_free(ls); + if (isl_local_space_check_range(ls, dst_type, dst_pos, 0) < 0) + return isl_local_space_free(ls); if (src_type == isl_dim_div) isl_die(isl_local_space_get_ctx(ls), isl_error_invalid, "cannot move divs", return isl_local_space_free(ls)); @@ -1513,4 +1678,42 @@ return isl_local_space_free(ls); return ls; +} + +/* Lift the point "pnt", living in the space of "ls" + * to live in a space with extra coordinates corresponding + * to the local variables of "ls". + */ +__isl_give isl_point *isl_local_space_lift_point(__isl_take isl_local_space *ls, + __isl_take isl_point *pnt) +{ + isl_size n_local; + isl_space *space; + isl_local *local; + isl_vec *vec; + + if (isl_local_space_check_has_space(ls, isl_point_peek_space(pnt)) < 0) + goto error; + + local = isl_local_space_peek_local(ls); + n_local = isl_local_space_dim(ls, isl_dim_div); + if (n_local < 0) + goto error; + + space = isl_point_take_space(pnt); + vec = isl_point_take_vec(pnt); + + space = isl_space_lift(space, n_local); + vec = isl_local_extend_point_vec(local, vec); + + pnt = isl_point_restore_vec(pnt, vec); + pnt = isl_point_restore_space(pnt, space); + + isl_local_space_free(ls); + + return pnt; +error: + isl_local_space_free(ls); + isl_point_free(pnt); + return NULL; } diff --git a/gcc/isl/isl_local_space_private.h b/gcc/isl/isl_local_space_private.h index a1bdb1b..bcca650 100644 --- a/gcc/isl/isl_local_space_private.h +++ a/gcc/isl/isl_local_space_private.h @@ -12,12 +12,18 @@ isl_mat *div; }; +isl_stat isl_local_space_check_range(__isl_keep isl_local_space *ls, + enum isl_dim_type type, unsigned first, unsigned n); + uint32_t isl_local_space_get_hash(__isl_keep isl_local_space *ls); -__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *dim, +__isl_give isl_local_space *isl_local_space_alloc(__isl_take isl_space *space, unsigned n_div); -__isl_give isl_local_space *isl_local_space_alloc_div(__isl_take isl_space *dim, - __isl_take isl_mat *div); +__isl_give isl_local_space *isl_local_space_alloc_div( + __isl_take isl_space *space, __isl_take isl_mat *div); + +__isl_keep isl_space *isl_local_space_peek_space( + __isl_keep isl_local_space *ls); __isl_give isl_local_space *isl_local_space_swap_div( __isl_take isl_local_space *ls, int a, int b); @@ -38,6 +44,10 @@ isl_bool isl_local_space_div_is_known(__isl_keep isl_local_space *ls, int div); isl_bool isl_local_space_divs_known(__isl_keep isl_local_space *ls); +__isl_give isl_basic_set *isl_local_space_lift_basic_set( + __isl_take isl_local_space *ls, __isl_take isl_basic_set *bset); +__isl_give isl_set *isl_local_space_lift_set(__isl_take isl_local_space *ls, + __isl_take isl_set *set); __isl_give isl_local_space *isl_local_space_substitute_equalities( __isl_take isl_local_space *ls, __isl_take isl_basic_set *eq); @@ -54,6 +64,8 @@ isl_bool isl_local_space_is_div_constraint(__isl_keep isl_local_space *ls, isl_int *constraint, unsigned div); +isl_bool isl_local_space_is_div_equality(__isl_keep isl_local_space *ls, + isl_int *constraint, unsigned div); int *isl_local_space_get_active(__isl_keep isl_local_space *ls, isl_int *l); @@ -78,5 +90,11 @@ int isl_local_space_cmp(__isl_keep isl_local_space *ls1, __isl_keep isl_local_space *ls2); + +__isl_give isl_point *isl_local_space_lift_point(__isl_take isl_local_space *ls, + __isl_take isl_point *pnt); + +isl_bool isl_local_space_has_space(__isl_keep isl_local_space *ls, + __isl_keep isl_space *space); #endif diff --git a/gcc/isl/isl_lp.c b/gcc/isl/isl_lp.c index 0c2f5ff..2389355 100644 --- a/gcc/isl/isl_lp.c +++ a/gcc/isl/isl_lp.c @@ -28,8 +28,10 @@ { struct isl_tab *tab; enum isl_lp_result res; - unsigned dim = isl_basic_map_total_dim(bmap); + isl_size dim = isl_basic_map_dim(bmap, isl_dim_all); + if (dim < 0) + return isl_lp_error; if (maximize) isl_seq_neg(f, f, 1 + dim); @@ -107,7 +109,9 @@ if (map->p[i]->n_div > max_div) max_div = map->p[i]->n_div; if (max_div > 0) { - unsigned total = isl_space_dim(map->dim, isl_dim_all); + isl_size total = isl_map_dim(map, isl_dim_all); + if (total < 0) + return isl_lp_error; v = isl_vec_alloc(map->ctx, 1 + total + max_div); if (!v) return isl_lp_error; @@ -259,7 +263,7 @@ isl_mat *bset_div = NULL; isl_mat *div = NULL; isl_val *res; - int bset_n_div, obj_n_div; + isl_size bset_n_div, obj_n_div; if (!bset || !obj) return NULL; @@ -271,6 +275,8 @@ bset_n_div = isl_basic_set_dim(bset, isl_dim_div); obj_n_div = isl_aff_dim(obj, isl_dim_div); + if (bset_n_div < 0 || obj_n_div < 0) + return NULL; if (bset_n_div == 0 && obj_n_div == 0) return basic_set_opt_lp(bset, max, obj); diff --git a/gcc/isl/isl_map.c b/gcc/isl/isl_map.c index 47e7acd..acb35a2 100644 --- a/gcc/isl/isl_map.c +++ a/gcc/isl/isl_map.c @@ -5,6 +5,7 @@ * Copyright 2014 INRIA Rocquencourt * Copyright 2016 INRIA Paris * Copyright 2016 Sven Verdoolaege + * Copyright 2018-2019 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -17,12 +18,14 @@ * B.P. 105 - 78153 Le Chesnay, France * and Centre de Recherche Inria de Paris, 2 rue Simone Iff - Voie DQ12, * CS 42112, 75589 Paris Cedex 12, France + * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA */ #include #include #include #include +#include #include #include "isl_space_private.h" #include "isl_equalities.h" @@ -43,23 +46,27 @@ #include #include #include +#include #include #include #include #include -static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type) +/* Treat "bset" as a basic map. + * Internally, isl_basic_set is defined to isl_basic_map, so in practice, + * this function performs a redundant cast. + */ +static __isl_keep const isl_basic_map *const_bset_to_bmap( + __isl_keep const isl_basic_set *bset) { - switch (type) { - case isl_dim_param: return dim->nparam; - case isl_dim_in: return dim->n_in; - case isl_dim_out: return dim->n_out; - case isl_dim_all: return dim->nparam + dim->n_in + dim->n_out; - default: return 0; - } + return (const isl_basic_map *) bset; } +#undef TYPE +#define TYPE isl_basic_map +#include "has_single_reference_templ.c" + static unsigned pos(__isl_keep isl_space *dim, enum isl_dim_type type) { switch (type) { @@ -70,11 +77,11 @@ } } -unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap, +isl_size isl_basic_map_dim(__isl_keep isl_basic_map *bmap, enum isl_dim_type type) { if (!bmap) - return 0; + return isl_size_error; switch (type) { case isl_dim_cst: return 1; case isl_dim_param: @@ -91,34 +98,70 @@ __isl_keep isl_space *isl_map_peek_space(__isl_keep const isl_map *map) { return map ? map->dim : NULL; +} + +/* Return the space of "set". + */ +__isl_keep isl_space *isl_set_peek_space(__isl_keep isl_set *set) +{ + return isl_map_peek_space(set_to_map(set)); } -unsigned isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type) +isl_size isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type) { - return map ? n(map->dim, type) : 0; + return isl_space_dim(isl_map_peek_space(map), type); } -unsigned isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type) +isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type) { - return set ? n(set->dim, type) : 0; + return isl_map_dim(set_to_map(set), type); } -unsigned isl_basic_map_offset(struct isl_basic_map *bmap, - enum isl_dim_type type) +/* Return the position of the variables of the given type + * within the sequence of variables of "bmap". + */ +isl_size isl_basic_map_var_offset(__isl_keep isl_basic_map *bmap, + enum isl_dim_type type) { isl_space *space; - if (!bmap) - return 0; + space = isl_basic_map_peek_space(bmap); + if (!space) + return isl_size_error; - space = bmap->dim; + switch (type) { + case isl_dim_param: + case isl_dim_in: + case isl_dim_out: return isl_space_offset(space, type); + case isl_dim_div: return isl_space_dim(space, isl_dim_all); + case isl_dim_cst: + default: + isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, + "invalid dimension type", return isl_size_error); + } +} + +/* Return the position of the variables of the given type + * within the sequence of variables of "bset". + */ +isl_size isl_basic_set_var_offset(__isl_keep isl_basic_set *bset, + enum isl_dim_type type) +{ + return isl_basic_map_var_offset(bset_to_bmap(bset), type); +} + +/* Return the position of the coefficients of the variables of the given type + * within the sequence of coefficients of "bmap". + */ +unsigned isl_basic_map_offset(__isl_keep isl_basic_map *bmap, + enum isl_dim_type type) +{ switch (type) { case isl_dim_cst: return 0; - case isl_dim_param: return 1; - case isl_dim_in: return 1 + space->nparam; - case isl_dim_out: return 1 + space->nparam + space->n_in; - case isl_dim_div: return 1 + space->nparam + space->n_in + - space->n_out; + case isl_dim_param: + case isl_dim_in: + case isl_dim_out: + case isl_dim_div: return 1 + isl_basic_map_var_offset(bmap, type); default: return 0; } } @@ -134,77 +177,47 @@ return pos(map->dim, type); } -unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset, +isl_size isl_basic_set_dim(__isl_keep isl_basic_set *bset, enum isl_dim_type type) { return isl_basic_map_dim(bset, type); } -unsigned isl_basic_set_n_dim(__isl_keep isl_basic_set *bset) +isl_size isl_basic_set_n_dim(__isl_keep isl_basic_set *bset) { return isl_basic_set_dim(bset, isl_dim_set); } -unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset) +isl_size isl_basic_set_n_param(__isl_keep isl_basic_set *bset) { return isl_basic_set_dim(bset, isl_dim_param); } -unsigned isl_basic_set_total_dim(__isl_keep const isl_basic_set *bset) +isl_size isl_basic_set_total_dim(__isl_keep const isl_basic_set *bset) { - if (!bset) - return 0; - return isl_space_dim(bset->dim, isl_dim_all) + bset->n_div; + return isl_basic_map_total_dim(const_bset_to_bmap(bset)); } -unsigned isl_set_n_dim(__isl_keep isl_set *set) +isl_size isl_set_n_dim(__isl_keep isl_set *set) { return isl_set_dim(set, isl_dim_set); } -unsigned isl_set_n_param(__isl_keep isl_set *set) +isl_size isl_set_n_param(__isl_keep isl_set *set) { return isl_set_dim(set, isl_dim_param); -} - -unsigned isl_basic_map_n_in(__isl_keep const isl_basic_map *bmap) -{ - return bmap ? bmap->dim->n_in : 0; -} - -unsigned isl_basic_map_n_out(__isl_keep const isl_basic_map *bmap) -{ - return bmap ? bmap->dim->n_out : 0; -} - -unsigned isl_basic_map_n_param(__isl_keep const isl_basic_map *bmap) -{ - return bmap ? bmap->dim->nparam : 0; -} - -unsigned isl_basic_map_n_div(__isl_keep const isl_basic_map *bmap) -{ - return bmap ? bmap->n_div : 0; -} - -unsigned isl_basic_map_total_dim(__isl_keep const isl_basic_map *bmap) -{ - return bmap ? isl_space_dim(bmap->dim, isl_dim_all) + bmap->n_div : 0; -} - -unsigned isl_map_n_in(__isl_keep const isl_map *map) -{ - return map ? map->dim->n_in : 0; } -unsigned isl_map_n_out(__isl_keep const isl_map *map) +isl_size isl_basic_map_total_dim(__isl_keep const isl_basic_map *bmap) { - return map ? map->dim->n_out : 0; -} + isl_size dim; -unsigned isl_map_n_param(__isl_keep const isl_map *map) -{ - return map ? map->dim->nparam : 0; + if (!bmap) + return isl_size_error; + dim = isl_space_dim(bmap->dim, isl_dim_all); + if (dim < 0) + return isl_size_error; + return dim + bmap->n_div; } /* Return the number of equality constraints in the description of "bmap". @@ -370,6 +383,58 @@ __isl_give isl_space *isl_basic_set_get_space(__isl_keep isl_basic_set *bset) { return isl_basic_map_get_space(bset_to_bmap(bset)); +} + +/* Return the space of "bmap". + * This may be either a copy or the space itself + * if there is only one reference to "bmap". + * This allows the space to be modified inplace + * if both the basic map and its space have only a single reference. + * The caller is not allowed to modify "bmap" between this call and + * a subsequent call to isl_basic_map_restore_space. + * The only exception is that isl_basic_map_free can be called instead. + */ +static __isl_give isl_space *isl_basic_map_take_space( + __isl_keep isl_basic_map *bmap) +{ + isl_space *space; + + if (!bmap) + return NULL; + if (bmap->ref != 1) + return isl_basic_map_get_space(bmap); + space = bmap->dim; + bmap->dim = NULL; + return space; +} + +/* Set the space of "bmap" to "space", where the space of "bmap" may be missing + * due to a preceding call to isl_basic_map_take_space. + * However, in this case, "bmap" only has a single reference and + * then the call to isl_basic_map_cow has no effect. + */ +static __isl_give isl_basic_map *isl_basic_map_restore_space( + __isl_take isl_basic_map *bmap, __isl_take isl_space *space) +{ + if (!bmap || !space) + goto error; + + if (bmap->dim == space) { + isl_space_free(space); + return bmap; + } + + bmap = isl_basic_map_cow(bmap); + if (!bmap) + goto error; + isl_space_free(bmap->dim); + bmap->dim = space; + + return bmap; +error: + isl_basic_map_free(bmap); + isl_space_free(space); + return NULL; } /* Extract the divs in "bmap" as a matrix. @@ -379,15 +444,15 @@ int i; isl_ctx *ctx; isl_mat *div; - unsigned total; + isl_size v_div; unsigned cols; - if (!bmap) + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) return NULL; ctx = isl_basic_map_get_ctx(bmap); - total = isl_space_dim(bmap->dim, isl_dim_all); - cols = 1 + 1 + total + bmap->n_div; + cols = 1 + 1 + v_div + bmap->n_div; div = isl_mat_alloc(ctx, bmap->n_div, cols); if (!div) return NULL; @@ -434,11 +499,11 @@ __isl_take isl_basic_map *bmap) { int i; - unsigned n_div; + isl_size n_div; - if (!bmap) - return NULL; n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); if (n_div == 0) return bmap; bmap = isl_basic_map_cow(bmap); @@ -448,8 +513,7 @@ for (i = 0; i < n_div; ++i) { if (isl_int_is_zero(bmap->div[i][0])) continue; - if (isl_basic_map_add_div_constraints(bmap, i) < 0) - return isl_basic_map_free(bmap); + bmap = isl_basic_map_add_div_constraints(bmap, i); } return bmap; @@ -459,13 +523,15 @@ __isl_take isl_local_space *ls) { int i; - int n_div; + isl_size n_div; isl_basic_map *bmap; + n_div = isl_local_space_dim(ls, isl_dim_div); + if (n_div < 0) + ls = isl_local_space_free(ls); if (!ls) return NULL; - n_div = isl_local_space_dim(ls, isl_dim_div); bmap = isl_basic_map_alloc_space(isl_local_space_get_space(ls), n_div, 0, 2 * n_div); @@ -503,20 +569,67 @@ return isl_space_copy(set->dim); } -__isl_give isl_basic_map *isl_basic_map_set_tuple_name( - __isl_take isl_basic_map *bmap, enum isl_dim_type type, const char *s) +/* Return the space of "map". + * This may be either a copy or the space itself + * if there is only one reference to "map". + * This allows the space to be modified inplace + * if both the map and its space have only a single reference. + * The caller is not allowed to modify "map" between this call and + * a subsequent call to isl_map_restore_space. + * The only exception is that isl_map_free can be called instead. + */ +static __isl_give isl_space *isl_map_take_space(__isl_keep isl_map *map) { - bmap = isl_basic_map_cow(bmap); - if (!bmap) + isl_space *space; + + if (!map) return NULL; - bmap->dim = isl_space_set_tuple_name(bmap->dim, type, s); - if (!bmap->dim) + if (map->ref != 1) + return isl_map_get_space(map); + space = map->dim; + map->dim = NULL; + return space; +} + +/* Set the space of "map" to "space", where the space of "map" may be missing + * due to a preceding call to isl_map_take_space. + * However, in this case, "map" only has a single reference and + * then the call to isl_map_cow has no effect. + */ +static __isl_give isl_map *isl_map_restore_space(__isl_take isl_map *map, + __isl_take isl_space *space) +{ + if (!map || !space) goto error; - bmap = isl_basic_map_finalize(bmap); - return bmap; + + if (map->dim == space) { + isl_space_free(space); + return map; + } + + map = isl_map_cow(map); + if (!map) + goto error; + isl_space_free(map->dim); + map->dim = space; + + return map; error: - isl_basic_map_free(bmap); + isl_map_free(map); + isl_space_free(space); return NULL; +} + +__isl_give isl_basic_map *isl_basic_map_set_tuple_name( + __isl_take isl_basic_map *bmap, enum isl_dim_type type, const char *s) +{ + isl_space *space; + + space = isl_basic_map_take_space(bmap); + space = isl_space_set_tuple_name(space, type, s); + bmap = isl_basic_map_restore_space(bmap, space); + bmap = isl_basic_map_finalize(bmap); + return bmap; } __isl_give isl_basic_set *isl_basic_set_set_tuple_name( @@ -535,14 +648,11 @@ enum isl_dim_type type, const char *s) { int i; + isl_space *space; map = isl_map_cow(map); if (!map) return NULL; - - map->dim = isl_space_set_tuple_name(map->dim, type, s); - if (!map->dim) - goto error; for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_set_tuple_name(map->p[i], type, s); @@ -550,6 +660,10 @@ goto error; } + space = isl_map_take_space(map); + space = isl_space_set_tuple_name(space, type, s); + map = isl_map_restore_space(map, space); + return map; error: isl_map_free(map); @@ -562,17 +676,13 @@ __isl_take isl_basic_map *bmap, enum isl_dim_type type, __isl_take isl_id *id) { - bmap = isl_basic_map_cow(bmap); - if (!bmap) - goto error; - bmap->dim = isl_space_set_tuple_id(bmap->dim, type, id); - if (!bmap->dim) - return isl_basic_map_free(bmap); + isl_space *space; + + space = isl_basic_map_take_space(bmap); + space = isl_space_set_tuple_id(space, type, id); + bmap = isl_basic_map_restore_space(bmap, space); bmap = isl_basic_map_finalize(bmap); return bmap; -error: - isl_id_free(id); - return NULL; } /* Replace the identifier of the tuple by "id". @@ -606,16 +716,13 @@ __isl_give isl_map *isl_map_set_tuple_id(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_id *id) { - map = isl_map_cow(map); - if (!map) - goto error; + isl_space *space; - map->dim = isl_space_set_tuple_id(map->dim, type, id); + space = isl_map_take_space(map); + space = isl_space_set_tuple_id(space, type, id); + map = isl_map_restore_space(map, space); - return isl_map_reset_space(map, isl_space_copy(map->dim)); -error: - isl_id_free(id); - return NULL; + return isl_map_reset_space(map, isl_map_get_space(map)); } __isl_give isl_set *isl_set_set_tuple_id(__isl_take isl_set *set, @@ -627,13 +734,13 @@ __isl_give isl_map *isl_map_reset_tuple_id(__isl_take isl_map *map, enum isl_dim_type type) { - map = isl_map_cow(map); - if (!map) - return NULL; + isl_space *space; - map->dim = isl_space_reset_tuple_id(map->dim, type); + space = isl_map_take_space(map); + space = isl_space_reset_tuple_id(space, type); + map = isl_map_restore_space(map, space); - return isl_map_reset_space(map, isl_space_copy(map->dim)); + return isl_map_reset_space(map, isl_map_get_space(map)); } __isl_give isl_set *isl_set_reset_tuple_id(__isl_take isl_set *set) @@ -730,30 +837,23 @@ __isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, const char *s) { - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; - bmap->dim = isl_space_set_dim_name(bmap->dim, type, pos, s); - if (!bmap->dim) - goto error; + isl_space *space; + + space = isl_basic_map_take_space(bmap); + space = isl_space_set_dim_name(space, type, pos, s); + bmap = isl_basic_map_restore_space(bmap, space); return isl_basic_map_finalize(bmap); -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_map *isl_map_set_dim_name(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, const char *s) { int i; + isl_space *space; map = isl_map_cow(map); if (!map) return NULL; - - map->dim = isl_space_set_dim_name(map->dim, type, pos, s); - if (!map->dim) - goto error; for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_set_dim_name(map->p[i], type, pos, s); @@ -761,6 +861,10 @@ goto error; } + space = isl_map_take_space(map); + space = isl_space_set_dim_name(space, type, pos, s); + map = isl_map_restore_space(map, space); + return map; error: isl_map_free(map); @@ -823,16 +927,13 @@ __isl_give isl_map *isl_map_set_dim_id(__isl_take isl_map *map, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) { - map = isl_map_cow(map); - if (!map) - goto error; + isl_space *space; - map->dim = isl_space_set_dim_id(map->dim, type, pos, id); + space = isl_map_take_space(map); + space = isl_space_set_dim_id(space, type, pos, id); + map = isl_map_restore_space(map, space); - return isl_map_reset_space(map, isl_space_copy(map->dim)); -error: - isl_id_free(id); - return NULL; + return isl_map_reset_space(map, isl_map_get_space(map)); } __isl_give isl_set *isl_set_set_dim_id(__isl_take isl_set *set, @@ -890,21 +991,20 @@ */ isl_bool isl_basic_set_eq_is_stride(__isl_keep isl_basic_set *bset, int i) { - unsigned nparam; - unsigned d; - unsigned n_div; + isl_size nparam; + isl_size d; + isl_size n_div; int pos1; int pos2; - if (!bset) + nparam = isl_basic_set_dim(bset, isl_dim_param); + d = isl_basic_set_dim(bset, isl_dim_set); + n_div = isl_basic_set_dim(bset, isl_dim_div); + if (nparam < 0 || d < 0 || n_div < 0) return isl_bool_error; if (!isl_int_is_zero(bset->eq[i][0])) return isl_bool_false; - - nparam = isl_basic_set_dim(bset, isl_dim_param); - d = isl_basic_set_dim(bset, isl_dim_set); - n_div = isl_basic_set_dim(bset, isl_dim_div); if (isl_seq_first_non_zero(bset->eq[i] + 1, nparam) != -1) return isl_bool_false; @@ -1015,7 +1115,7 @@ isl_bool isl_basic_map_has_rational(__isl_keep isl_basic_map *bmap) { isl_bool has_rational = isl_bool_true; - unsigned total; + isl_size total; if (!bmap) return isl_bool_error; @@ -1025,9 +1125,9 @@ return isl_bool_false; bmap = isl_basic_map_copy(bmap); bmap = isl_basic_map_implicit_equalities(bmap); - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return isl_bool_error; - total = isl_basic_map_total_dim(bmap); if (bmap->n_eq == total) { int i, j; for (i = 0; i < bmap->n_eq; ++i) { @@ -1103,16 +1203,21 @@ return isl_space_is_params(map->dim); } -static struct isl_basic_map *basic_map_init(struct isl_ctx *ctx, - struct isl_basic_map *bmap, unsigned extra, - unsigned n_eq, unsigned n_ineq) +static __isl_give isl_basic_map *basic_map_init(isl_ctx *ctx, + __isl_take isl_basic_map *bmap, unsigned extra, + unsigned n_eq, unsigned n_ineq) { int i; - size_t row_size = 1 + isl_space_dim(bmap->dim, isl_dim_all) + extra; + isl_space *space = isl_basic_map_peek_space(bmap); + isl_size n_var = isl_space_dim(space, isl_dim_all); + size_t row_size = 1 + n_var + extra; bmap->ctx = ctx; isl_ctx_ref(ctx); + if (n_var < 0) + return isl_basic_map_free(bmap); + bmap->block = isl_blk_alloc(ctx, (n_ineq + n_eq) * row_size); if (isl_blk_is_error(bmap->block)) goto error; @@ -1185,21 +1290,21 @@ return NULL; } -struct isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim, +__isl_give isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq) { struct isl_basic_map *bmap; - if (!dim) + if (!space) return NULL; - bmap = isl_calloc_type(dim->ctx, struct isl_basic_map); + bmap = isl_calloc_type(space->ctx, struct isl_basic_map); if (!bmap) goto error; - bmap->dim = dim; + bmap->dim = space; - return basic_map_init(dim->ctx, bmap, extra, n_eq, n_ineq); + return basic_map_init(space->ctx, bmap, extra, n_eq, n_ineq); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1218,27 +1323,37 @@ return bmap; } -static void dup_constraints( - struct isl_basic_map *dst, struct isl_basic_map *src) +static __isl_give isl_basic_map *dup_constraints(__isl_take isl_basic_map *dst, + __isl_keep isl_basic_map *src) { int i; - unsigned total = isl_basic_map_total_dim(src); + isl_size total = isl_basic_map_dim(src, isl_dim_all); + + if (!dst || total < 0) + return isl_basic_map_free(dst); for (i = 0; i < src->n_eq; ++i) { int j = isl_basic_map_alloc_equality(dst); + if (j < 0) + return isl_basic_map_free(dst); isl_seq_cpy(dst->eq[j], src->eq[i], 1+total); } for (i = 0; i < src->n_ineq; ++i) { int j = isl_basic_map_alloc_inequality(dst); + if (j < 0) + return isl_basic_map_free(dst); isl_seq_cpy(dst->ineq[j], src->ineq[i], 1+total); } for (i = 0; i < src->n_div; ++i) { int j = isl_basic_map_alloc_div(dst); + if (j < 0) + return isl_basic_map_free(dst); isl_seq_cpy(dst->div[j], src->div[i], 1+1+total); } ISL_F_SET(dst, ISL_BASIC_SET_FINAL); + return dst; } __isl_give isl_basic_map *isl_basic_map_dup(__isl_keep isl_basic_map *bmap) @@ -1249,9 +1364,9 @@ return NULL; dup = isl_basic_map_alloc_space(isl_space_copy(bmap->dim), bmap->n_div, bmap->n_eq, bmap->n_ineq); + dup = dup_constraints(dup, bmap); if (!dup) return NULL; - dup_constraints(dup, bmap); dup->flags = bmap->flags; dup->sample = isl_vec_copy(bmap->sample); return dup; @@ -1338,6 +1453,38 @@ static int room_for_con(struct isl_basic_map *bmap, unsigned n) { return bmap->n_eq + bmap->n_ineq + n <= bmap->c_size; +} + +/* Check that "bset" does not involve any parameters. + */ +isl_stat isl_basic_set_check_no_params(__isl_keep isl_basic_set *bset) +{ + isl_size nparam; + + nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0) + return isl_stat_error; + if (nparam != 0) + isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid, + "basic set should not have any parameters", + return isl_stat_error); + return isl_stat_ok; +} + +/* Check that "bset" does not involve any local variables. + */ +isl_stat isl_basic_set_check_no_locals(__isl_keep isl_basic_set *bset) +{ + isl_size n_div; + + n_div = isl_basic_set_dim(bset, isl_dim_div); + if (n_div < 0) + return isl_stat_error; + if (n_div != 0) + isl_die(isl_basic_set_get_ctx(bset), isl_error_invalid, + "basic set should not have any local variables", + return isl_stat_error); + return isl_stat_ok; } /* Check that "map" has only named parameters, reporting an error @@ -1346,6 +1493,14 @@ isl_stat isl_map_check_named_params(__isl_keep isl_map *map) { return isl_space_check_named_params(isl_map_peek_space(map)); +} + +/* Check that "bmap" has only named parameters, reporting an error + * if it does not. + */ +static isl_stat isl_basic_map_check_named_params(__isl_keep isl_basic_map *bmap) +{ + return isl_space_check_named_params(isl_basic_map_peek_space(bmap)); } /* Check that "bmap1" and "bmap2" have the same parameters, @@ -1413,14 +1568,16 @@ int isl_basic_map_alloc_equality(struct isl_basic_map *bmap) { + isl_size total; struct isl_ctx *ctx; - if (!bmap) + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return -1; ctx = bmap->ctx; isl_assert(ctx, room_for_con(bmap, 1), return -1); isl_assert(ctx, (bmap->eq - bmap->ineq) + bmap->n_eq <= bmap->c_size, return -1); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_IMPLICIT); ISL_F_CLR(bmap, ISL_BASIC_MAP_ALL_EQUALITIES); @@ -1439,7 +1596,7 @@ bmap->eq--; return 0; } - isl_seq_clr(bmap->eq[bmap->n_eq] + 1 + isl_basic_map_total_dim(bmap), + isl_seq_clr(bmap->eq[bmap->n_eq] + 1 + total, bmap->extra - bmap->n_div); return bmap->n_eq++; } @@ -1449,33 +1606,44 @@ return isl_basic_map_alloc_equality(bset_to_bmap(bset)); } -int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n) +__isl_give isl_basic_map *isl_basic_map_free_equality( + __isl_take isl_basic_map *bmap, unsigned n) { if (!bmap) - return -1; - isl_assert(bmap->ctx, n <= bmap->n_eq, return -1); + return NULL; + if (n > bmap->n_eq) + isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, + "invalid number of equalities", + isl_basic_map_free(bmap)); bmap->n_eq -= n; - return 0; + return bmap; } -int isl_basic_set_free_equality(struct isl_basic_set *bset, unsigned n) +__isl_give isl_basic_set *isl_basic_set_free_equality( + __isl_take isl_basic_set *bset, unsigned n) { - return isl_basic_map_free_equality(bset_to_bmap(bset), n); + return bset_from_bmap(isl_basic_map_free_equality(bset_to_bmap(bset), + n)); } +/* Drop the equality constraint at position "pos", + * preserving the order of the other equality constraints. + */ int isl_basic_map_drop_equality(struct isl_basic_map *bmap, unsigned pos) { isl_int *t; + int r; + if (!bmap) return -1; isl_assert(bmap->ctx, pos < bmap->n_eq, return -1); - if (pos != bmap->n_eq - 1) { - t = bmap->eq[pos]; - bmap->eq[pos] = bmap->eq[bmap->n_eq - 1]; - bmap->eq[bmap->n_eq - 1] = t; - } + t = bmap->eq[pos]; bmap->n_eq--; + for (r = pos; r < bmap->n_eq; ++r) + bmap->eq[r] = bmap->eq[r + 1]; + bmap->eq[bmap->n_eq] = t; + return 0; } @@ -1499,7 +1667,7 @@ bmap->n_ineq--; bmap->eq--; ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS); ISL_F_CLR(bmap, ISL_BASIC_MAP_ALL_EQUALITIES); } @@ -1511,17 +1679,19 @@ int isl_basic_map_alloc_inequality(__isl_keep isl_basic_map *bmap) { + isl_size total; struct isl_ctx *ctx; - if (!bmap) + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return -1; ctx = bmap->ctx; isl_assert(ctx, room_for_ineq(bmap, 1), return -1); ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_IMPLICIT); ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); ISL_F_CLR(bmap, ISL_BASIC_MAP_ALL_EQUALITIES); - isl_seq_clr(bmap->ineq[bmap->n_ineq] + - 1 + isl_basic_map_total_dim(bmap), + isl_seq_clr(bmap->ineq[bmap->n_ineq] + 1 + total, bmap->extra - bmap->n_div); return bmap->n_ineq++; } @@ -1531,18 +1701,24 @@ return isl_basic_map_alloc_inequality(bset_to_bmap(bset)); } -int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n) +__isl_give isl_basic_map *isl_basic_map_free_inequality( + __isl_take isl_basic_map *bmap, unsigned n) { if (!bmap) - return -1; - isl_assert(bmap->ctx, n <= bmap->n_ineq, return -1); - bmap->n_ineq -= n; - return 0; + return NULL; + if (n > bmap->n_ineq) + isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, + "invalid number of inequalities", + return isl_basic_map_free(bmap)); + bmap->n_ineq -= n; + return bmap; } -int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n) +__isl_give isl_basic_set *isl_basic_set_free_inequality( + __isl_take isl_basic_set *bset, unsigned n) { - return isl_basic_map_free_inequality(bset_to_bmap(bset), n); + return bset_from_bmap(isl_basic_map_free_inequality(bset_to_bmap(bset), + n)); } int isl_basic_map_drop_inequality(struct isl_basic_map *bmap, unsigned pos) @@ -1556,7 +1732,7 @@ t = bmap->ineq[pos]; bmap->ineq[pos] = bmap->ineq[bmap->n_ineq - 1]; bmap->ineq[bmap->n_ineq - 1] = t; - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); } bmap->n_ineq--; return 0; @@ -1570,15 +1746,25 @@ __isl_give isl_basic_map *isl_basic_map_add_eq(__isl_take isl_basic_map *bmap, isl_int *eq) { + isl_bool empty; + isl_size total; int k; + + empty = isl_basic_map_plain_is_empty(bmap); + if (empty < 0) + return isl_basic_map_free(bmap); + if (empty) + return bmap; + bmap = isl_basic_map_cow(bmap); bmap = isl_basic_map_extend_constraints(bmap, 1, 0); - if (!bmap) - return NULL; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); k = isl_basic_map_alloc_equality(bmap); if (k < 0) goto error; - isl_seq_cpy(bmap->eq[k], eq, 1 + isl_basic_map_total_dim(bmap)); + isl_seq_cpy(bmap->eq[k], eq, 1 + total); return bmap; error: isl_basic_map_free(bmap); @@ -1594,15 +1780,18 @@ __isl_give isl_basic_map *isl_basic_map_add_ineq(__isl_take isl_basic_map *bmap, isl_int *ineq) { + isl_size total; int k; + bmap = isl_basic_map_cow(bmap); bmap = isl_basic_map_extend_constraints(bmap, 0, 1); - if (!bmap) - return NULL; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); k = isl_basic_map_alloc_inequality(bmap); if (k < 0) goto error; - isl_seq_cpy(bmap->ineq[k], ineq, 1 + isl_basic_map_total_dim(bmap)); + isl_seq_cpy(bmap->ineq[k], ineq, 1 + total); return bmap; error: isl_basic_map_free(bmap); @@ -1617,11 +1806,13 @@ int isl_basic_map_alloc_div(struct isl_basic_map *bmap) { - if (!bmap) + isl_size total; + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return -1; isl_assert(bmap->ctx, bmap->n_div < bmap->extra, return -1); - isl_seq_clr(bmap->div[bmap->n_div] + - 1 + 1 + isl_basic_map_total_dim(bmap), + isl_seq_clr(bmap->div[bmap->n_div] + 1 + 1 + total, bmap->extra - bmap->n_div); ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS); return bmap->n_div++; @@ -1631,23 +1822,19 @@ { return isl_basic_map_alloc_div(bset_to_bmap(bset)); } + +#undef TYPE +#define TYPE isl_basic_map +#include "check_type_range_templ.c" /* Check that there are "n" dimensions of type "type" starting at "first" - * in "bmap". + * in "bset". */ -static isl_stat isl_basic_map_check_range(__isl_keep isl_basic_map *bmap, +isl_stat isl_basic_set_check_range(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n) { - unsigned dim; - - if (!bmap) - return isl_stat_error; - dim = isl_basic_map_dim(bmap, type); - if (first + n > dim || first + n < first) - isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, - "position or range out of bounds", - return isl_stat_error); - return isl_stat_ok; + return isl_basic_map_check_range(bset_to_bmap(bset), + type, first, n); } /* Insert an extra integer division, prescribed by "div", to "bmap" @@ -1660,12 +1847,14 @@ __isl_take isl_basic_map *bmap, int pos, __isl_keep isl_vec *div) { int i, k; + isl_size total; bmap = isl_basic_map_cow(bmap); - if (!bmap || !div) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0 || !div) return isl_basic_map_free(bmap); - if (div->size != 1 + 1 + isl_basic_map_dim(bmap, isl_dim_all)) + if (div->size != 1 + 1 + total) isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, "unexpected size", return isl_basic_map_free(bmap)); if (isl_basic_map_check_range(bmap, isl_dim_div, pos, 0) < 0) @@ -1680,7 +1869,7 @@ isl_int_set_si(bmap->div[k][div->size], 0); for (i = k; i > pos; --i) - isl_basic_map_swap_div(bmap, i, i - 1); + bmap = isl_basic_map_swap_div(bmap, i, i - 1); return bmap; } @@ -1692,100 +1881,39 @@ isl_assert(bmap->ctx, n <= bmap->n_div, return isl_stat_error); bmap->n_div -= n; return isl_stat_ok; -} - -/* Copy constraint from src to dst, putting the vars of src at offset - * dim_off in dst and the divs of src at offset div_off in dst. - * If both sets are actually map, then dim_off applies to the input - * variables. - */ -static void copy_constraint(struct isl_basic_map *dst_map, isl_int *dst, - struct isl_basic_map *src_map, isl_int *src, - unsigned in_off, unsigned out_off, unsigned div_off) -{ - unsigned src_nparam = isl_basic_map_dim(src_map, isl_dim_param); - unsigned dst_nparam = isl_basic_map_dim(dst_map, isl_dim_param); - unsigned src_in = isl_basic_map_dim(src_map, isl_dim_in); - unsigned dst_in = isl_basic_map_dim(dst_map, isl_dim_in); - unsigned src_out = isl_basic_map_dim(src_map, isl_dim_out); - unsigned dst_out = isl_basic_map_dim(dst_map, isl_dim_out); - isl_int_set(dst[0], src[0]); - isl_seq_cpy(dst+1, src+1, isl_min(dst_nparam, src_nparam)); - if (dst_nparam > src_nparam) - isl_seq_clr(dst+1+src_nparam, - dst_nparam - src_nparam); - isl_seq_clr(dst+1+dst_nparam, in_off); - isl_seq_cpy(dst+1+dst_nparam+in_off, - src+1+src_nparam, - isl_min(dst_in-in_off, src_in)); - if (dst_in-in_off > src_in) - isl_seq_clr(dst+1+dst_nparam+in_off+src_in, - dst_in - in_off - src_in); - isl_seq_clr(dst+1+dst_nparam+dst_in, out_off); - isl_seq_cpy(dst+1+dst_nparam+dst_in+out_off, - src+1+src_nparam+src_in, - isl_min(dst_out-out_off, src_out)); - if (dst_out-out_off > src_out) - isl_seq_clr(dst+1+dst_nparam+dst_in+out_off+src_out, - dst_out - out_off - src_out); - isl_seq_clr(dst+1+dst_nparam+dst_in+dst_out, div_off); - isl_seq_cpy(dst+1+dst_nparam+dst_in+dst_out+div_off, - src+1+src_nparam+src_in+src_out, - isl_min(dst_map->extra-div_off, src_map->n_div)); - if (dst_map->n_div-div_off > src_map->n_div) - isl_seq_clr(dst+1+dst_nparam+dst_in+dst_out+ - div_off+src_map->n_div, - dst_map->n_div - div_off - src_map->n_div); -} - -static void copy_div(struct isl_basic_map *dst_map, isl_int *dst, - struct isl_basic_map *src_map, isl_int *src, - unsigned in_off, unsigned out_off, unsigned div_off) -{ - isl_int_set(dst[0], src[0]); - copy_constraint(dst_map, dst+1, src_map, src+1, in_off, out_off, div_off); } static __isl_give isl_basic_map *add_constraints( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2, unsigned i_pos, unsigned o_pos) { - int i; - unsigned div_off; + isl_size total, n_param, n_in, n_out, n_div; + unsigned o_in, o_out; + isl_ctx *ctx; + isl_space *space; + struct isl_dim_map *dim_map; - if (!bmap1 || !bmap2) + space = isl_basic_map_peek_space(bmap2); + if (!bmap1 || !space) goto error; - - div_off = bmap1->n_div; - - for (i = 0; i < bmap2->n_eq; ++i) { - int i1 = isl_basic_map_alloc_equality(bmap1); - if (i1 < 0) - goto error; - copy_constraint(bmap1, bmap1->eq[i1], bmap2, bmap2->eq[i], - i_pos, o_pos, div_off); - } - - for (i = 0; i < bmap2->n_ineq; ++i) { - int i1 = isl_basic_map_alloc_inequality(bmap1); - if (i1 < 0) - goto error; - copy_constraint(bmap1, bmap1->ineq[i1], bmap2, bmap2->ineq[i], - i_pos, o_pos, div_off); - } - for (i = 0; i < bmap2->n_div; ++i) { - int i1 = isl_basic_map_alloc_div(bmap1); - if (i1 < 0) - goto error; - copy_div(bmap1, bmap1->div[i1], bmap2, bmap2->div[i], - i_pos, o_pos, div_off); - } - - isl_basic_map_free(bmap2); - - return bmap1; - + total = isl_basic_map_dim(bmap1, isl_dim_all); + n_param = isl_basic_map_dim(bmap2, isl_dim_param); + n_in = isl_basic_map_dim(bmap2, isl_dim_in); + o_in = isl_basic_map_offset(bmap1, isl_dim_in) - 1 + i_pos; + n_out = isl_basic_map_dim(bmap2, isl_dim_out); + o_out = isl_basic_map_offset(bmap1, isl_dim_out) - 1 + o_pos; + n_div = isl_basic_map_dim(bmap2, isl_dim_div); + if (total < 0 || n_param < 0 || n_in < 0 || n_out < 0 || n_div < 0) + goto error; + ctx = isl_basic_map_get_ctx(bmap1); + dim_map = isl_dim_map_alloc(ctx, total + n_div); + isl_dim_map_dim_range(dim_map, space, isl_dim_param, 0, n_param, 0); + isl_dim_map_dim_range(dim_map, space, isl_dim_in, 0, n_in, o_in); + isl_dim_map_dim_range(dim_map, space, isl_dim_out, 0, n_out, o_out); + isl_dim_map_div(dim_map, bmap2, total); + + return isl_basic_map_add_constraints_dim_map(bmap1, bmap2, dim_map); error: isl_basic_map_free(bmap1); isl_basic_map_free(bmap2); @@ -1800,37 +1928,37 @@ } __isl_give isl_basic_map *isl_basic_map_extend_space( - __isl_take isl_basic_map *base, __isl_take isl_space *dim, + __isl_take isl_basic_map *base, __isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq) { struct isl_basic_map *ext; unsigned flags; int dims_ok; - if (!dim) + if (!space) goto error; if (!base) goto error; - dims_ok = isl_space_is_equal(base->dim, dim) && + dims_ok = isl_space_is_equal(base->dim, space) && base->extra >= base->n_div + extra; if (dims_ok && room_for_con(base, n_eq + n_ineq) && room_for_ineq(base, n_ineq)) { - isl_space_free(dim); + isl_space_free(space); return base; } - isl_assert(base->ctx, base->dim->nparam <= dim->nparam, goto error); - isl_assert(base->ctx, base->dim->n_in <= dim->n_in, goto error); - isl_assert(base->ctx, base->dim->n_out <= dim->n_out, goto error); + isl_assert(base->ctx, base->dim->nparam <= space->nparam, goto error); + isl_assert(base->ctx, base->dim->n_in <= space->n_in, goto error); + isl_assert(base->ctx, base->dim->n_out <= space->n_out, goto error); extra += base->extra; n_eq += base->n_eq; n_ineq += base->n_ineq; - ext = isl_basic_map_alloc_space(dim, extra, n_eq, n_ineq); - dim = NULL; + ext = isl_basic_map_alloc_space(space, extra, n_eq, n_ineq); + space = NULL; if (!ext) goto error; @@ -1846,7 +1974,7 @@ return ext; error: - isl_space_free(dim); + isl_space_free(space); isl_basic_map_free(base); return NULL; } @@ -1887,14 +2015,6 @@ error: isl_basic_map_free(base); return NULL; -} - -struct isl_basic_set *isl_basic_set_extend(struct isl_basic_set *base, - unsigned nparam, unsigned dim, unsigned extra, - unsigned n_eq, unsigned n_ineq) -{ - return bset_from_bmap(isl_basic_map_extend(bset_to_bmap(base), - nparam, 0, dim, extra, n_eq, n_ineq)); } struct isl_basic_set *isl_basic_set_extend_constraints( @@ -1980,12 +2100,9 @@ int i; struct isl_blk blk; - if (!bmap) + if (isl_basic_map_check_range(bmap, isl_dim_all, pos - 1, n1 + n2) < 0) goto error; - isl_assert(bmap->ctx, - pos + n1 + n2 <= 1 + isl_basic_map_total_dim(bmap), goto error); - if (n1 == 0 || n2 == 0) return bmap; @@ -2011,7 +2128,7 @@ isl_blk_free(bmap->ctx, blk); - ISL_F_CLR(bmap, ISL_BASIC_SET_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_SET_SORTED); bmap = isl_basic_map_gauss(bmap, NULL); return isl_basic_map_finalize(bmap); error: @@ -2023,16 +2140,21 @@ __isl_take isl_basic_map *bmap) { int i = 0; - unsigned total; - if (!bmap) - goto error; - total = isl_basic_map_total_dim(bmap); + isl_size total; + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); if (isl_basic_map_free_div(bmap, bmap->n_div) < 0) return isl_basic_map_free(bmap); - isl_basic_map_free_inequality(bmap, bmap->n_ineq); - if (bmap->n_eq > 0) - isl_basic_map_free_equality(bmap, bmap->n_eq-1); - else { + bmap = isl_basic_map_free_inequality(bmap, bmap->n_ineq); + if (!bmap) + return NULL; + if (bmap->n_eq > 0) { + bmap = isl_basic_map_free_equality(bmap, bmap->n_eq - 1); + if (!bmap) + return NULL; + } else { i = isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; @@ -2132,10 +2254,15 @@ /* Swap divs "a" and "b" in "bmap" and adjust the constraints and * div definitions accordingly. */ -void isl_basic_map_swap_div(struct isl_basic_map *bmap, int a, int b) +__isl_give isl_basic_map *isl_basic_map_swap_div(__isl_take isl_basic_map *bmap, + int a, int b) { int i; - unsigned off = isl_space_dim(bmap->dim, isl_dim_all); + isl_size off; + + off = isl_basic_map_var_offset(bmap, isl_dim_div); + if (off < 0) + return isl_basic_map_free(bmap); swap_div(bmap, a, b); @@ -2147,15 +2274,9 @@ for (i = 0; i < bmap->n_div; ++i) isl_int_swap(bmap->div[i][1+1+off+a], bmap->div[i][1+1+off+b]); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); -} + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); -/* Swap divs "a" and "b" in "bset" and adjust the constraints and - * div definitions accordingly. - */ -void isl_basic_set_swap_div(__isl_keep isl_basic_set *bset, int a, int b) -{ - isl_basic_map_swap_div(bset, a, b); + return bmap; } static void constraint_drop_vars(isl_int *c, unsigned n, unsigned rem) @@ -2202,38 +2323,49 @@ error: isl_basic_map_free(bmap); return NULL; +} + +#undef TYPE +#define TYPE isl_map +static +#include "check_type_range_templ.c" + +/* Check that there are "n" dimensions of type "type" starting at "first" + * in "set". + */ +static isl_stat isl_set_check_range(__isl_keep isl_set *set, + enum isl_dim_type type, unsigned first, unsigned n) +{ + return isl_map_check_range(set_to_map(set), type, first, n); } /* Drop "n" dimensions of type "type" starting at "first". + * Perform the core computation, without cowing or + * simplifying and finalizing the result. * * In principle, this frees up some extra variables as the number * of columns remains constant, but we would have to extend * the div array too as the number of rows in this array is assumed * to be equal to extra. */ -__isl_give isl_basic_map *isl_basic_map_drop(__isl_take isl_basic_map *bmap, - enum isl_dim_type type, unsigned first, unsigned n) +__isl_give isl_basic_map *isl_basic_map_drop_core( + __isl_take isl_basic_map *bmap, enum isl_dim_type type, + unsigned first, unsigned n) { int i; - unsigned dim; unsigned offset; unsigned left; - - if (!bmap) - goto error; - - dim = isl_basic_map_dim(bmap, type); - isl_assert(bmap->ctx, first + n <= dim, goto error); + isl_size total; - if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type)) - return bmap; + if (isl_basic_map_check_range(bmap, type, first, n) < 0) + return isl_basic_map_free(bmap); - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); offset = isl_basic_map_offset(bmap, type) + first; - left = isl_basic_map_total_dim(bmap) - (offset - 1) - n; + left = total - (offset - 1) - n; for (i = 0; i < bmap->n_eq; ++i) constraint_drop_vars(bmap->eq[i]+offset, n, left); @@ -2246,20 +2378,42 @@ if (type == isl_dim_div) { bmap = move_divs_last(bmap, first, n); if (!bmap) - goto error; + return NULL; if (isl_basic_map_free_div(bmap, n) < 0) return isl_basic_map_free(bmap); } else bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n); if (!bmap->dim) - goto error; + return isl_basic_map_free(bmap); + + ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); + return bmap; +} + +/* Drop "n" dimensions of type "type" starting at "first". + * + * In principle, this frees up some extra variables as the number + * of columns remains constant, but we would have to extend + * the div array too as the number of rows in this array is assumed + * to be equal to extra. + */ +__isl_give isl_basic_map *isl_basic_map_drop(__isl_take isl_basic_map *bmap, + enum isl_dim_type type, unsigned first, unsigned n) +{ + if (!bmap) + return NULL; + if (n == 0 && !isl_space_is_named_or_nested(bmap->dim, type)) + return bmap; + + bmap = isl_basic_map_cow(bmap); + if (!bmap) + return NULL; - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + bmap = isl_basic_map_drop_core(bmap, type, first, n); + bmap = isl_basic_map_simplify(bmap); return isl_basic_map_finalize(bmap); -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_basic_set *isl_basic_set_drop(__isl_take isl_basic_set *bset, @@ -2267,25 +2421,31 @@ { return bset_from_bmap(isl_basic_map_drop(bset_to_bmap(bset), type, first, n)); +} + +/* No longer consider "map" to be normalized. + */ +static __isl_give isl_map *isl_map_unmark_normalized(__isl_take isl_map *map) +{ + if (!map) + return NULL; + ISL_F_CLR(map, ISL_MAP_NORMALIZED); + return map; } __isl_give isl_map *isl_map_drop(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n) { int i; - - if (!map) - goto error; + isl_space *space; - isl_assert(map->ctx, first + n <= isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, first, n) < 0) + return isl_map_free(map); if (n == 0 && !isl_space_is_named_or_nested(map->dim, type)) return map; map = isl_map_cow(map); if (!map) - goto error; - map->dim = isl_space_drop_dims(map->dim, type, first, n); - if (!map->dim) goto error; for (i = 0; i < map->n; ++i) { @@ -2293,8 +2453,12 @@ if (!map->p[i]) goto error; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); + space = isl_map_take_space(map); + space = isl_space_drop_dims(space, type, first, n); + map = isl_map_restore_space(map, space); + return map; error: isl_map_free(map); @@ -2307,54 +2471,16 @@ return set_from_map(isl_map_drop(set_to_map(set), type, first, n)); } -/* - * We don't cow, as the div is assumed to be redundant. +/* Drop the integer division at position "div", which is assumed + * not to appear in any of the constraints or + * in any of the other integer divisions. + * + * Since the integer division is redundant, there is no need to cow. */ __isl_give isl_basic_map *isl_basic_map_drop_div( __isl_take isl_basic_map *bmap, unsigned div) { - int i; - unsigned pos; - - if (!bmap) - goto error; - - pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div; - - isl_assert(bmap->ctx, div < bmap->n_div, goto error); - - for (i = 0; i < bmap->n_eq; ++i) - constraint_drop_vars(bmap->eq[i]+pos, 1, bmap->extra-div-1); - - for (i = 0; i < bmap->n_ineq; ++i) { - if (!isl_int_is_zero(bmap->ineq[i][pos])) { - isl_basic_map_drop_inequality(bmap, i); - --i; - continue; - } - constraint_drop_vars(bmap->ineq[i]+pos, 1, bmap->extra-div-1); - } - - for (i = 0; i < bmap->n_div; ++i) - constraint_drop_vars(bmap->div[i]+1+pos, 1, bmap->extra-div-1); - - if (div != bmap->n_div - 1) { - int j; - isl_int *t = bmap->div[div]; - - for (j = div; j < bmap->n_div - 1; ++j) - bmap->div[j] = bmap->div[j+1]; - - bmap->div[bmap->n_div - 1] = t; - } - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); - if (isl_basic_map_free_div(bmap, 1) < 0) - return isl_basic_map_free(bmap); - - return bmap; -error: - isl_basic_map_free(bmap); - return NULL; + return isl_basic_map_drop_core(bmap, isl_dim_div, div, 1); } /* Eliminate the specified n dimensions starting at first from the @@ -2366,14 +2492,11 @@ { int i; - if (!map) - return NULL; if (n == 0) return map; - if (first + n > isl_map_dim(map, type) || first + n < first) - isl_die(map->ctx, isl_error_invalid, - "index out of bounds", goto error); + if (isl_map_check_range(map, type, first, n) < 0) + return isl_map_free(map); map = isl_map_cow(map); if (!map) @@ -2413,10 +2536,12 @@ __isl_give isl_basic_map *isl_basic_map_remove_divs( __isl_take isl_basic_map *bmap) { - if (!bmap) - return NULL; - bmap = isl_basic_map_eliminate_vars(bmap, - isl_space_dim(bmap->dim, isl_dim_all), bmap->n_div); + isl_size v_div; + + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); + bmap = isl_basic_map_eliminate_vars(bmap, v_div, bmap->n_div); if (!bmap) return NULL; bmap->n_div = 0; @@ -2599,7 +2724,6 @@ isl_int_set_si(bmap->ineq[k][1 + total + div], -1); } - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); return bmap; error: isl_basic_map_free(bmap); @@ -2657,7 +2781,7 @@ int i; int check_lb, check_ub; isl_int v; - unsigned total; + isl_size v_div; if (!bmap) return NULL; @@ -2665,12 +2789,14 @@ if (isl_int_is_zero(bmap->div[div][0])) return bmap; - total = isl_space_dim(bmap->dim, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); check_lb = 0; check_ub = 0; for (i = 0; (!check_lb || !check_ub) && i < bmap->n_ineq; ++i) { - int s = isl_int_sgn(bmap->ineq[i][1 + total + div]); + int s = isl_int_sgn(bmap->ineq[i][1 + v_div + div]); if (s > 0) check_ub = 1; if (s < 0) @@ -2683,10 +2809,10 @@ isl_int_init(v); for (i = 0; bmap && i < bmap->n_ineq; ++i) { - if (!isl_int_is_zero(bmap->ineq[i][1 + total + div])) + if (!isl_int_is_zero(bmap->ineq[i][1 + v_div + div])) continue; - bmap = insert_bounds_on_div_from_ineq(bmap, div, i, total, v, + bmap = insert_bounds_on_div_from_ineq(bmap, div, i, v_div, v, check_lb, check_ub); } @@ -2802,13 +2928,9 @@ { int i; - if (!map) + if (isl_map_check_range(map, type, first, n) < 0) return isl_bool_error; - if (first + n > isl_map_dim(map, type)) - isl_die(map->ctx, isl_error_invalid, - "index out of bounds", return isl_bool_error); - for (i = 0; i < map->n; ++i) { isl_bool involves = isl_basic_map_involves_dims(map->p[i], type, first, n); @@ -2833,8 +2955,12 @@ /* Drop all constraints in bmap that involve any of the dimensions * first to first+n-1. + * This function only performs the actual removal of constraints. + * + * This function should not call finalize since it is used by + * remove_redundant_divs, which in turn is called by isl_basic_map_finalize. */ -static __isl_give isl_basic_map *isl_basic_map_drop_constraints_involving( +__isl_give isl_basic_map *isl_basic_map_drop_constraints_involving( __isl_take isl_basic_map *bmap, unsigned first, unsigned n) { int i; @@ -2850,21 +2976,23 @@ for (i = bmap->n_eq - 1; i >= 0; --i) { if (isl_seq_first_non_zero(bmap->eq[i] + 1 + first, n) == -1) continue; - isl_basic_map_drop_equality(bmap, i); + if (isl_basic_map_drop_equality(bmap, i) < 0) + return isl_basic_map_free(bmap); } for (i = bmap->n_ineq - 1; i >= 0; --i) { if (isl_seq_first_non_zero(bmap->ineq[i] + 1 + first, n) == -1) continue; - isl_basic_map_drop_inequality(bmap, i); + if (isl_basic_map_drop_inequality(bmap, i) < 0) + return isl_basic_map_free(bmap); } - bmap = isl_basic_map_add_known_div_constraints(bmap); return bmap; } /* Drop all constraints in bset that involve any of the dimensions * first to first+n-1. + * This function only performs the actual removal of constraints. */ __isl_give isl_basic_set *isl_basic_set_drop_constraints_involving( __isl_take isl_basic_set *bset, unsigned first, unsigned n) @@ -2898,13 +3026,15 @@ for (i = bmap->n_eq - 1; i >= 0; --i) { if (isl_seq_first_non_zero(bmap->eq[i] + 1 + first, n) != -1) continue; - isl_basic_map_drop_equality(bmap, i); + if (isl_basic_map_drop_equality(bmap, i) < 0) + return isl_basic_map_free(bmap); } for (i = bmap->n_ineq - 1; i >= 0; --i) { if (isl_seq_first_non_zero(bmap->ineq[i] + 1 + first, n) != -1) continue; - isl_basic_map_drop_inequality(bmap, i); + if (isl_basic_map_drop_inequality(bmap, i) < 0) + return isl_basic_map_free(bmap); } bmap = isl_basic_map_add_known_div_constraints(bmap); @@ -2939,7 +3069,9 @@ bmap = isl_basic_map_remove_divs_involving_dims(bmap, type, first, n); first += isl_basic_map_offset(bmap, type) - 1; - return isl_basic_map_drop_constraints_involving(bmap, first, n); + bmap = isl_basic_map_drop_constraints_involving(bmap, first, n); + bmap = isl_basic_map_add_known_div_constraints(bmap); + return bmap; } /* Drop all constraints in bset that involve any of the dimensions @@ -2961,15 +3093,9 @@ enum isl_dim_type type, unsigned first, unsigned n)) { int i; - unsigned dim; - - if (!map) - return NULL; - dim = isl_map_dim(map, type); - if (first + n > dim || first + n < first) - isl_die(isl_map_get_ctx(map), isl_error_invalid, - "index out of bounds", return isl_map_free(map)); + if (isl_map_check_range(map, type, first, n) < 0) + return isl_map_free(map); map = isl_map_cow(map); if (!map) @@ -3142,9 +3268,8 @@ return map; map = isl_map_cow(map); - if (!map) - return NULL; - isl_assert(map->ctx, first + n <= isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, first, n) < 0) + return isl_map_free(map); for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_eliminate_vars(map->p[i], @@ -3173,175 +3298,79 @@ return isl_map_remove_dims(map, isl_dim_in, first, n); } -static void dump_term(struct isl_basic_map *bmap, - isl_int c, int pos, FILE *out) +void isl_basic_set_print_internal(struct isl_basic_set *bset, + FILE *out, int indent) { - const char *name; - unsigned in = isl_basic_map_dim(bmap, isl_dim_in); - unsigned dim = in + isl_basic_map_dim(bmap, isl_dim_out); - unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param); - if (!pos) - isl_int_print(out, c, 0); - else { - if (!isl_int_is_one(c)) - isl_int_print(out, c, 0); - if (pos < 1 + nparam) { - name = isl_space_get_dim_name(bmap->dim, - isl_dim_param, pos - 1); - if (name) - fprintf(out, "%s", name); - else - fprintf(out, "p%d", pos - 1); - } else if (pos < 1 + nparam + in) - fprintf(out, "i%d", pos - 1 - nparam); - else if (pos < 1 + nparam + dim) - fprintf(out, "o%d", pos - 1 - nparam - in); - else - fprintf(out, "e%d", pos - 1 - nparam - dim); + isl_printer *p; + + if (!bset) { + fprintf(out, "null basic set\n"); + return; } -} -static void dump_constraint_sign(struct isl_basic_map *bmap, isl_int *c, - int sign, FILE *out) -{ - int i; - int first; - unsigned len = 1 + isl_basic_map_total_dim(bmap); - isl_int v; + fprintf(out, "%*s", indent, ""); + fprintf(out, "ref: %d, nparam: %d, dim: %d, extra: %d, flags: %x\n", + bset->ref, bset->dim->nparam, bset->dim->n_out, + bset->extra, bset->flags); - isl_int_init(v); - for (i = 0, first = 1; i < len; ++i) { - if (isl_int_sgn(c[i]) * sign <= 0) - continue; - if (!first) - fprintf(out, " + "); - first = 0; - isl_int_abs(v, c[i]); - dump_term(bmap, v, i, out); - } - isl_int_clear(v); - if (first) - fprintf(out, "0"); + p = isl_printer_to_file(isl_basic_set_get_ctx(bset), out); + p = isl_printer_set_dump(p, 1); + p = isl_printer_set_indent(p, indent); + p = isl_printer_start_line(p); + p = isl_printer_print_basic_set(p, bset); + p = isl_printer_end_line(p); + isl_printer_free(p); } -static void dump_constraint(struct isl_basic_map *bmap, isl_int *c, - const char *op, FILE *out, int indent) +void isl_basic_map_print_internal(struct isl_basic_map *bmap, + FILE *out, int indent) { - int i; + isl_printer *p; + + if (!bmap) { + fprintf(out, "null basic map\n"); + return; + } fprintf(out, "%*s", indent, ""); + fprintf(out, "ref: %d, nparam: %d, in: %d, out: %d, extra: %d, " + "flags: %x, n_name: %d\n", + bmap->ref, + bmap->dim->nparam, bmap->dim->n_in, bmap->dim->n_out, + bmap->extra, bmap->flags, bmap->dim->n_id); - dump_constraint_sign(bmap, c, 1, out); - fprintf(out, " %s ", op); - dump_constraint_sign(bmap, c, -1, out); + p = isl_printer_to_file(isl_basic_map_get_ctx(bmap), out); + p = isl_printer_set_dump(p, 1); + p = isl_printer_set_indent(p, indent); + p = isl_printer_start_line(p); + p = isl_printer_print_basic_map(p, bmap); + p = isl_printer_end_line(p); + isl_printer_free(p); +} - fprintf(out, "\n"); +__isl_give isl_basic_map *isl_inequality_negate(__isl_take isl_basic_map *bmap, + unsigned pos) +{ + isl_size total; - for (i = bmap->n_div; i < bmap->extra; ++i) { - if (isl_int_is_zero(c[1+isl_space_dim(bmap->dim, isl_dim_all)+i])) - continue; - fprintf(out, "%*s", indent, ""); - fprintf(out, "ERROR: unused div coefficient not zero\n"); - abort(); - } -} - -static void dump_constraints(struct isl_basic_map *bmap, - isl_int **c, unsigned n, - const char *op, FILE *out, int indent) -{ - int i; - - for (i = 0; i < n; ++i) - dump_constraint(bmap, c[i], op, out, indent); -} - -static void dump_affine(struct isl_basic_map *bmap, isl_int *exp, FILE *out) -{ - int j; - int first = 1; - unsigned total = isl_basic_map_total_dim(bmap); - - for (j = 0; j < 1 + total; ++j) { - if (isl_int_is_zero(exp[j])) - continue; - if (!first && isl_int_is_pos(exp[j])) - fprintf(out, "+"); - dump_term(bmap, exp[j], j, out); - first = 0; - } -} - -static void dump(struct isl_basic_map *bmap, FILE *out, int indent) -{ - int i; - - dump_constraints(bmap, bmap->eq, bmap->n_eq, "=", out, indent); - dump_constraints(bmap, bmap->ineq, bmap->n_ineq, ">=", out, indent); - - for (i = 0; i < bmap->n_div; ++i) { - fprintf(out, "%*s", indent, ""); - fprintf(out, "e%d = [(", i); - dump_affine(bmap, bmap->div[i]+1, out); - fprintf(out, ")/"); - isl_int_print(out, bmap->div[i][0], 0); - fprintf(out, "]\n"); - } -} - -void isl_basic_set_print_internal(struct isl_basic_set *bset, - FILE *out, int indent) -{ - if (!bset) { - fprintf(out, "null basic set\n"); - return; - } - - fprintf(out, "%*s", indent, ""); - fprintf(out, "ref: %d, nparam: %d, dim: %d, extra: %d, flags: %x\n", - bset->ref, bset->dim->nparam, bset->dim->n_out, - bset->extra, bset->flags); - dump(bset_to_bmap(bset), out, indent); -} - -void isl_basic_map_print_internal(struct isl_basic_map *bmap, - FILE *out, int indent) -{ - if (!bmap) { - fprintf(out, "null basic map\n"); - return; - } - - fprintf(out, "%*s", indent, ""); - fprintf(out, "ref: %d, nparam: %d, in: %d, out: %d, extra: %d, " - "flags: %x, n_name: %d\n", - bmap->ref, - bmap->dim->nparam, bmap->dim->n_in, bmap->dim->n_out, - bmap->extra, bmap->flags, bmap->dim->n_id); - dump(bmap, out, indent); -} - -int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos) -{ - unsigned total; - if (!bmap) - return -1; - total = isl_basic_map_total_dim(bmap); - isl_assert(bmap->ctx, pos < bmap->n_ineq, return -1); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); + if (pos >= bmap->n_ineq) + isl_die(isl_basic_map_get_ctx(bmap), isl_error_invalid, + "invalid position", return isl_basic_map_free(bmap)); isl_seq_neg(bmap->ineq[pos], bmap->ineq[pos], 1 + total); isl_int_sub_ui(bmap->ineq[pos][0], bmap->ineq[pos][0], 1); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); - return 0; + ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); + return bmap; } __isl_give isl_set *isl_set_alloc_space(__isl_take isl_space *space, int n, unsigned flags) { - if (!space) - return NULL; - if (isl_space_dim(space, isl_dim_in) != 0) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "set cannot have input dimensions", goto error); + if (isl_space_check_is_set(space) < 0) + goto error; return isl_map_alloc_space(space, n, flags); error: isl_space_free(space); @@ -3457,11 +3486,15 @@ __isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset) { struct isl_basic_map *bmap_domain; + isl_size dim; if (isl_basic_map_check_equal_params(bmap, bset_to_bmap(bset)) < 0) goto error; - if (isl_space_dim(bset->dim, isl_dim_set) != 0) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + goto error; + if (dim != 0) isl_assert(bset->ctx, isl_basic_map_compatible_domain(bmap, bset), goto error); @@ -3502,13 +3535,16 @@ __isl_take isl_basic_map *bmap, __isl_take isl_basic_set *bset) { struct isl_basic_map *bmap_range; + isl_size dim; if (isl_basic_map_check_equal_params(bmap, bset_to_bmap(bset)) < 0) goto error; - if (isl_space_dim(bset->dim, isl_dim_set) != 0 && - isl_basic_map_check_compatible_range(bmap, bset) < 0) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) goto error; + if (dim != 0 && isl_basic_map_check_compatible_range(bmap, bset) < 0) + goto error; if (isl_basic_set_plain_is_universe(bset)) { isl_basic_set_free(bset); @@ -3535,20 +3571,20 @@ __isl_keep isl_vec *vec) { int i; - unsigned total; + isl_size total; isl_int s; - if (!bmap || !vec) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0 || !vec) return isl_bool_error; - total = 1 + isl_basic_map_total_dim(bmap); - if (total != vec->size) + if (1 + total != vec->size) return isl_bool_false; isl_int_init(s); for (i = 0; i < bmap->n_eq; ++i) { - isl_seq_inner_product(vec->el, bmap->eq[i], total, &s); + isl_seq_inner_product(vec->el, bmap->eq[i], 1 + total, &s); if (!isl_int_is_zero(s)) { isl_int_clear(s); return isl_bool_false; @@ -3556,7 +3592,7 @@ } for (i = 0; i < bmap->n_ineq; ++i) { - isl_seq_inner_product(vec->el, bmap->ineq[i], total, &s); + isl_seq_inner_product(vec->el, bmap->ineq[i], 1 + total, &s); if (isl_int_is_neg(s)) { isl_int_clear(s); return isl_bool_false; @@ -3578,17 +3614,23 @@ __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { struct isl_vec *sample = NULL; + isl_space *space1, *space2; + isl_size dim1, dim2, nparam1, nparam2; if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0) goto error; - if (isl_space_dim(bmap1->dim, isl_dim_all) == - isl_space_dim(bmap1->dim, isl_dim_param) && - isl_space_dim(bmap2->dim, isl_dim_all) != - isl_space_dim(bmap2->dim, isl_dim_param)) + space1 = isl_basic_map_peek_space(bmap1); + space2 = isl_basic_map_peek_space(bmap2); + dim1 = isl_space_dim(space1, isl_dim_all); + dim2 = isl_space_dim(space2, isl_dim_all); + nparam1 = isl_space_dim(space1, isl_dim_param); + nparam2 = isl_space_dim(space2, isl_dim_param); + if (dim1 < 0 || dim2 < 0 || nparam1 < 0 || nparam2 < 0) + goto error; + if (dim1 == nparam1 && dim2 != nparam2) return isl_basic_map_intersect(bmap2, bmap1); - if (isl_space_dim(bmap2->dim, isl_dim_all) != - isl_space_dim(bmap2->dim, isl_dim_param)) + if (dim2 != nparam2) isl_assert(bmap1->ctx, isl_space_is_equal(bmap1->dim, bmap2->dim), goto error); @@ -3670,7 +3712,6 @@ isl_map_free(map2); return map1; } - map1->p[0] = isl_basic_map_cow(map1->p[0]); if (map2->p[0]->n_eq == 1) map1->p[0] = isl_basic_map_add_eq(map1->p[0], map2->p[0]->eq[0]); else @@ -3689,6 +3730,7 @@ isl_map_free(map2); + map1 = isl_map_unmark_normalized(map1); return map1; error: isl_map_free(map1); @@ -3703,8 +3745,10 @@ __isl_take isl_map *map2) { unsigned flags = 0; + isl_bool equal; isl_map *result; int i, j; + isl_size dim2, nparam2; if (!map1 || !map2) goto error; @@ -3728,9 +3772,20 @@ (map1->p[0]->n_eq + map1->p[0]->n_ineq == 1 || map2->p[0]->n_eq + map2->p[0]->n_ineq == 1)) return map_intersect_add_constraint(map1, map2); + + equal = isl_map_plain_is_equal(map1, map2); + if (equal < 0) + goto error; + if (equal) { + isl_map_free(map2); + return map1; + } - if (isl_space_dim(map2->dim, isl_dim_all) != - isl_space_dim(map2->dim, isl_dim_param)) + dim2 = isl_map_dim(map2, isl_dim_all); + nparam2 = isl_map_dim(map2, isl_dim_param); + if (dim2 < 0 || nparam2 < 0) + goto error; + if (dim2 != nparam2) isl_assert(map1->ctx, isl_space_is_equal(map1->dim, map2->dim), goto error); @@ -3814,7 +3869,8 @@ __isl_give isl_basic_map *isl_basic_map_reverse(__isl_take isl_basic_map *bmap) { isl_space *space; - unsigned pos, n1, n2; + unsigned pos; + isl_size n1, n2; if (!bmap) return NULL; @@ -3825,8 +3881,37 @@ pos = isl_basic_map_offset(bmap, isl_dim_in); n1 = isl_basic_map_dim(bmap, isl_dim_in); n2 = isl_basic_map_dim(bmap, isl_dim_out); + if (n1 < 0 || n2 < 0) + bmap = isl_basic_map_free(bmap); bmap = isl_basic_map_swap_vars(bmap, pos, n1, n2); return isl_basic_map_reset_space(bmap, space); +} + +/* Given a basic map A -> (B -> C), return the corresponding basic map + * A -> (C -> B). + */ +static __isl_give isl_basic_map *isl_basic_map_range_reverse( + __isl_take isl_basic_map *bmap) +{ + isl_space *space; + isl_size offset, n1, n2; + + space = isl_basic_map_peek_space(bmap); + if (isl_space_check_range_is_wrapping(space) < 0) + return isl_basic_map_free(bmap); + offset = isl_basic_map_var_offset(bmap, isl_dim_out); + n1 = isl_space_wrapped_dim(space, isl_dim_out, isl_dim_in); + n2 = isl_space_wrapped_dim(space, isl_dim_out, isl_dim_out); + if (offset < 0 || n1 < 0 || n2 < 0) + return isl_basic_map_free(bmap); + + bmap = isl_basic_map_swap_vars(bmap, 1 + offset, n1, n2); + + space = isl_basic_map_take_space(bmap); + space = isl_space_range_reverse(space); + bmap = isl_basic_map_restore_space(bmap, space); + + return bmap; } static __isl_give isl_basic_map *basic_map_space_reset( @@ -3849,50 +3934,60 @@ __isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned pos, unsigned n) { - isl_bool rational; - isl_space *res_dim; + isl_bool rational, is_empty; + isl_space *res_space; struct isl_basic_map *res; struct isl_dim_map *dim_map; - unsigned total, off; + isl_size total; + unsigned off; enum isl_dim_type t; if (n == 0) return basic_map_space_reset(bmap, type); - - if (!bmap) - return NULL; - res_dim = isl_space_insert_dims(isl_basic_map_get_space(bmap), type, pos, n); + is_empty = isl_basic_map_plain_is_empty(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (is_empty < 0 || total < 0) + return isl_basic_map_free(bmap); + res_space = isl_space_insert_dims(isl_basic_map_get_space(bmap), + type, pos, n); + if (!res_space) + return isl_basic_map_free(bmap); + if (is_empty) { + isl_basic_map_free(bmap); + return isl_basic_map_empty(res_space); + } - total = isl_basic_map_total_dim(bmap) + n; - dim_map = isl_dim_map_alloc(bmap->ctx, total); + dim_map = isl_dim_map_alloc(bmap->ctx, total + n); off = 0; for (t = isl_dim_param; t <= isl_dim_out; ++t) { + isl_size dim; + if (t != type) { isl_dim_map_dim(dim_map, bmap->dim, t, off); } else { - unsigned size = isl_basic_map_dim(bmap, t); + isl_size size = isl_basic_map_dim(bmap, t); + if (size < 0) + dim_map = isl_dim_map_free(dim_map); isl_dim_map_dim_range(dim_map, bmap->dim, t, 0, pos, off); isl_dim_map_dim_range(dim_map, bmap->dim, t, pos, size - pos, off + pos + n); } - off += isl_space_dim(res_dim, t); + dim = isl_space_dim(res_space, t); + if (dim < 0) + dim_map = isl_dim_map_free(dim_map); + off += dim; } isl_dim_map_div(dim_map, bmap, off); - res = isl_basic_map_alloc_space(res_dim, + res = isl_basic_map_alloc_space(res_space, bmap->n_div, bmap->n_eq, bmap->n_ineq); rational = isl_basic_map_is_rational(bmap); if (rational < 0) res = isl_basic_map_free(res); if (rational) res = isl_basic_map_set_rational(res); - if (isl_basic_map_plain_is_empty(bmap)) { - isl_basic_map_free(bmap); - free(dim_map); - return isl_basic_map_set_to_empty(res); - } res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map); return isl_basic_map_finalize(res); } @@ -3907,10 +4002,12 @@ __isl_give isl_basic_map *isl_basic_map_add_dims(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned n) { - if (!bmap) - return NULL; - return isl_basic_map_insert_dims(bmap, type, - isl_basic_map_dim(bmap, type), n); + isl_size dim; + + dim = isl_basic_map_dim(bmap, type); + if (dim < 0) + return isl_basic_map_free(bmap); + return isl_basic_map_insert_dims(bmap, type, dim, n); } __isl_give isl_basic_set *isl_basic_set_add_dims(__isl_take isl_basic_set *bset, @@ -3943,6 +4040,7 @@ enum isl_dim_type type, unsigned pos, unsigned n) { int i; + isl_space *space; if (n == 0) return map_space_reset(map, type); @@ -3951,15 +4049,15 @@ if (!map) return NULL; - map->dim = isl_space_insert_dims(map->dim, type, pos, n); - if (!map->dim) - goto error; - for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_insert_dims(map->p[i], type, pos, n); if (!map->p[i]) goto error; } + + space = isl_map_take_space(map); + space = isl_space_insert_dims(space, type, pos, n); + map = isl_map_restore_space(map, space); return map; error: @@ -3976,9 +4074,12 @@ __isl_give isl_map *isl_map_add_dims(__isl_take isl_map *map, enum isl_dim_type type, unsigned n) { - if (!map) - return NULL; - return isl_map_insert_dims(map, type, isl_map_dim(map, type), n); + isl_size dim; + + dim = isl_map_dim(map, type); + if (dim < 0) + return isl_map_free(map); + return isl_map_insert_dims(map, type, dim, n); } __isl_give isl_set *isl_set_add_dims(__isl_take isl_set *set, @@ -3998,10 +4099,12 @@ enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n) { + isl_space *space; struct isl_dim_map *dim_map; struct isl_basic_map *res; enum isl_dim_type t; - unsigned total, off; + isl_size total; + unsigned off; if (!bmap) return NULL; @@ -4022,45 +4125,45 @@ if (pos(bmap->dim, dst_type) + dst_pos == pos(bmap->dim, src_type) + src_pos + ((src_type < dst_type) ? n : 0)) { - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; - - bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos, + space = isl_basic_map_take_space(bmap); + space = isl_space_move_dims(space, dst_type, dst_pos, src_type, src_pos, n); - if (!bmap->dim) - goto error; - + bmap = isl_basic_map_restore_space(bmap, space); bmap = isl_basic_map_finalize(bmap); return bmap; } - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); dim_map = isl_dim_map_alloc(bmap->ctx, total); off = 0; + space = isl_basic_map_peek_space(bmap); for (t = isl_dim_param; t <= isl_dim_out; ++t) { - unsigned size = isl_space_dim(bmap->dim, t); + isl_size size = isl_space_dim(space, t); + if (size < 0) + dim_map = isl_dim_map_free(dim_map); if (t == dst_type) { - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, 0, dst_pos, off); off += dst_pos; - isl_dim_map_dim_range(dim_map, bmap->dim, src_type, + isl_dim_map_dim_range(dim_map, space, src_type, src_pos, n, off); off += n; - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, dst_pos, size - dst_pos, off); off += size - dst_pos; } else if (t == src_type) { - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, 0, src_pos, off); off += src_pos; - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, src_pos + n, size - src_pos - n, off); off += size - src_pos - n; } else { - isl_dim_map_dim(dim_map, bmap->dim, t, off); + isl_dim_map_dim(dim_map, space, t, off); off += size; } } @@ -4069,15 +4172,14 @@ res = isl_basic_map_alloc_space(isl_basic_map_get_space(bmap), bmap->n_div, bmap->n_eq, bmap->n_ineq); bmap = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map); - if (!bmap) - goto error; - - bmap->dim = isl_space_move_dims(bmap->dim, dst_type, dst_pos, + space = isl_basic_map_take_space(bmap); + space = isl_space_move_dims(space, dst_type, dst_pos, src_type, src_pos, n); - if (!bmap->dim) + bmap = isl_basic_map_restore_space(bmap, space); + if (!bmap) goto error; - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); bmap = isl_basic_map_gauss(bmap, NULL); bmap = isl_basic_map_finalize(bmap); @@ -4116,17 +4218,16 @@ enum isl_dim_type src_type, unsigned src_pos, unsigned n) { int i; + isl_space *space; - if (!map) - return NULL; if (n == 0) { map = isl_map_reset(map, src_type); map = isl_map_reset(map, dst_type); return map; } - isl_assert(map->ctx, src_pos + n <= isl_map_dim(map, src_type), - goto error); + if (isl_map_check_range(map, src_type, src_pos, n)) + return isl_map_free(map); if (dst_type == src_type && dst_pos == src_pos) return map; @@ -4137,10 +4238,6 @@ if (!map) return NULL; - map->dim = isl_space_move_dims(map->dim, dst_type, dst_pos, src_type, src_pos, n); - if (!map->dim) - goto error; - for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_move_dims(map->p[i], dst_type, dst_pos, @@ -4148,6 +4245,11 @@ if (!map->p[i]) goto error; } + + space = isl_map_take_space(map); + space = isl_space_move_dims(space, dst_type, dst_pos, + src_type, src_pos, n); + map = isl_map_restore_space(map, space); return map; error: @@ -4162,34 +4264,41 @@ static __isl_give isl_basic_map *move_last(__isl_take isl_basic_map *bmap, enum isl_dim_type type, unsigned first, unsigned n) { + isl_space *space; struct isl_dim_map *dim_map; struct isl_basic_map *res; enum isl_dim_type t; - unsigned total, off; + isl_size total; + unsigned off; if (!bmap) return NULL; - if (pos(bmap->dim, type) + first + n == - 1 + isl_space_dim(bmap->dim, isl_dim_all)) + if (isl_basic_map_offset(bmap, type) + first + n == + isl_basic_map_offset(bmap, isl_dim_div)) return bmap; - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); dim_map = isl_dim_map_alloc(bmap->ctx, total); off = 0; + space = isl_basic_map_peek_space(bmap); for (t = isl_dim_param; t <= isl_dim_out; ++t) { - unsigned size = isl_space_dim(bmap->dim, t); + isl_size size = isl_space_dim(space, t); + if (size < 0) + dim_map = isl_dim_map_free(dim_map); if (t == type) { - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, 0, first, off); off += first; - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, first, n, total - bmap->n_div - n); - isl_dim_map_dim_range(dim_map, bmap->dim, t, + isl_dim_map_dim_range(dim_map, space, t, first + n, size - (first + n), off); off += size - (first + n); } else { - isl_dim_map_dim(dim_map, bmap->dim, t, off); + isl_dim_map_dim(dim_map, space, t, off); off += size; } } @@ -4221,7 +4330,7 @@ if (!bmap) return NULL; - row_size = 1 + isl_space_dim(bmap->dim, isl_dim_all) + bmap->extra; + row_size = isl_basic_map_offset(bmap, isl_dim_div) + bmap->extra; old = bmap->block2.data; bmap->block2 = isl_blk_extend(bmap->ctx, bmap->block2, (bmap->extra + n) * (1 + row_size)); @@ -4258,7 +4367,7 @@ { int i; int *groups; - unsigned dim, n_div; + isl_size dim, n_div; isl_bool non_empty; non_empty = isl_basic_map_plain_is_non_empty(bmap); @@ -4269,6 +4378,8 @@ dim = isl_basic_map_dim(bmap, isl_dim_all); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (dim < 0 || n_div < 0) + return isl_basic_map_free(bmap); groups = isl_calloc_array(isl_basic_map_get_ctx(bmap), int, dim); if (!groups) return isl_basic_map_free(bmap); @@ -4295,6 +4406,7 @@ enum isl_dim_type type, unsigned first, unsigned n) { isl_bool empty; + isl_space *space; if (n == 0) return basic_map_space_reset(bmap, type); @@ -4322,18 +4434,13 @@ bmap = move_last(bmap, type, first, n); bmap = isl_basic_map_cow(bmap); bmap = insert_div_rows(bmap, n); - if (!bmap) - return NULL; - bmap->dim = isl_space_drop_dims(bmap->dim, type, first, n); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_drop_dims(space, type, first, n); + bmap = isl_basic_map_restore_space(bmap, space); bmap = isl_basic_map_simplify(bmap); bmap = isl_basic_map_drop_redundant_divs(bmap); return isl_basic_map_finalize(bmap); -error: - isl_basic_map_free(bmap); - return NULL; } /* Turn the n dimensions of type type, starting at first @@ -4353,33 +4460,56 @@ enum isl_dim_type type, unsigned first, unsigned n) { int i; - - if (!map) - return NULL; + isl_space *space; if (n == 0) return map_space_reset(map, type); - isl_assert(map->ctx, first + n <= isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, first, n) < 0) + return isl_map_free(map); map = isl_map_cow(map); if (!map) return NULL; - - map->dim = isl_space_drop_dims(map->dim, type, first, n); - if (!map->dim) - goto error; for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_project_out(map->p[i], type, first, n); if (!map->p[i]) goto error; } + + if (map->n > 1) + ISL_F_CLR(map, ISL_MAP_DISJOINT); + map = isl_map_unmark_normalized(map); + + space = isl_map_take_space(map); + space = isl_space_drop_dims(space, type, first, n); + map = isl_map_restore_space(map, space); return map; error: isl_map_free(map); return NULL; +} + +#undef TYPE +#define TYPE isl_map +#include "isl_project_out_all_params_templ.c" + +/* Turn all the dimensions of type "type", except the "n" starting at "first" + * into existentially quantified variables. + */ +__isl_give isl_map *isl_map_project_onto(__isl_take isl_map *map, + enum isl_dim_type type, unsigned first, unsigned n) +{ + isl_size dim; + + dim = isl_map_dim(map, type); + if (isl_map_check_range(map, type, first, n) < 0 || dim < 0) + return isl_map_free(map); + map = isl_map_project_out(map, type, first + n, dim - (first + n)); + map = isl_map_project_out(map, type, 0, first); + return map; } /* Turn the n dimensions of type type, starting at first @@ -4390,6 +4520,62 @@ { return set_from_map(isl_map_project_out(set_to_map(set), type, first, n)); +} + +/* If "set" involves a parameter with identifier "id", + * then turn it into an existentially quantified variable. + */ +__isl_give isl_set *isl_set_project_out_param_id(__isl_take isl_set *set, + __isl_take isl_id *id) +{ + int pos; + + if (!set || !id) + goto error; + pos = isl_set_find_dim_by_id(set, isl_dim_param, id); + isl_id_free(id); + if (pos < 0) + return set; + return isl_set_project_out(set, isl_dim_param, pos, 1); +error: + isl_set_free(set); + isl_id_free(id); + return NULL; +} + +/* If "set" involves any of the parameters with identifiers in "list", + * then turn them into existentially quantified variables. + */ +__isl_give isl_set *isl_set_project_out_param_id_list(__isl_take isl_set *set, + __isl_take isl_id_list *list) +{ + int i; + isl_size n; + + n = isl_id_list_size(list); + if (n < 0) + goto error; + for (i = 0; i < n; ++i) { + isl_id *id; + + id = isl_id_list_get_at(list, i); + set = isl_set_project_out_param_id(set, id); + } + + isl_id_list_free(list); + return set; +error: + isl_id_list_free(list); + isl_set_free(set); + return NULL; +} + +/* Project out all parameters from "set" by existentially quantifying + * over them. + */ +__isl_give isl_set *isl_set_project_out_all_params(__isl_take isl_set *set) +{ + return set_from_map(isl_map_project_out_all_params(set_to_map(set))); } /* Return a map that projects the elements in "set" onto their @@ -4400,18 +4586,13 @@ enum isl_dim_type type, unsigned first, unsigned n) { int i; - int dim; isl_map *map; - if (!set) - return NULL; if (type != isl_dim_set) isl_die(isl_set_get_ctx(set), isl_error_invalid, "only set dimensions can be projected out", goto error); - dim = isl_set_dim(set, isl_dim_set); - if (first + n > dim || first + n < first) - isl_die(isl_set_get_ctx(set), isl_error_invalid, - "index out of bounds", goto error); + if (isl_set_check_range(set, type, first, n) < 0) + return isl_set_free(set); map = isl_map_from_domain(set); map = isl_map_add_dims(map, isl_dim_out, n); @@ -4424,15 +4605,20 @@ return NULL; } -static struct isl_basic_map *add_divs(struct isl_basic_map *bmap, unsigned n) +static __isl_give isl_basic_map *add_divs(__isl_take isl_basic_map *bmap, + unsigned n) { int i, j; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); for (i = 0; i < n; ++i) { j = isl_basic_map_alloc_div(bmap); if (j < 0) goto error; - isl_seq_clr(bmap->div[j], 1+1+isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->div[j], 1 + 1 + total); } return bmap; error: @@ -4443,9 +4629,10 @@ struct isl_basic_map *isl_basic_map_apply_range( struct isl_basic_map *bmap1, struct isl_basic_map *bmap2) { - isl_space *dim_result = NULL; + isl_space *space_result = NULL; struct isl_basic_map *bmap; - unsigned n_in, n_out, n, nparam, total, pos; + isl_size n_in, n_out, n, nparam; + unsigned total, pos; struct isl_dim_map *dim_map1, *dim_map2; if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0) @@ -4455,14 +4642,16 @@ isl_die(isl_basic_map_get_ctx(bmap1), isl_error_invalid, "spaces don't match", goto error); - dim_result = isl_space_join(isl_space_copy(bmap1->dim), - isl_space_copy(bmap2->dim)); - n_in = isl_basic_map_dim(bmap1, isl_dim_in); n_out = isl_basic_map_dim(bmap2, isl_dim_out); n = isl_basic_map_dim(bmap1, isl_dim_out); nparam = isl_basic_map_dim(bmap1, isl_dim_param); + if (n_in < 0 || n_out < 0 || n < 0 || nparam < 0) + goto error; + space_result = isl_space_join(isl_basic_map_get_space(bmap1), + isl_basic_map_get_space(bmap2)); + total = nparam + n_in + n_out + bmap1->n_div + bmap2->n_div + n; dim_map1 = isl_dim_map_alloc(bmap1->ctx, total); dim_map2 = isl_dim_map_alloc(bmap1->ctx, total); @@ -4475,7 +4664,7 @@ isl_dim_map_dim(dim_map1, bmap1->dim, isl_dim_out, pos += bmap2->n_div); isl_dim_map_dim(dim_map2, bmap2->dim, isl_dim_in, pos); - bmap = isl_basic_map_alloc_space(dim_result, + bmap = isl_basic_map_alloc_space(space_result, bmap1->n_div + bmap2->n_div + n, bmap1->n_eq + bmap2->n_eq, bmap1->n_ineq + bmap2->n_ineq); @@ -4491,8 +4680,8 @@ return NULL; } -struct isl_basic_set *isl_basic_set_apply( - struct isl_basic_set *bset, struct isl_basic_map *bmap) +__isl_give isl_basic_set *isl_basic_set_apply(__isl_take isl_basic_set *bset, + __isl_take isl_basic_map *bmap) { if (!bset || !bmap) goto error; @@ -4533,7 +4722,8 @@ __isl_give isl_basic_map *isl_basic_map_sum(__isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { - unsigned n_in, n_out, nparam, total, pos; + isl_size n_in, n_out, nparam; + unsigned total, pos; struct isl_basic_map *bmap = NULL; struct isl_dim_map *dim_map1, *dim_map2; int i; @@ -4547,6 +4737,8 @@ nparam = isl_basic_map_dim(bmap1, isl_dim_param); n_in = isl_basic_map_dim(bmap1, isl_dim_in); n_out = isl_basic_map_dim(bmap1, isl_dim_out); + if (nparam < 0 || n_in < 0 || n_out < 0) + goto error; total = nparam + n_in + n_out + bmap1->n_div + bmap2->n_div + 2 * n_out; dim_map1 = isl_dim_map_alloc(bmap1->ctx, total); @@ -4637,13 +4829,14 @@ __isl_give isl_basic_map *isl_basic_map_neg(__isl_take isl_basic_map *bmap) { int i, j; - unsigned off, n; + unsigned off; + isl_size n; bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; - n = isl_basic_map_dim(bmap, isl_dim_out); + if (n < 0) + return isl_basic_map_free(bmap); + off = isl_basic_map_offset(bmap, isl_dim_out); for (i = 0; i < bmap->n_eq; ++i) for (j = 0; j < n; ++j) @@ -4696,17 +4889,17 @@ __isl_give isl_basic_map *isl_basic_map_floordiv(__isl_take isl_basic_map *bmap, isl_int d) { - unsigned n_in, n_out, nparam, total, pos; + isl_size n_in, n_out, nparam; + unsigned total, pos; struct isl_basic_map *result = NULL; struct isl_dim_map *dim_map; int i; - - if (!bmap) - return NULL; nparam = isl_basic_map_dim(bmap, isl_dim_param); n_in = isl_basic_map_dim(bmap, isl_dim_in); n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (nparam < 0 || n_in < 0 || n_out < 0) + return isl_basic_map_free(bmap); total = nparam + n_in + n_out + bmap->n_div + n_out; dim_map = isl_dim_map_alloc(bmap->ctx, total); @@ -4756,12 +4949,12 @@ return NULL; ISL_F_CLR(map, ISL_MAP_DISJOINT); - ISL_F_CLR(map, ISL_MAP_NORMALIZED); for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_floordiv(map->p[i], d); if (!map->p[i]) goto error; } + map = isl_map_unmark_normalized(map); return map; error: @@ -4793,15 +4986,19 @@ unsigned pos) { int i; - unsigned nparam; - unsigned n_in; + isl_size nparam; + isl_size n_in; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + if (total < 0 || nparam < 0 || n_in < 0) + return isl_basic_map_free(bmap); i = isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; - nparam = isl_basic_map_dim(bmap, isl_dim_param); - n_in = isl_basic_map_dim(bmap, isl_dim_in); - isl_seq_clr(bmap->eq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[i], 1 + total); isl_int_set_si(bmap->eq[i][1+nparam+pos], -1); isl_int_set_si(bmap->eq[i][1+nparam+n_in+pos], 1); return isl_basic_map_finalize(bmap); @@ -4816,15 +5013,19 @@ unsigned pos) { int i; - unsigned nparam; - unsigned n_in; + isl_size nparam; + isl_size n_in; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + if (total < 0 || nparam < 0 || n_in < 0) + return isl_basic_map_free(bmap); i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; - nparam = isl_basic_map_dim(bmap, isl_dim_param); - n_in = isl_basic_map_dim(bmap, isl_dim_in); - isl_seq_clr(bmap->ineq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[i], 1 + total); isl_int_set_si(bmap->ineq[i][0], -1); isl_int_set_si(bmap->ineq[i][1+nparam+pos], -1); isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], 1); @@ -4840,15 +5041,19 @@ __isl_take isl_basic_map *bmap, unsigned pos) { int i; - unsigned nparam; - unsigned n_in; + isl_size nparam; + isl_size n_in; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + if (total < 0 || nparam < 0 || n_in < 0) + return isl_basic_map_free(bmap); i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; - nparam = isl_basic_map_dim(bmap, isl_dim_param); - n_in = isl_basic_map_dim(bmap, isl_dim_in); - isl_seq_clr(bmap->ineq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[i], 1 + total); isl_int_set_si(bmap->ineq[i][1+nparam+pos], -1); isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], 1); return isl_basic_map_finalize(bmap); @@ -4863,15 +5068,19 @@ unsigned pos) { int i; - unsigned nparam; - unsigned n_in; + isl_size nparam; + isl_size n_in; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + if (total < 0 || nparam < 0 || n_in < 0) + return isl_basic_map_free(bmap); i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; - nparam = isl_basic_map_dim(bmap, isl_dim_param); - n_in = isl_basic_map_dim(bmap, isl_dim_in); - isl_seq_clr(bmap->ineq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[i], 1 + total); isl_int_set_si(bmap->ineq[i][0], -1); isl_int_set_si(bmap->ineq[i][1+nparam+pos], 1); isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], -1); @@ -4887,15 +5096,19 @@ __isl_take isl_basic_map *bmap, unsigned pos) { int i; - unsigned nparam; - unsigned n_in; + isl_size nparam; + isl_size n_in; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + if (total < 0 || nparam < 0 || n_in < 0) + return isl_basic_map_free(bmap); i = isl_basic_map_alloc_inequality(bmap); if (i < 0) goto error; - nparam = isl_basic_map_dim(bmap, isl_dim_param); - n_in = isl_basic_map_dim(bmap, isl_dim_in); - isl_seq_clr(bmap->ineq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[i], 1 + total); isl_int_set_si(bmap->ineq[i][1+nparam+pos], 1); isl_int_set_si(bmap->ineq[i][1+nparam+n_in+pos], -1); return isl_basic_map_finalize(bmap); @@ -4905,11 +5118,11 @@ } __isl_give isl_basic_map *isl_basic_map_equal( - __isl_take isl_space *dim, unsigned n_equal) + __isl_take isl_space *space, unsigned n_equal) { int i; struct isl_basic_map *bmap; - bmap = isl_basic_map_alloc_space(dim, 0, n_equal, 0); + bmap = isl_basic_map_alloc_space(space, 0, n_equal, 0); if (!bmap) return NULL; for (i = 0; i < n_equal && bmap; ++i) @@ -4917,14 +5130,14 @@ return isl_basic_map_finalize(bmap); } -/* Return a relation on of dimension "dim" expressing i_[0..pos] << o_[0..pos] +/* Return a relation on of dimension "space" expressing i_[0..pos] << o_[0..pos] */ -__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *dim, +__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *space, unsigned pos) { int i; struct isl_basic_map *bmap; - bmap = isl_basic_map_alloc_space(dim, 0, pos, 1); + bmap = isl_basic_map_alloc_space(space, 0, pos, 1); if (!bmap) return NULL; for (i = 0; i < pos && bmap; ++i) @@ -4934,29 +5147,29 @@ return isl_basic_map_finalize(bmap); } -/* Return a relation on "dim" expressing i_[0..pos] <<= o_[0..pos] +/* Return a relation on "space" expressing i_[0..pos] <<= o_[0..pos] */ __isl_give isl_basic_map *isl_basic_map_less_or_equal_at( - __isl_take isl_space *dim, unsigned pos) + __isl_take isl_space *space, unsigned pos) { int i; isl_basic_map *bmap; - bmap = isl_basic_map_alloc_space(dim, 0, pos, 1); + bmap = isl_basic_map_alloc_space(space, 0, pos, 1); for (i = 0; i < pos; ++i) bmap = var_equal(bmap, i); bmap = var_less_or_equal(bmap, pos); return isl_basic_map_finalize(bmap); } -/* Return a relation on "dim" expressing i_pos > o_pos +/* Return a relation on "space" expressing i_pos > o_pos */ -__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim, +__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *space, unsigned pos) { int i; struct isl_basic_map *bmap; - bmap = isl_basic_map_alloc_space(dim, 0, pos, 1); + bmap = isl_basic_map_alloc_space(space, 0, pos, 1); if (!bmap) return NULL; for (i = 0; i < pos && bmap; ++i) @@ -4966,53 +5179,53 @@ return isl_basic_map_finalize(bmap); } -/* Return a relation on "dim" expressing i_[0..pos] >>= o_[0..pos] +/* Return a relation on "space" expressing i_[0..pos] >>= o_[0..pos] */ __isl_give isl_basic_map *isl_basic_map_more_or_equal_at( - __isl_take isl_space *dim, unsigned pos) + __isl_take isl_space *space, unsigned pos) { int i; isl_basic_map *bmap; - bmap = isl_basic_map_alloc_space(dim, 0, pos, 1); + bmap = isl_basic_map_alloc_space(space, 0, pos, 1); for (i = 0; i < pos; ++i) bmap = var_equal(bmap, i); bmap = var_more_or_equal(bmap, pos); return isl_basic_map_finalize(bmap); } -static __isl_give isl_map *map_lex_lte_first(__isl_take isl_space *dims, +static __isl_give isl_map *map_lex_lte_first(__isl_take isl_space *space, unsigned n, int equal) { struct isl_map *map; int i; if (n == 0 && equal) - return isl_map_universe(dims); + return isl_map_universe(space); - map = isl_map_alloc_space(isl_space_copy(dims), n, ISL_MAP_DISJOINT); + map = isl_map_alloc_space(isl_space_copy(space), n, ISL_MAP_DISJOINT); for (i = 0; i + 1 < n; ++i) map = isl_map_add_basic_map(map, - isl_basic_map_less_at(isl_space_copy(dims), i)); + isl_basic_map_less_at(isl_space_copy(space), i)); if (n > 0) { if (equal) map = isl_map_add_basic_map(map, - isl_basic_map_less_or_equal_at(dims, n - 1)); + isl_basic_map_less_or_equal_at(space, n - 1)); else map = isl_map_add_basic_map(map, - isl_basic_map_less_at(dims, n - 1)); + isl_basic_map_less_at(space, n - 1)); } else - isl_space_free(dims); + isl_space_free(space); return map; } -static __isl_give isl_map *map_lex_lte(__isl_take isl_space *dims, int equal) +static __isl_give isl_map *map_lex_lte(__isl_take isl_space *space, int equal) { - if (!dims) + if (!space) return NULL; - return map_lex_lte_first(dims, dims->n_out, equal); + return map_lex_lte_first(space, space->n_out, equal); } __isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_space *dim, unsigned n) @@ -5035,38 +5248,38 @@ return map_lex_lte(isl_space_map_from_set(set_dim), 1); } -static __isl_give isl_map *map_lex_gte_first(__isl_take isl_space *dims, +static __isl_give isl_map *map_lex_gte_first(__isl_take isl_space *space, unsigned n, int equal) { struct isl_map *map; int i; if (n == 0 && equal) - return isl_map_universe(dims); + return isl_map_universe(space); - map = isl_map_alloc_space(isl_space_copy(dims), n, ISL_MAP_DISJOINT); + map = isl_map_alloc_space(isl_space_copy(space), n, ISL_MAP_DISJOINT); for (i = 0; i + 1 < n; ++i) map = isl_map_add_basic_map(map, - isl_basic_map_more_at(isl_space_copy(dims), i)); + isl_basic_map_more_at(isl_space_copy(space), i)); if (n > 0) { if (equal) map = isl_map_add_basic_map(map, - isl_basic_map_more_or_equal_at(dims, n - 1)); + isl_basic_map_more_or_equal_at(space, n - 1)); else map = isl_map_add_basic_map(map, - isl_basic_map_more_at(dims, n - 1)); + isl_basic_map_more_at(space, n - 1)); } else - isl_space_free(dims); + isl_space_free(space); return map; } -static __isl_give isl_map *map_lex_gte(__isl_take isl_space *dims, int equal) +static __isl_give isl_map *map_lex_gte(__isl_take isl_space *space, int equal) { - if (!dims) + if (!space) return NULL; - return map_lex_gte_first(dims, dims->n_out, equal); + return map_lex_gte_first(space, space->n_out, equal); } __isl_give isl_map *isl_map_lex_gt_first(__isl_take isl_space *dim, unsigned n) @@ -5169,47 +5382,59 @@ return map; } -/* For a div d = floor(f/m), add the constraint +/* For the div d = floor(f/m) at position "div", add the constraint * * f - m d >= 0 */ -static isl_stat add_upper_div_constraint(__isl_keep isl_basic_map *bmap, - unsigned pos, isl_int *div) +static __isl_give isl_basic_map *add_upper_div_constraint( + __isl_take isl_basic_map *bmap, unsigned div) { int i; - unsigned total = isl_basic_map_total_dim(bmap); + isl_size v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + isl_size n_div; + unsigned pos; + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (v_div < 0 || n_div < 0) + return isl_basic_map_free(bmap); + pos = v_div + div; i = isl_basic_map_alloc_inequality(bmap); if (i < 0) - return isl_stat_error; - isl_seq_cpy(bmap->ineq[i], div + 1, 1 + total); - isl_int_neg(bmap->ineq[i][1 + pos], div[0]); + return isl_basic_map_free(bmap); + isl_seq_cpy(bmap->ineq[i], bmap->div[div] + 1, 1 + v_div + n_div); + isl_int_neg(bmap->ineq[i][1 + pos], bmap->div[div][0]); - return isl_stat_ok; + return bmap; } -/* For a div d = floor(f/m), add the constraint +/* For the div d = floor(f/m) at position "div", add the constraint * * -(f-(m-1)) + m d >= 0 */ -static isl_stat add_lower_div_constraint(__isl_keep isl_basic_map *bmap, - unsigned pos, isl_int *div) +static __isl_give isl_basic_map *add_lower_div_constraint( + __isl_take isl_basic_map *bmap, unsigned div) { int i; - unsigned total = isl_basic_map_total_dim(bmap); + isl_size v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + isl_size n_div; + unsigned pos; + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (v_div < 0 || n_div < 0) + return isl_basic_map_free(bmap); + pos = v_div + div; i = isl_basic_map_alloc_inequality(bmap); if (i < 0) - return isl_stat_error; - isl_seq_neg(bmap->ineq[i], div + 1, 1 + total); - isl_int_set(bmap->ineq[i][1 + pos], div[0]); + return isl_basic_map_free(bmap); + isl_seq_neg(bmap->ineq[i], bmap->div[div] + 1, 1 + v_div + n_div); + isl_int_set(bmap->ineq[i][1 + pos], bmap->div[div][0]); isl_int_add(bmap->ineq[i][0], bmap->ineq[i][0], bmap->ineq[i][1 + pos]); isl_int_sub_ui(bmap->ineq[i][0], bmap->ineq[i][0], 1); - return isl_stat_ok; + return bmap; } -/* For a div d = floor(f/m), add the constraints +/* For the div d = floor(f/m) at position "pos", add the constraints * * f - m d >= 0 * -(f-(m-1)) + m d >= 0 @@ -5218,30 +5443,12 @@ * * f - m d >= m */ -int isl_basic_map_add_div_constraints_var(__isl_keep isl_basic_map *bmap, - unsigned pos, isl_int *div) -{ - if (add_upper_div_constraint(bmap, pos, div) < 0) - return -1; - if (add_lower_div_constraint(bmap, pos, div) < 0) - return -1; - return 0; -} - -int isl_basic_set_add_div_constraints_var(__isl_keep isl_basic_set *bset, - unsigned pos, isl_int *div) -{ - return isl_basic_map_add_div_constraints_var(bset_to_bmap(bset), - pos, div); -} - -int isl_basic_map_add_div_constraints(struct isl_basic_map *bmap, unsigned div) +__isl_give isl_basic_map *isl_basic_map_add_div_constraints( + __isl_take isl_basic_map *bmap, unsigned pos) { - unsigned total = isl_basic_map_total_dim(bmap); - unsigned div_pos = total - bmap->n_div + div; - - return isl_basic_map_add_div_constraints_var(bmap, div_pos, - bmap->div[div]); + bmap = add_upper_div_constraint(bmap, pos); + bmap = add_lower_div_constraint(bmap, pos); + return bmap; } /* For each known div d = floor(f/m), add the constraints @@ -5255,11 +5462,11 @@ __isl_give isl_basic_map *isl_basic_map_add_known_div_constraints( __isl_take isl_basic_map *bmap) { - unsigned n_div; + isl_size n_div; - if (!bmap) - return NULL; n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); if (n_div == 0) return bmap; @@ -5282,27 +5489,20 @@ * * if sign > 0. */ -int isl_basic_map_add_div_constraint(__isl_keep isl_basic_map *bmap, - unsigned div, int sign) +__isl_give isl_basic_map *isl_basic_map_add_div_constraint( + __isl_take isl_basic_map *bmap, unsigned div, int sign) { - unsigned total; - unsigned div_pos; - - if (!bmap) - return -1; - - total = isl_basic_map_total_dim(bmap); - div_pos = total - bmap->n_div + div; - if (sign < 0) - return add_upper_div_constraint(bmap, div_pos, bmap->div[div]); + return add_upper_div_constraint(bmap, div); else - return add_lower_div_constraint(bmap, div_pos, bmap->div[div]); + return add_lower_div_constraint(bmap, div); } __isl_give isl_basic_set *isl_basic_map_underlying_set( __isl_take isl_basic_map *bmap) { + isl_space *space; + if (!bmap) goto error; if (bmap->dim->nparam == 0 && bmap->dim->n_in == 0 && @@ -5312,10 +5512,12 @@ return bset_from_bmap(bmap); bmap = isl_basic_map_cow(bmap); if (!bmap) - goto error; - bmap->dim = isl_space_underlying(bmap->dim, bmap->n_div); - if (!bmap->dim) - goto error; + return NULL; + space = isl_basic_map_take_space(bmap); + space = isl_space_underlying(space, bmap->n_div); + bmap = isl_basic_map_restore_space(bmap, space); + if (!bmap) + return NULL; bmap->extra -= bmap->n_div; bmap->n_div = 0; bmap = isl_basic_map_finalize(bmap); @@ -5337,12 +5539,13 @@ __isl_give isl_basic_set_list *isl_basic_map_list_underlying_set( __isl_take isl_basic_map_list *list) { - int i, n; - - if (!list) - return NULL; + int i; + isl_size n; n = isl_basic_map_list_n_basic_map(list); + if (n < 0) + goto error; + for (i = 0; i < n; ++i) { isl_basic_map *bmap; isl_basic_set *bset; @@ -5353,6 +5556,9 @@ } return list; +error: + isl_basic_map_list_free(list); + return NULL; } __isl_give isl_basic_map *isl_basic_map_overlying_set( @@ -5360,16 +5566,21 @@ { struct isl_basic_map *bmap; struct isl_ctx *ctx; + isl_size dim, bmap_total; unsigned total; int i; if (!bset || !like) goto error; ctx = bset->ctx; - isl_assert(ctx, bset->n_div == 0, goto error); - isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error); - isl_assert(ctx, bset->dim->n_out == isl_basic_map_total_dim(like), - goto error); + if (isl_basic_set_check_no_params(bset) < 0 || + isl_basic_set_check_no_locals(bset) < 0) + goto error; + dim = isl_basic_set_dim(bset, isl_dim_set); + bmap_total = isl_basic_map_dim(like, isl_dim_all); + if (dim < 0 || bmap_total < 0) + goto error; + isl_assert(ctx, dim == bmap_total, goto error); if (like->n_div == 0) { isl_space *space = isl_basic_map_get_space(like); isl_basic_map_free(like); @@ -5378,11 +5589,11 @@ bset = isl_basic_set_cow(bset); if (!bset) goto error; - total = bset->dim->n_out + bset->extra; + total = dim + bset->extra; bmap = bset_to_bmap(bset); - isl_space_free(bmap->dim); - bmap->dim = isl_space_copy(like->dim); - if (!bmap->dim) + isl_space_free(isl_basic_map_take_space(bmap)); + bmap = isl_basic_map_restore_space(bmap, isl_basic_map_get_space(like)); + if (!bmap) goto error; bmap->n_div = like->n_div; bmap->extra += like->n_div; @@ -5480,13 +5691,9 @@ isl_space_free(space); return bmap; } - bmap = isl_basic_map_cow(bmap); - if (!bmap || !space) - goto error; + isl_space_free(isl_basic_map_take_space(bmap)); + bmap = isl_basic_map_restore_space(bmap, space); - isl_space_free(bmap->dim); - bmap->dim = space; - bmap = isl_basic_map_finalize(bmap); return bmap; @@ -5501,30 +5708,78 @@ { return bset_from_bmap(isl_basic_map_reset_space(bset_to_bmap(bset), dim)); +} + +/* Check that the total dimensions of "map" and "space" are the same. + */ +static isl_stat check_map_space_equal_total_dim(__isl_keep isl_map *map, + __isl_keep isl_space *space) +{ + isl_size dim1, dim2; + + dim1 = isl_map_dim(map, isl_dim_all); + dim2 = isl_space_dim(space, isl_dim_all); + if (dim1 < 0 || dim2 < 0) + return isl_stat_error; + if (dim1 == dim2) + return isl_stat_ok; + isl_die(isl_map_get_ctx(map), isl_error_invalid, + "total dimensions do not match", return isl_stat_error); } __isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map, - __isl_take isl_space *dim) + __isl_take isl_space *space) { int i; map = isl_map_cow(map); - if (!map || !dim) + if (!map || !space) goto error; for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_reset_space(map->p[i], - isl_space_copy(dim)); + isl_space_copy(space)); if (!map->p[i]) goto error; } - isl_space_free(map->dim); - map->dim = dim; + isl_space_free(isl_map_take_space(map)); + map = isl_map_restore_space(map, space); return map; error: isl_map_free(map); - isl_space_free(dim); + isl_space_free(space); + return NULL; +} + +/* Replace the space of "map" by "space", without modifying + * the dimension of "map". + * + * If the space of "map" is identical to "space" (including the identifiers + * of the input and output dimensions), then simply return the original input. + */ +__isl_give isl_map *isl_map_reset_equal_dim_space(__isl_take isl_map *map, + __isl_take isl_space *space) +{ + isl_bool equal; + isl_space *map_space; + + map_space = isl_map_peek_space(map); + equal = isl_space_is_equal(map_space, space); + if (equal >= 0 && equal) + equal = isl_space_has_equal_ids(map_space, space); + if (equal < 0) + goto error; + if (equal) { + isl_space_free(space); + return map; + } + if (check_map_space_equal_total_dim(map, space) < 0) + goto error; + return isl_map_reset_space(map, space); +error: + isl_map_free(map); + isl_space_free(space); return NULL; } @@ -5540,7 +5795,7 @@ { isl_bool is_params; isl_space *space; - unsigned n; + isl_size n; is_params = isl_basic_set_is_params(bset); if (is_params < 0) @@ -5549,6 +5804,8 @@ return bset; n = isl_basic_set_dim(bset, isl_dim_set); + if (n < 0) + return isl_basic_set_free(bset); bset = isl_basic_set_project_out(bset, isl_dim_set, 0, n); space = isl_basic_set_get_space(bset); space = isl_space_params(space); @@ -5572,18 +5829,7 @@ */ __isl_give isl_set *isl_set_params(__isl_take isl_set *set) { - isl_space *space; - unsigned n; - - if (isl_set_is_params(set)) - return set; - - n = isl_set_dim(set, isl_dim_set); - set = isl_set_project_out(set, isl_dim_set, 0, n); - space = isl_set_get_space(set); - space = isl_space_params(space); - set = isl_set_reset_space(set, space); - return set; + return isl_map_params(set_to_map(set)); } /* Construct a zero-dimensional set with the given parameter domain. @@ -5602,28 +5848,30 @@ __isl_give isl_set *isl_map_params(__isl_take isl_map *map) { isl_space *space; - unsigned n; - - n = isl_map_dim(map, isl_dim_in); - map = isl_map_project_out(map, isl_dim_in, 0, n); - n = isl_map_dim(map, isl_dim_out); - map = isl_map_project_out(map, isl_dim_out, 0, n); + isl_size n_in, n_out; + + n_in = isl_map_dim(map, isl_dim_in); + n_out = isl_map_dim(map, isl_dim_out); + if (n_in < 0 || n_out < 0) + return isl_map_free(map); + map = isl_map_project_out(map, isl_dim_in, 0, n_in); + map = isl_map_project_out(map, isl_dim_out, 0, n_out); space = isl_map_get_space(map); space = isl_space_params(space); map = isl_map_reset_space(map, space); return map; } -struct isl_basic_set *isl_basic_map_domain(struct isl_basic_map *bmap) +__isl_give isl_basic_set *isl_basic_map_domain(__isl_take isl_basic_map *bmap) { isl_space *space; - unsigned n_out; + isl_size n_out; - if (!bmap) - return NULL; + n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (n_out < 0) + return isl_basic_map_free(bmap); space = isl_space_domain(isl_basic_map_get_space(bmap)); - n_out = isl_basic_map_dim(bmap, isl_dim_out); bmap = isl_basic_map_project_out(bmap, isl_dim_out, 0, n_out); return isl_basic_map_reset_space(bmap, space); @@ -5666,16 +5914,19 @@ __isl_take isl_basic_map *bmap) { int i; - isl_space *dim; + isl_space *space; isl_basic_map *domain; - int nparam, n_in, n_out; + isl_size nparam, n_in, n_out; nparam = isl_basic_map_dim(bmap, isl_dim_param); n_in = isl_basic_map_dim(bmap, isl_dim_in); n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (nparam < 0 || n_in < 0 || n_out < 0) + return isl_basic_map_free(bmap); - dim = isl_space_from_range(isl_space_domain(isl_basic_map_get_space(bmap))); - domain = isl_basic_map_universe(dim); + space = isl_basic_map_get_space(bmap); + space = isl_space_from_range(isl_space_domain(space)); + domain = isl_basic_map_universe(space); bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap)); bmap = isl_basic_map_apply_range(bmap, domain); @@ -5693,16 +5944,19 @@ __isl_take isl_basic_map *bmap) { int i; - isl_space *dim; + isl_space *space; isl_basic_map *range; - int nparam, n_in, n_out; + isl_size nparam, n_in, n_out; nparam = isl_basic_map_dim(bmap, isl_dim_param); n_in = isl_basic_map_dim(bmap, isl_dim_in); n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (nparam < 0 || n_in < 0 || n_out < 0) + return isl_basic_map_free(bmap); - dim = isl_space_from_range(isl_space_range(isl_basic_map_get_space(bmap))); - range = isl_basic_map_universe(dim); + space = isl_basic_map_get_space(bmap); + space = isl_space_from_range(isl_space_range(space)); + range = isl_basic_map_universe(space); bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap)); bmap = isl_basic_map_apply_range(bmap, range); @@ -5767,56 +6021,44 @@ return NULL; } -__isl_give isl_map *isl_map_domain_map(__isl_take isl_map *map) +/* Transform "map" by applying "fn_space" to its space and "fn_bmap" + * to each of its basic maps. + */ +static __isl_give isl_map *isl_map_transform(__isl_take isl_map *map, + __isl_give isl_space *(*fn_space)(__isl_take isl_space *space), + __isl_give isl_basic_map *(*fn_bmap)(__isl_take isl_basic_map *bmap)) { int i; + isl_space *space; map = isl_map_cow(map); if (!map) return NULL; - map->dim = isl_space_domain_map(map->dim); - if (!map->dim) - goto error; for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_domain_map(map->p[i]); + map->p[i] = fn_bmap(map->p[i]); if (!map->p[i]) - goto error; + return isl_map_free(map); } - ISL_F_CLR(map, ISL_MAP_DISJOINT); - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); + + space = isl_map_take_space(map); + space = fn_space(space); + map = isl_map_restore_space(map, space); + return map; -error: - isl_map_free(map); - return NULL; } -__isl_give isl_map *isl_map_range_map(__isl_take isl_map *map) +__isl_give isl_map *isl_map_domain_map(__isl_take isl_map *map) { - int i; - isl_space *range_dim; - - map = isl_map_cow(map); - if (!map) - return NULL; + return isl_map_transform(map, &isl_space_domain_map, + &isl_basic_map_domain_map); +} - range_dim = isl_space_range(isl_map_get_space(map)); - range_dim = isl_space_from_range(range_dim); - map->dim = isl_space_from_domain(isl_space_wrap(map->dim)); - map->dim = isl_space_join(map->dim, range_dim); - if (!map->dim) - goto error; - for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_range_map(map->p[i]); - if (!map->p[i]) - goto error; - } - ISL_F_CLR(map, ISL_MAP_DISJOINT); - ISL_F_CLR(map, ISL_MAP_NORMALIZED); - return map; -error: - isl_map_free(map); - return NULL; +__isl_give isl_map *isl_map_range_map(__isl_take isl_map *map) +{ + return isl_map_transform(map, &isl_space_range_map, + &isl_basic_map_range_map); } /* Given a wrapped map of the form A[B -> C], @@ -5954,13 +6196,16 @@ return bset; } -__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_space *dim) +__isl_give isl_basic_map *isl_basic_map_nat_universe( + __isl_take isl_space *space) { int i; - unsigned total = isl_space_dim(dim, isl_dim_all); + isl_size total = isl_space_dim(space, isl_dim_all); isl_basic_map *bmap; - bmap= isl_basic_map_alloc_space(dim, 0, 0, total); + if (total < 0) + space = isl_space_free(space); + bmap = isl_basic_map_alloc_space(space, 0, 0, total); for (i = 0; i < total; ++i) { int k = isl_basic_map_alloc_inequality(bmap); if (k < 0) @@ -5974,9 +6219,10 @@ return NULL; } -__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_space *dim) +__isl_give isl_basic_set *isl_basic_set_nat_universe( + __isl_take isl_space *space) { - return isl_basic_map_nat_universe(dim); + return isl_basic_map_nat_universe(space); } __isl_give isl_map *isl_map_nat_universe(__isl_take isl_space *dim) @@ -6045,7 +6291,7 @@ isl_assert(map->ctx, map->n < map->size, goto error); map->p[map->n] = bmap; map->n++; - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; error: if (map) @@ -6075,17 +6321,22 @@ return NULL; } -static struct isl_basic_map *isl_basic_map_fix_pos_si( - struct isl_basic_map *bmap, unsigned pos, int value) +static __isl_give isl_basic_map *isl_basic_map_fix_pos_si( + __isl_take isl_basic_map *bmap, unsigned pos, int value) { int j; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); + bmap = isl_basic_map_cow(bmap); bmap = isl_basic_map_extend_constraints(bmap, 1, 0); j = isl_basic_map_alloc_equality(bmap); if (j < 0) goto error; - isl_seq_clr(bmap->eq[j] + 1, isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[j] + 1, total); isl_int_set_si(bmap->eq[j][pos], -1); isl_int_set_si(bmap->eq[j][0], value); bmap = isl_basic_map_simplify(bmap); @@ -6099,13 +6350,18 @@ __isl_take isl_basic_map *bmap, unsigned pos, isl_int value) { int j; + isl_size total; + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); bmap = isl_basic_map_cow(bmap); bmap = isl_basic_map_extend_constraints(bmap, 1, 0); j = isl_basic_map_alloc_equality(bmap); if (j < 0) goto error; - isl_seq_clr(bmap->eq[j] + 1, isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[j] + 1, total); isl_int_set_si(bmap->eq[j][pos], -1); isl_int_set(bmap->eq[j][0], value); bmap = isl_basic_map_simplify(bmap); @@ -6192,23 +6448,31 @@ isl_dim_set, dim, value)); } -static int remove_if_empty(__isl_keep isl_map *map, int i) +/* Remove the basic map at position "i" from "map" if this basic map + * is (obviously) empty. + */ +static __isl_give isl_map *remove_if_empty(__isl_take isl_map *map, int i) { - int empty = isl_basic_map_plain_is_empty(map->p[i]); + isl_bool empty; + + if (!map) + return NULL; + empty = isl_basic_map_plain_is_empty(map->p[i]); if (empty < 0) - return -1; + return isl_map_free(map); if (!empty) - return 0; + return map; isl_basic_map_free(map->p[i]); - if (i != map->n - 1) { - ISL_F_CLR(map, ISL_MAP_NORMALIZED); - map->p[i] = map->p[map->n - 1]; - } map->n--; + if (i != map->n) { + map->p[i] = map->p[map->n]; + map = isl_map_unmark_normalized(map); - return 0; + } + + return map; } /* Perform "fn" on each basic map of "map", where we may not be holding @@ -6234,8 +6498,9 @@ goto error; isl_basic_map_free(map->p[i]); map->p[i] = bmap; - if (remove_if_empty(map, i) < 0) - goto error; + map = remove_if_empty(map, i); + if (!map) + return NULL; } return map; @@ -6250,20 +6515,16 @@ int i; map = isl_map_cow(map); - if (!map) - return NULL; - - isl_assert(map->ctx, pos < isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, pos, 1) < 0) + return isl_map_free(map); for (i = map->n - 1; i >= 0; --i) { map->p[i] = isl_basic_map_fix_si(map->p[i], type, pos, value); - if (remove_if_empty(map, i) < 0) - goto error; + map = remove_if_empty(map, i); + if (!map) + return NULL; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; -error: - isl_map_free(map); - return NULL; } __isl_give isl_set *isl_set_fix_si(__isl_take isl_set *set, @@ -6278,16 +6539,14 @@ int i; map = isl_map_cow(map); - if (!map) - return NULL; - - isl_assert(map->ctx, pos < isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, pos, 1) < 0) + return isl_map_free(map); for (i = 0; i < map->n; ++i) { map->p[i] = isl_basic_map_fix(map->p[i], type, pos, value); if (!map->p[i]) goto error; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; error: isl_map_free(map); @@ -6315,16 +6574,16 @@ if (!isl_val_is_int(v)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "expecting integer value", goto error); - if (pos >= isl_map_dim(map, type)) - isl_die(isl_map_get_ctx(map), isl_error_invalid, - "index out of bounds", goto error); + if (isl_map_check_range(map, type, pos, 1) < 0) + goto error; for (i = map->n - 1; i >= 0; --i) { map->p[i] = isl_basic_map_fix_val(map->p[i], type, pos, isl_val_copy(v)); - if (remove_if_empty(map, i) < 0) + map = remove_if_empty(map, i); + if (!map) goto error; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); isl_val_free(v); return map; error: @@ -6359,8 +6618,12 @@ enum isl_dim_type type, unsigned pos, int value, int upper) { int j; + isl_size total; if (isl_basic_map_check_range(bmap, type, pos, 1) < 0) + return isl_basic_map_free(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return isl_basic_map_free(bmap); pos += isl_basic_map_offset(bmap, type); bmap = isl_basic_map_cow(bmap); @@ -6368,7 +6631,7 @@ j = isl_basic_map_alloc_inequality(bmap); if (j < 0) goto error; - isl_seq_clr(bmap->ineq[j], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[j], 1 + total); if (upper) { isl_int_set_si(bmap->ineq[j][pos], -1); isl_int_set_si(bmap->ineq[j][0], value); @@ -6405,17 +6668,15 @@ int i; map = isl_map_cow(map); - if (!map) - return NULL; - - isl_assert(map->ctx, pos < isl_map_dim(map, type), goto error); + if (isl_map_check_range(map, type, pos, 1) < 0) + return isl_map_free(map); for (i = 0; i < map->n; ++i) { map->p[i] = basic_map_bound_si(map->p[i], type, pos, value, upper); if (!map->p[i]) goto error; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; error: isl_map_free(map); @@ -6455,8 +6716,12 @@ enum isl_dim_type type, unsigned pos, isl_int value, int upper) { int j; + isl_size total; if (isl_basic_map_check_range(bmap, type, pos, 1) < 0) + return isl_basic_map_free(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return isl_basic_map_free(bmap); pos += isl_basic_map_offset(bmap, type); bmap = isl_basic_map_cow(bmap); @@ -6464,7 +6729,7 @@ j = isl_basic_map_alloc_inequality(bmap); if (j < 0) goto error; - isl_seq_clr(bmap->ineq[j], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[j], 1 + total); if (upper) { isl_int_set_si(bmap->ineq[j][pos], -1); isl_int_set(bmap->ineq[j][0], value); @@ -6488,22 +6753,16 @@ int i; map = isl_map_cow(map); - if (!map) - return NULL; - - if (pos >= isl_map_dim(map, type)) - isl_die(map->ctx, isl_error_invalid, - "index out of bounds", goto error); + if (isl_map_check_range(map, type, pos, 1) < 0) + return isl_map_free(map); for (i = map->n - 1; i >= 0; --i) { map->p[i] = basic_map_bound(map->p[i], type, pos, value, upper); - if (remove_if_empty(map, i) < 0) - goto error; + map = remove_if_empty(map, i); + if (!map) + return NULL; } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; -error: - isl_map_free(map); - return NULL; } __isl_give isl_map *isl_map_lower_bound(__isl_take isl_map *map, @@ -6622,25 +6881,16 @@ __isl_give isl_map *isl_map_reverse(__isl_take isl_map *map) { - int i; - - map = isl_map_cow(map); - if (!map) - return NULL; + return isl_map_transform(map, &isl_space_reverse, + &isl_basic_map_reverse); +} - map->dim = isl_space_reverse(map->dim); - if (!map->dim) - goto error; - for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_reverse(map->p[i]); - if (!map->p[i]) - goto error; - } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); - return map; -error: - isl_map_free(map); - return NULL; +/* Given a map A -> (B -> C), return the corresponding map A -> (C -> B). + */ +__isl_give isl_map *isl_map_range_reverse(__isl_take isl_map *map) +{ + return isl_map_transform(map, &isl_space_range_reverse, + &isl_basic_map_range_reverse); } #undef TYPE @@ -6898,18 +7148,20 @@ { int i; isl_pw_aff *pwaff; - unsigned n_out; + isl_size n_out; n_out = isl_map_dim(map, isl_dim_out); + if (n_out < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_out, pos + 1, n_out - (pos + 1)); map = isl_map_project_out(map, isl_dim_out, 0, pos); if (!map) return NULL; if (map->n == 0) { - isl_space *dim = isl_map_get_space(map); + isl_space *space = isl_map_get_space(map); isl_map_free(map); - return isl_pw_aff_empty(dim); + return isl_pw_aff_empty(space); } pwaff = basic_map_dim_opt(map->p[0], max); @@ -6975,17 +7227,16 @@ static __isl_give isl_basic_set *basic_set_parameter_preimage( __isl_take isl_basic_set *bset, __isl_take isl_mat *mat) { - unsigned nparam; + isl_size nparam; - if (!bset || !mat) + nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0 || !mat) goto error; bset->dim = isl_space_cow(bset->dim); if (!bset->dim) goto error; - nparam = isl_basic_set_dim(bset, isl_dim_param); - isl_assert(bset->ctx, mat->n_row == 1 + nparam, goto error); bset->dim->nparam = 0; @@ -7009,12 +7260,11 @@ __isl_take isl_mat *mat) { isl_space *space; - unsigned nparam; - - if (!set || !mat) - goto error; + isl_size nparam; nparam = isl_set_dim(set, isl_dim_param); + if (nparam < 0 || !mat) + goto error; if (mat->n_row != 1 + nparam) isl_die(isl_set_get_ctx(set), isl_error_internal, @@ -7026,6 +7276,8 @@ set = isl_set_reset_space(set, space); set = isl_set_preimage(set, mat); nparam = isl_set_dim(set, isl_dim_out); + if (nparam < 0) + set = isl_set_free(set); space = isl_set_get_space(set); space = isl_space_move_dims(space, isl_dim_param, 0, isl_dim_out, 0, nparam); @@ -7054,7 +7306,7 @@ if (!bset) goto error; - len = 1 + isl_space_dim(bset->dim, isl_dim_all) + bset->extra; + len = isl_basic_set_offset(bset, isl_dim_div) + bset->extra; for (i = 0; i < eq->n_row; ++i) { k = isl_basic_set_alloc_equality(bset); if (k < 0) @@ -7109,13 +7361,12 @@ static int first_parameter_equality(__isl_keep isl_basic_set *bset) { int i, j; - unsigned nparam, n_div; - - if (!bset) - return -1; + isl_size nparam, n_div; nparam = isl_basic_set_dim(bset, isl_dim_param); n_div = isl_basic_set_dim(bset, isl_dim_div); + if (nparam < 0 || n_div < 0) + return -1; for (i = 0, j = n_div - 1; i < bset->n_eq && j >= 0; --j) { if (!isl_int_is_zero(bset->eq[i][1 + nparam + j])) @@ -7143,7 +7394,7 @@ { isl_morph *morph1, *morph2; isl_set *set; - unsigned n; + isl_size n; if (!bset) return NULL; @@ -7156,6 +7407,8 @@ morph2 = isl_basic_set_variable_compression(bset, isl_dim_set); bset = isl_morph_basic_set(morph2, bset); n = isl_basic_set_dim(bset, isl_dim_set); + if (n < 0) + bset = isl_basic_set_free(bset); bset = isl_basic_set_project_out(bset, isl_dim_set, 0, n); set = isl_basic_set_lexmin_compute_divs(bset); @@ -7189,7 +7442,7 @@ struct isl_mat *eq; struct isl_mat *T, *T2; struct isl_set *set; - unsigned nparam; + isl_size nparam; bset = isl_basic_set_cow(bset); if (!bset) @@ -7209,6 +7462,8 @@ return base_compute_divs(bset); nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0) + return isl_set_from_basic_set(isl_basic_set_free(bset)); eq = isl_mat_sub_alloc6(bset->ctx, bset->eq, i, bset->n_eq - i, 0, 1 + nparam); eq = isl_mat_cow(eq); @@ -7245,10 +7500,12 @@ __isl_take isl_basic_map *bmap, __isl_keep isl_local_space *ls) { int i; - int n_div; + isl_size n_div; int old_n_div; n_div = isl_local_space_dim(ls, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); if (n_div == 0) return bmap; @@ -7274,13 +7531,13 @@ static __isl_give isl_basic_map *basic_replace_space_by_local_space( __isl_take isl_basic_map *bmap, __isl_take isl_local_space *ls) { - int n_div; + isl_size n_div; bmap = isl_basic_map_cow(bmap); - if (!bmap || !ls) + n_div = isl_local_space_dim(ls, isl_dim_div); + if (!bmap || n_div < 0) goto error; - n_div = isl_local_space_dim(ls, isl_dim_div); bmap = insert_divs_from_local_space(bmap, ls); if (!bmap) goto error; @@ -7318,10 +7575,8 @@ if (!map->p[i]) goto error; } - isl_space_free(map->dim); - map->dim = isl_local_space_get_space(ls); - if (!map->dim) - goto error; + isl_space_free(isl_map_take_space(map)); + map = isl_map_restore_space(map, isl_local_space_get_space(ls)); isl_local_space_free(ls); return map; @@ -7345,16 +7600,16 @@ * is reset to that of the input, including the existentially quantified * variables for which we already had an explicit representation. */ -static struct isl_map *compute_divs(struct isl_basic_map *bmap) +static __isl_give isl_map *compute_divs(__isl_take isl_basic_map *bmap) { struct isl_basic_set *bset; struct isl_set *set; struct isl_map *map; - isl_space *dim; + isl_space *space; isl_local_space *ls; - unsigned nparam; - unsigned n_in; - unsigned n_out; + isl_size nparam; + isl_size n_in; + isl_size n_out; int n_known; int i; @@ -7364,15 +7619,15 @@ return NULL; n_known = isl_basic_map_first_unknown_div(bmap); - if (n_known < 0) - return isl_map_from_basic_map(isl_basic_map_free(bmap)); - nparam = isl_basic_map_dim(bmap, isl_dim_param); n_in = isl_basic_map_dim(bmap, isl_dim_in); n_out = isl_basic_map_dim(bmap, isl_dim_out); - dim = isl_space_set_alloc(bmap->ctx, + if (n_known < 0 || nparam < 0 || n_in < 0 || n_out < 0) + return isl_map_from_basic_map(isl_basic_map_free(bmap)); + + space = isl_space_set_alloc(bmap->ctx, nparam + n_in + n_out + n_known, 0); - if (!dim) + if (!space) goto error; ls = isl_basic_map_get_local_space(bmap); @@ -7384,7 +7639,7 @@ bmap->n_div -= n_known; bmap->extra -= n_known; } - bmap = isl_basic_map_reset_space(bmap, dim); + bmap = isl_basic_map_reset_space(bmap, space); bset = bset_from_bmap(bmap); set = parameter_compute_divs(bset); @@ -7468,11 +7723,12 @@ */ isl_bool isl_basic_map_divs_known(__isl_keep isl_basic_map *bmap) { - int first, n; + int first; + isl_size n; n = isl_basic_map_dim(bmap, isl_dim_div); first = isl_basic_map_first_unknown_div(bmap); - if (first < 0) + if (n < 0 || first < 0) return isl_bool_error; return first == n; } @@ -7843,23 +8099,89 @@ &map_intersect_domain); } -/* Given a map "map" in a space [A -> B] -> C and a map "factor" - * in the space B -> C, return the intersection. - * The parameters are assumed to have been aligned. - * - * The map "factor" is first extended to a map living in the space - * [A -> B] -> C and then a regular intersection is computed. +/* Data structure that specifies how isl_map_intersect_factor + * should operate. + * + * "preserve_type" is the tuple where the factor differs from + * the input map and of which the identifiers needs + * to be preserved explicitly. + * "other_factor" is used to extract the space of the other factor + * from the space of the product ("map"). + * "product" is used to combine the given factor and a universe map + * in the space returned by "other_factor" to produce a map + * that lives in the same space as the input map. + */ +struct isl_intersect_factor_control { + enum isl_dim_type preserve_type; + __isl_give isl_space *(*other_factor)(__isl_take isl_space *space); + __isl_give isl_map *(*product)(__isl_take isl_map *factor, + __isl_take isl_map *other); +}; + +/* Given a map "map" in some product space and a map "factor" + * living in some factor space, return the intersection. + * + * After aligning the parameters, + * the map "factor" is first extended to a map living in the same space + * as "map" and then a regular intersection is computed. + * + * Note that the extension is computed as a product, which is anonymous + * by default. If "map" has an identifier on the corresponding tuple, + * then this identifier needs to be set on the product + * before the intersection is computed. + */ +static __isl_give isl_map *isl_map_intersect_factor( + __isl_take isl_map *map, __isl_take isl_map *factor, + struct isl_intersect_factor_control *control) +{ + isl_bool equal, has_id; + isl_id *id; + isl_space *space; + isl_map *other, *product; + + equal = isl_map_has_equal_params(map, factor); + if (equal < 0) + goto error; + if (!equal) { + map = isl_map_align_params(map, isl_map_get_space(factor)); + factor = isl_map_align_params(factor, isl_map_get_space(map)); + } + + space = isl_map_get_space(map); + has_id = isl_space_has_tuple_id(space, control->preserve_type); + if (has_id < 0) + space = isl_space_free(space); + else if (has_id) + id = isl_space_get_tuple_id(space, control->preserve_type); + + other = isl_map_universe(control->other_factor(space)); + product = control->product(factor, other); + + if (has_id >= 0 && has_id) + product = isl_map_set_tuple_id(product, + control->preserve_type, id); + + return map_intersect(map, product); +error: + isl_map_free(map); + isl_map_free(factor); + return NULL; +} + +/* Return the domain product of "map2" and "map1". */ -static __isl_give isl_map *map_intersect_domain_factor_range( - __isl_take isl_map *map, __isl_take isl_map *factor) +static __isl_give isl_map *isl_map_reverse_domain_product( + __isl_take isl_map *map1, __isl_take isl_map *map2) { - isl_space *space; - isl_map *ext_factor; + return isl_map_domain_product(map2, map1); +} - space = isl_space_domain_factor_domain(isl_map_get_space(map)); - ext_factor = isl_map_universe(space); - ext_factor = isl_map_domain_product(ext_factor, factor); - return map_intersect(map, ext_factor); +/* Return the range product of "map2" and "map1". + */ +static __isl_give isl_map *isl_map_reverse_range_product( + __isl_take isl_map *map1, __isl_take isl_map *map2) +{ + return isl_map_range_product(map2, map1); } /* Given a map "map" in a space [A -> B] -> C and a map "factor" @@ -7868,26 +8190,28 @@ __isl_give isl_map *isl_map_intersect_domain_factor_range( __isl_take isl_map *map, __isl_take isl_map *factor) { - return isl_map_align_params_map_map_and(map, factor, - &map_intersect_domain_factor_range); + struct isl_intersect_factor_control control = { + .preserve_type = isl_dim_in, + .other_factor = isl_space_domain_factor_domain, + .product = isl_map_reverse_domain_product, + }; + + return isl_map_intersect_factor(map, factor, &control); } /* Given a map "map" in a space A -> [B -> C] and a map "factor" - * in the space A -> C, return the intersection. - * - * The map "factor" is first extended to a map living in the space - * A -> [B -> C] and then a regular intersection is computed. + * in the space A -> B, return the intersection. */ -static __isl_give isl_map *map_intersect_range_factor_range( +__isl_give isl_map *isl_map_intersect_range_factor_domain( __isl_take isl_map *map, __isl_take isl_map *factor) { - isl_space *space; - isl_map *ext_factor; + struct isl_intersect_factor_control control = { + .preserve_type = isl_dim_out, + .other_factor = isl_space_range_factor_range, + .product = isl_map_range_product, + }; - space = isl_space_range_factor_domain(isl_map_get_space(map)); - ext_factor = isl_map_universe(space); - ext_factor = isl_map_range_product(ext_factor, factor); - return isl_map_intersect(map, ext_factor); + return isl_map_intersect_factor(map, factor, &control); } /* Given a map "map" in a space A -> [B -> C] and a map "factor" @@ -7895,9 +8219,52 @@ */ __isl_give isl_map *isl_map_intersect_range_factor_range( __isl_take isl_map *map, __isl_take isl_map *factor) +{ + struct isl_intersect_factor_control control = { + .preserve_type = isl_dim_out, + .other_factor = isl_space_range_factor_domain, + .product = isl_map_reverse_range_product, + }; + + return isl_map_intersect_factor(map, factor, &control); +} + +/* Given a set "set" in a space [A -> B] and a set "domain" + * in the space A, return the intersection. + * + * The set "domain" is first extended to a set living in the space + * [A -> B] and then a regular intersection is computed. + */ +__isl_give isl_set *isl_set_intersect_factor_domain(__isl_take isl_set *set, + __isl_take isl_set *domain) +{ + struct isl_intersect_factor_control control = { + .preserve_type = isl_dim_set, + .other_factor = isl_space_factor_range, + .product = isl_map_range_product, + }; + + return set_from_map(isl_map_intersect_factor(set_to_map(set), + set_to_map(domain), &control)); +} + +/* Given a set "set" in a space [A -> B] and a set "range" + * in the space B, return the intersection. + * + * The set "range" is first extended to a set living in the space + * [A -> B] and then a regular intersection is computed. + */ +__isl_give isl_set *isl_set_intersect_factor_range(__isl_take isl_set *set, + __isl_take isl_set *range) { - return isl_map_align_params_map_map_and(map, factor, - &map_intersect_range_factor_range); + struct isl_intersect_factor_control control = { + .preserve_type = isl_dim_set, + .other_factor = isl_space_factor_domain, + .product = isl_map_reverse_range_product, + }; + + return set_from_map(isl_map_intersect_factor(set_to_map(set), + set_to_map(range), &control)); } static __isl_give isl_map *map_apply_domain(__isl_take isl_map *map1, @@ -7923,17 +8290,17 @@ static __isl_give isl_map *map_apply_range(__isl_take isl_map *map1, __isl_take isl_map *map2) { - isl_space *dim_result; + isl_space *space; struct isl_map *result; int i, j; if (!map1 || !map2) goto error; - dim_result = isl_space_join(isl_space_copy(map1->dim), + space = isl_space_join(isl_space_copy(map1->dim), isl_space_copy(map2->dim)); - result = isl_map_alloc_space(dim_result, map1->n * map2->n, 0); + result = isl_map_alloc_space(space, map1->n * map2->n, 0); if (!result) goto error; for (i = 0; i < map1->n; ++i) @@ -7969,8 +8336,9 @@ { isl_space *target_space; struct isl_basic_set *bset; - unsigned dim; - unsigned nparam; + isl_size dim; + isl_size nparam; + isl_size total; int i; if (!bmap) @@ -7978,11 +8346,16 @@ isl_assert(bmap->ctx, isl_space_tuple_is_equal(bmap->dim, isl_dim_in, bmap->dim, isl_dim_out), goto error); - target_space = isl_space_domain(isl_basic_map_get_space(bmap)); dim = isl_basic_map_dim(bmap, isl_dim_in); nparam = isl_basic_map_dim(bmap, isl_dim_param); + if (dim < 0 || nparam < 0) + goto error; + target_space = isl_space_domain(isl_basic_map_get_space(bmap)); bmap = isl_basic_map_from_range(isl_basic_map_wrap(bmap)); bmap = isl_basic_map_add_dims(bmap, isl_dim_in, dim); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + bmap = isl_basic_map_free(bmap); bmap = isl_basic_map_extend_constraints(bmap, dim, 0); for (i = 0; i < dim; ++i) { int j = isl_basic_map_alloc_equality(bmap); @@ -7990,7 +8363,7 @@ bmap = isl_basic_map_free(bmap); break; } - isl_seq_clr(bmap->eq[j], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[j], 1 + total); isl_int_set_si(bmap->eq[j][1+nparam+i], 1); isl_int_set_si(bmap->eq[j][1+nparam+dim+i], 1); isl_int_set_si(bmap->eq[j][1+nparam+2*dim+i], -1); @@ -8001,6 +8374,23 @@ error: isl_basic_map_free(bmap); return NULL; +} + +/* Check that domain and range of "map" are the same. + */ +isl_stat isl_map_check_equal_tuples(__isl_keep isl_map *map) +{ + isl_space *space; + isl_bool equal; + + space = isl_map_peek_space(map); + equal = isl_space_tuple_is_equal(space, isl_dim_in, space, isl_dim_out); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(isl_map_get_ctx(map), isl_error_invalid, + "domain and range don't match", return isl_stat_error); + return isl_stat_ok; } /* @@ -8040,10 +8430,10 @@ __isl_take isl_basic_map *bmap) { int i, k; - isl_space *dim; + isl_space *space; isl_basic_map *domain; - int nparam, n; - unsigned total; + isl_size nparam, n; + isl_size total; if (!isl_space_tuple_is_equal(bmap->dim, isl_dim_in, bmap->dim, isl_dim_out)) @@ -8052,15 +8442,20 @@ nparam = isl_basic_map_dim(bmap, isl_dim_param); n = isl_basic_map_dim(bmap, isl_dim_in); + if (nparam < 0 || n < 0) + return isl_basic_map_free(bmap); - dim = isl_space_from_range(isl_space_domain(isl_basic_map_get_space(bmap))); - domain = isl_basic_map_universe(dim); + space = isl_basic_map_get_space(bmap); + space = isl_space_from_range(isl_space_domain(space)); + domain = isl_basic_map_universe(space); bmap = isl_basic_map_from_domain(isl_basic_map_wrap(bmap)); bmap = isl_basic_map_apply_range(bmap, domain); bmap = isl_basic_map_extend_constraints(bmap, n, 0); - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); for (i = 0; i < n; ++i) { k = isl_basic_map_alloc_equality(bmap); @@ -8084,79 +8479,28 @@ */ __isl_give isl_map *isl_map_deltas_map(__isl_take isl_map *map) { - int i; - isl_space *domain_dim; - - if (!map) - return NULL; - - if (!isl_space_tuple_is_equal(map->dim, isl_dim_in, - map->dim, isl_dim_out)) - isl_die(map->ctx, isl_error_invalid, - "domain and range don't match", goto error); - - map = isl_map_cow(map); - if (!map) - return NULL; + if (isl_map_check_equal_tuples(map) < 0) + return isl_map_free(map); - domain_dim = isl_space_from_range(isl_space_domain(isl_map_get_space(map))); - map->dim = isl_space_from_domain(isl_space_wrap(map->dim)); - map->dim = isl_space_join(map->dim, domain_dim); - if (!map->dim) - goto error; - for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_deltas_map(map->p[i]); - if (!map->p[i]) - goto error; - } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); - return map; -error: - isl_map_free(map); - return NULL; + return isl_map_transform(map, &isl_space_range_map, + &isl_basic_map_deltas_map); } -static __isl_give isl_basic_map *basic_map_identity(__isl_take isl_space *dims) +__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *space) { - struct isl_basic_map *bmap; - unsigned nparam; - unsigned dim; - int i; + isl_size n_in, n_out; - if (!dims) - return NULL; - - nparam = dims->nparam; - dim = dims->n_out; - bmap = isl_basic_map_alloc_space(dims, 0, dim, 0); - if (!bmap) + n_in = isl_space_dim(space, isl_dim_in); + n_out = isl_space_dim(space, isl_dim_out); + if (n_in < 0 || n_out < 0) goto error; - - for (i = 0; i < dim; ++i) { - int j = isl_basic_map_alloc_equality(bmap); - if (j < 0) - goto error; - isl_seq_clr(bmap->eq[j], 1 + isl_basic_map_total_dim(bmap)); - isl_int_set_si(bmap->eq[j][1+nparam+i], 1); - isl_int_set_si(bmap->eq[j][1+nparam+dim+i], -1); - } - return isl_basic_map_finalize(bmap); -error: - isl_basic_map_free(bmap); - return NULL; -} - -__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *dim) -{ - if (!dim) - return NULL; - if (dim->n_in != dim->n_out) - isl_die(dim->ctx, isl_error_invalid, + if (n_in != n_out) + isl_die(space->ctx, isl_error_invalid, "number of input and output dimensions needs to be " "the same", goto error); - return basic_map_identity(dim); + return isl_basic_map_equal(space, n_in); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -8180,14 +8524,16 @@ __isl_take isl_space *space) { int i; - unsigned nparam; - unsigned dim; + isl_size nparam; + isl_size dim; + isl_size total; struct isl_basic_set *bset; - if (!space) - return NULL; - nparam = space->nparam; - dim = space->n_out; + nparam = isl_space_dim(space, isl_dim_param); + dim = isl_space_dim(space, isl_dim_set); + total = isl_space_dim(space, isl_dim_all); + if (nparam < 0 || dim < 0 || total < 0) + space = isl_space_free(space); bset = isl_basic_set_alloc_space(space, 0, 0, dim); if (!bset) return NULL; @@ -8195,7 +8541,7 @@ int k = isl_basic_set_alloc_inequality(bset); if (k < 0) goto error; - isl_seq_clr(bset->ineq[k], 1 + isl_basic_set_total_dim(bset)); + isl_seq_clr(bset->ineq[k], 1 + total); isl_int_set_si(bset->ineq[k][1 + nparam + i], 1); } return bset; @@ -8206,17 +8552,21 @@ /* Construct the half-space x_pos >= 0. */ -static __isl_give isl_basic_set *nonneg_halfspace(__isl_take isl_space *dim, +static __isl_give isl_basic_set *nonneg_halfspace(__isl_take isl_space *space, int pos) { int k; + isl_size total; isl_basic_set *nonneg; - nonneg = isl_basic_set_alloc_space(dim, 0, 0, 1); + total = isl_space_dim(space, isl_dim_all); + if (total < 0) + space = isl_space_free(space); + nonneg = isl_basic_set_alloc_space(space, 0, 0, 1); k = isl_basic_set_alloc_inequality(nonneg); if (k < 0) goto error; - isl_seq_clr(nonneg->ineq[k], 1 + isl_basic_set_total_dim(nonneg)); + isl_seq_clr(nonneg->ineq[k], 1 + total); isl_int_set_si(nonneg->ineq[k][pos], 1); return isl_basic_set_finalize(nonneg); @@ -8227,16 +8577,21 @@ /* Construct the half-space x_pos <= -1. */ -static __isl_give isl_basic_set *neg_halfspace(__isl_take isl_space *dim, int pos) +static __isl_give isl_basic_set *neg_halfspace(__isl_take isl_space *space, + int pos) { int k; + isl_size total; isl_basic_set *neg; - neg = isl_basic_set_alloc_space(dim, 0, 0, 1); + total = isl_space_dim(space, isl_dim_all); + if (total < 0) + space = isl_space_free(space); + neg = isl_basic_set_alloc_space(space, 0, 0, 1); k = isl_basic_set_alloc_inequality(neg); if (k < 0) goto error; - isl_seq_clr(neg->ineq[k], 1 + isl_basic_set_total_dim(neg)); + isl_seq_clr(neg->ineq[k], 1 + total); isl_int_set_si(neg->ineq[k][0], -1); isl_int_set_si(neg->ineq[k][pos], -1); @@ -8254,12 +8609,11 @@ isl_basic_set *nonneg; isl_basic_set *neg; - if (!set) - return NULL; if (n == 0) return set; - isl_assert(set->ctx, first + n <= isl_set_dim(set, type), goto error); + if (isl_set_check_range(set, type, first, n) < 0) + return isl_set_free(set); offset = pos(set->dim, type); for (i = 0; i < n; ++i) { @@ -8271,9 +8625,6 @@ } return set; -error: - isl_set_free(set); - return NULL; } static isl_stat foreach_orthant(__isl_take isl_set *set, int *signs, int first, @@ -8318,8 +8669,8 @@ isl_stat (*fn)(__isl_take isl_set *orthant, int *signs, void *user), void *user) { - unsigned nparam; - unsigned nvar; + isl_size nparam; + isl_size nvar; int *signs; isl_stat r; @@ -8330,6 +8681,8 @@ nparam = isl_set_dim(set, isl_dim_param); nvar = isl_set_dim(set, isl_dim_set); + if (nparam < 0 || nvar < 0) + return isl_stat_error; signs = isl_alloc_array(set->ctx, int, nparam + nvar); @@ -8349,7 +8702,7 @@ isl_bool isl_basic_map_is_subset(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2) { - int is_subset; + isl_bool is_subset; struct isl_map *map1; struct isl_map *map2; @@ -8483,9 +8836,7 @@ if (is_subset != isl_bool_true) return is_subset; is_subset = isl_basic_map_is_subset(bmap2, bmap1); - if (is_subset == isl_bool_error) - return is_subset; - return !is_subset; + return isl_bool_not(is_subset); } isl_bool isl_map_is_strict_subset(__isl_keep isl_map *map1, @@ -8499,9 +8850,7 @@ if (is_subset != isl_bool_true) return is_subset; is_subset = isl_map_is_subset(map2, map1); - if (is_subset == isl_bool_error) - return is_subset; - return !is_subset; + return isl_bool_not(is_subset); } isl_bool isl_set_is_strict_subset(__isl_keep isl_set *set1, @@ -8534,9 +8883,11 @@ static isl_stat involves_divs(__isl_take isl_constraint *c, void *user) { isl_bool *univ = user; - unsigned n; + isl_size n; n = isl_constraint_dim(c, isl_dim_div); + if (n < 0) + c = isl_constraint_free(c); *univ = isl_constraint_involves_dims(c, isl_dim_div, 0, n); isl_constraint_free(c); if (*univ < 0 || !*univ) @@ -8554,13 +8905,17 @@ */ isl_bool isl_basic_map_is_universe(__isl_keep isl_basic_map *bmap) { + isl_size n_div; isl_bool univ; isl_basic_map *test; univ = isl_basic_map_plain_is_universe(bmap); if (univ < 0 || univ) return univ; - if (isl_basic_map_dim(bmap, isl_dim_div) == 0) + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_bool_error; + if (n_div == 0) return isl_bool_false; univ = isl_bool_true; if (isl_basic_map_foreach_constraint(bmap, &involves_divs, &univ) < 0 && @@ -8667,14 +9022,16 @@ */ isl_bool isl_basic_map_plain_is_non_empty(__isl_keep isl_basic_map *bmap) { - unsigned total; + isl_size total; if (!bmap) return isl_bool_error; if (!bmap->sample) return isl_bool_false; - total = 1 + isl_basic_map_total_dim(bmap); - if (bmap->sample->size != total) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; + if (bmap->sample->size != 1 + total) return isl_bool_false; return isl_basic_map_contains(bmap, bmap->sample); } @@ -8717,12 +9074,11 @@ __isl_take isl_basic_map *bmap) { int i; - unsigned off; + isl_size off; - if (!bmap) - return NULL; - - off = isl_space_dim(bmap->dim, isl_dim_all); + off = isl_basic_map_var_offset(bmap, isl_dim_div); + if (off < 0) + return isl_basic_map_free(bmap); for (i = 0; i < bmap->n_div; ++i) { int pos; @@ -8736,7 +9092,9 @@ isl_die(isl_basic_map_get_ctx(bmap), isl_error_internal, "integer division depends on itself", return isl_basic_map_free(bmap)); - isl_basic_map_swap_div(bmap, i, i + pos); + bmap = isl_basic_map_swap_div(bmap, i, i + pos); + if (!bmap) + return NULL; --i; } return bmap; @@ -8810,7 +9168,9 @@ for (j = n_div - 1; j >= 0; --j) { if (exp[j] == j) break; - isl_basic_map_swap_div(bmap, j, exp[j]); + bmap = isl_basic_map_swap_div(bmap, j, exp[j]); + if (!bmap) + goto error; } j = 0; for (i = 0; i < div->n_row; ++i) { @@ -8820,7 +9180,8 @@ isl_seq_cpy(bmap->div[i], div->row[i], div->n_col); if (isl_basic_map_div_is_marked_unknown(bmap, i)) continue; - if (isl_basic_map_add_div_constraints(bmap, i) < 0) + bmap = isl_basic_map_add_div_constraints(bmap, i); + if (!bmap) goto error; } } @@ -8846,23 +9207,28 @@ /* Look for a div in dst that corresponds to the div "div" in src. * The divs before "div" in src and dst are assumed to be the same. * - * Returns -1 if no corresponding div was found and the position - * of the corresponding div in dst otherwise. + * Return the position of the corresponding div in dst + * if there is one. Otherwise, return a position beyond the integer divisions. + * Return -1 on error. */ static int find_div(__isl_keep isl_basic_map *dst, __isl_keep isl_basic_map *src, unsigned div) { int i; - - unsigned total = isl_space_dim(src->dim, isl_dim_all); + isl_size n_div; + isl_size v_div; - isl_assert(dst->ctx, div <= dst->n_div, return -1); - for (i = div; i < dst->n_div; ++i) - if (isl_seq_eq(dst->div[i], src->div[div], 1+1+total+div) && - isl_seq_first_non_zero(dst->div[i]+1+1+total+div, - dst->n_div - div) == -1) + v_div = isl_basic_map_var_offset(src, isl_dim_div); + n_div = isl_basic_map_dim(dst, isl_dim_div); + if (n_div < 0 || v_div < 0) + return -1; + isl_assert(dst->ctx, div <= n_div, return -1); + for (i = div; i < n_div; ++i) + if (isl_seq_eq(dst->div[i], src->div[div], 1+1+v_div+div) && + isl_seq_first_non_zero(dst->div[i] + 1 + 1 + v_div + div, + n_div - div) == -1) return i; - return -1; + return n_div; } /* Align the divs of "dst" to those of "src", adding divs from "src" @@ -8876,8 +9242,10 @@ __isl_take isl_basic_map *dst, __isl_keep isl_basic_map *src) { int i; - int known, extended; - unsigned total; + isl_bool known; + int extended; + isl_size v_div; + isl_size dst_n_div; if (!dst || !src) return isl_basic_map_free(dst); @@ -8893,18 +9261,28 @@ "some src divs are unknown", return isl_basic_map_free(dst)); - src = isl_basic_map_order_divs(src); + v_div = isl_basic_map_var_offset(src, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(dst); + + src = isl_basic_map_order_divs(isl_basic_map_copy(src)); + if (!src) + return isl_basic_map_free(dst); extended = 0; - total = isl_space_dim(src->dim, isl_dim_all); + dst_n_div = isl_basic_map_dim(dst, isl_dim_div); + if (dst_n_div < 0) + dst = isl_basic_map_free(dst); for (i = 0; i < src->n_div; ++i) { int j = find_div(dst, src, i); - if (j < 0) { + if (j < 0) + dst = isl_basic_map_free(dst); + if (j == dst_n_div) { if (!extended) { int extra = src->n_div - i; dst = isl_basic_map_cow(dst); if (!dst) - return NULL; + goto error; dst = isl_basic_map_extend_space(dst, isl_space_copy(dst->dim), extra, 0, 2 * extra); @@ -8912,16 +9290,25 @@ } j = isl_basic_map_alloc_div(dst); if (j < 0) - return isl_basic_map_free(dst); - isl_seq_cpy(dst->div[j], src->div[i], 1+1+total+i); - isl_seq_clr(dst->div[j]+1+1+total+i, dst->n_div - i); - if (isl_basic_map_add_div_constraints(dst, j) < 0) - return isl_basic_map_free(dst); + goto error; + isl_seq_cpy(dst->div[j], src->div[i], 1+1+v_div+i); + isl_seq_clr(dst->div[j]+1+1+v_div+i, dst->n_div - i); + dst_n_div++; + dst = isl_basic_map_add_div_constraints(dst, j); + if (!dst) + goto error; } if (j != i) - isl_basic_map_swap_div(dst, i, j); + dst = isl_basic_map_swap_div(dst, i, j); + if (!dst) + goto error; } + isl_basic_map_free(src); return dst; +error: + isl_basic_map_free(src); + isl_basic_map_free(dst); + return NULL; } __isl_give isl_map *isl_map_align_divs_internal(__isl_take isl_map *map) @@ -8945,7 +9332,7 @@ return isl_map_free(map); } - ISL_F_CLR(map, ISL_MAP_NORMALIZED); + map = isl_map_unmark_normalized(map); return map; } @@ -8966,16 +9353,17 @@ __isl_give isl_map *isl_map_align_divs_to_basic_map_list( __isl_take isl_map *map, __isl_keep isl_basic_map_list *list) { - int i, n; + int i; + isl_size n; + n = isl_basic_map_list_n_basic_map(list); map = isl_map_compute_divs(map); map = isl_map_cow(map); - if (!map || !list) + if (!map || n < 0) return isl_map_free(map); if (map->n == 0) return map; - n = isl_basic_map_list_n_basic_map(list); for (i = 0; i < n; ++i) { isl_basic_map *bmap; @@ -8995,12 +9383,13 @@ __isl_give isl_basic_map_list *isl_basic_map_list_align_divs_to_basic_map( __isl_take isl_basic_map_list *list, __isl_keep isl_basic_map *bmap) { - int i, n; + int i; + isl_size n; - if (!list || !bmap) + n = isl_basic_map_list_n_basic_map(list); + if (n < 0 || !bmap) return isl_basic_map_list_free(list); - n = isl_basic_map_list_n_basic_map(list); for (i = 0; i < n; ++i) { isl_basic_map *bmap_i; @@ -9049,7 +9438,7 @@ return NULL; for (i = map->n - 1; i >= 0; --i) - remove_if_empty(map, i); + map = remove_if_empty(map, i); return map; } @@ -9057,6 +9446,24 @@ struct isl_set *isl_set_remove_empty_parts(struct isl_set *set) { return set_from_map(isl_map_remove_empty_parts(set_to_map(set))); +} + +/* Create a binary relation that maps the shared initial "pos" dimensions + * of "bset1" and "bset2" to the remaining dimensions of "bset1" and "bset2". + */ +static __isl_give isl_basic_map *join_initial(__isl_keep isl_basic_set *bset1, + __isl_keep isl_basic_set *bset2, int pos) +{ + isl_basic_map *bmap1; + isl_basic_map *bmap2; + + bmap1 = isl_basic_map_from_range(isl_basic_set_copy(bset1)); + bmap2 = isl_basic_map_from_range(isl_basic_set_copy(bset2)); + bmap1 = isl_basic_map_move_dims(bmap1, isl_dim_in, 0, + isl_dim_out, 0, pos); + bmap2 = isl_basic_map_move_dims(bmap2, isl_dim_in, 0, + isl_dim_out, 0, pos); + return isl_basic_map_range_product(bmap1, bmap2); } /* Given two basic sets bset1 and bset2, compute the maximal difference @@ -9068,31 +9475,23 @@ int pos, isl_int *opt) { isl_basic_map *bmap1; - isl_basic_map *bmap2; struct isl_ctx *ctx; struct isl_vec *obj; - unsigned total; - unsigned nparam; - unsigned dim1; + isl_size total; + isl_size nparam; + isl_size dim1; enum isl_lp_result res; - if (!bset1 || !bset2) + nparam = isl_basic_set_dim(bset1, isl_dim_param); + dim1 = isl_basic_set_dim(bset1, isl_dim_set); + if (nparam < 0 || dim1 < 0 || !bset2) return isl_lp_error; - - nparam = isl_basic_set_n_param(bset1); - dim1 = isl_basic_set_n_dim(bset1); - bmap1 = isl_basic_map_from_range(isl_basic_set_copy(bset1)); - bmap2 = isl_basic_map_from_range(isl_basic_set_copy(bset2)); - bmap1 = isl_basic_map_move_dims(bmap1, isl_dim_in, 0, - isl_dim_out, 0, pos); - bmap2 = isl_basic_map_move_dims(bmap2, isl_dim_in, 0, - isl_dim_out, 0, pos); - bmap1 = isl_basic_map_range_product(bmap1, bmap2); - if (!bmap1) + bmap1 = join_initial(bset1, bset2, pos); + total = isl_basic_map_dim(bmap1, isl_dim_all); + if (total < 0) return isl_lp_error; - total = isl_basic_map_total_dim(bmap1); ctx = bmap1->ctx; obj = isl_vec_alloc(ctx, 1 + total); if (!obj) @@ -9121,8 +9520,8 @@ * 0 if bset1 and bset2 are incomparable * -2 if some error occurred. */ -int isl_basic_set_compare_at(struct isl_basic_set *bset1, - struct isl_basic_set *bset2, int pos) +int isl_basic_set_compare_at(__isl_keep isl_basic_set *bset1, + __isl_keep isl_basic_set *bset2, int pos) { isl_int opt; enum isl_lp_result res; @@ -9160,30 +9559,37 @@ int isl_basic_set_follows_at(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2, int pos) { - isl_int opt; - enum isl_lp_result res; - int cmp; - - isl_int_init(opt); + isl_bool empty; + isl_basic_map *bmap; + isl_size dim1; - res = basic_set_maximal_difference_at(bset1, bset2, pos, &opt); + dim1 = isl_basic_set_dim(bset1, isl_dim_set); + if (dim1 < 0) + return -2; + bmap = join_initial(bset1, bset2, pos); + bmap = isl_basic_map_order_ge(bmap, isl_dim_out, 0, + isl_dim_out, dim1 - pos); + empty = isl_basic_map_is_empty(bmap); + if (empty < 0) + goto error; + if (empty) { + isl_basic_map_free(bmap); + return -1; + } + bmap = isl_basic_map_order_gt(bmap, isl_dim_out, 0, + isl_dim_out, dim1 - pos); + empty = isl_basic_map_is_empty(bmap); + if (empty < 0) + goto error; + isl_basic_map_free(bmap); + if (empty) + return 0; + return 1; +error: + isl_basic_map_free(bmap); + return -2; +} - if (res == isl_lp_empty) - cmp = -1; - else if ((res == isl_lp_ok && isl_int_is_pos(opt)) || - res == isl_lp_unbounded) - cmp = 1; - else if (res == isl_lp_ok && isl_int_is_neg(opt)) - cmp = -1; - else if (res == isl_lp_ok) - cmp = 0; - else - cmp = -2; - - isl_int_clear(opt); - return cmp; -} - /* Given two sets set1 and set2, check whether * for any common value of the parameters and dimensions preceding pos * there is a value of dimension pos in set1 that is larger @@ -9222,11 +9628,11 @@ { int i; int d; - unsigned total; + isl_size total; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return isl_bool_error; - total = isl_basic_map_total_dim(bmap); for (i = 0, d = total-1; i < bmap->n_eq && d+1 > pos; ++i) { for (; d+1 > pos; --d) if (!isl_int_is_zero(bmap->eq[i][1+d])) @@ -9323,9 +9729,8 @@ isl_bool isl_map_plain_is_fixed(__isl_keep isl_map *map, enum isl_dim_type type, unsigned pos, isl_int *val) { - if (pos >= isl_map_dim(map, type)) - isl_die(isl_map_get_ctx(map), isl_error_invalid, - "position out of bounds", return isl_bool_error); + if (isl_map_check_range(map, type, pos, 1) < 0) + return isl_bool_error; return isl_map_plain_has_fixed_var(map, map_offset(map, type) - 1 + pos, val); } @@ -9374,8 +9779,12 @@ isl_bool isl_basic_set_plain_dim_is_fixed(__isl_keep isl_basic_set *bset, unsigned dim, isl_int *val) { - return isl_basic_set_plain_has_fixed_var(bset, - isl_basic_set_n_param(bset) + dim, val); + isl_size nparam; + + nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0) + return isl_bool_error; + return isl_basic_set_plain_has_fixed_var(bset, nparam + dim, val); } /* Return -1 if the constraint "c1" should be sorted before "c2" @@ -9427,29 +9836,36 @@ int isl_basic_map_constraint_cmp(__isl_keep isl_basic_map *bmap, isl_int *c1, isl_int *c2) { - unsigned total; + isl_size total; + unsigned size; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return -2; - total = isl_basic_map_total_dim(bmap); - return sort_constraint_cmp(&c1, &c2, &total); + size = total; + return sort_constraint_cmp(&c1, &c2, &size); } __isl_give isl_basic_map *isl_basic_map_sort_constraints( __isl_take isl_basic_map *bmap) { - unsigned total; + isl_size total; + unsigned size; if (!bmap) return NULL; if (bmap->n_ineq == 0) return bmap; - if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_NORMALIZED)) + if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_SORTED)) return bmap; - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); + size = total; if (isl_sort(bmap->ineq, bmap->n_ineq, sizeof(isl_int *), - &sort_constraint_cmp, &total) < 0) + &sort_constraint_cmp, &size) < 0) return isl_basic_map_free(bmap); + ISL_F_SET(bmap, ISL_BASIC_MAP_SORTED); return bmap; } @@ -9463,21 +9879,15 @@ __isl_give isl_basic_map *isl_basic_map_normalize( __isl_take isl_basic_map *bmap) { - if (!bmap) - return NULL; - if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_NORMALIZED)) - return bmap; bmap = isl_basic_map_remove_redundancies(bmap); bmap = isl_basic_map_sort_constraints(bmap); - if (bmap) - ISL_F_SET(bmap, ISL_BASIC_MAP_NORMALIZED); return bmap; } int isl_basic_map_plain_cmp(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2) { int i, cmp; - unsigned total; + isl_size total; isl_space *space1, *space2; if (!bmap1 || !bmap2) @@ -9506,7 +9916,9 @@ return bmap1->n_ineq - bmap2->n_ineq; if (bmap1->n_div != bmap2->n_div) return bmap1->n_div - bmap2->n_div; - total = isl_basic_map_total_dim(bmap1); + total = isl_basic_map_dim(bmap1, isl_dim_all); + if (total < 0) + return -1; for (i = 0; i < bmap1->n_eq; ++i) { cmp = isl_seq_cmp(bmap1->eq[i], bmap2->eq[i], 1+total); if (cmp) @@ -9738,12 +10150,13 @@ __isl_give isl_basic_map *isl_basic_map_list_intersect( __isl_take isl_basic_map_list *list) { - int i, n; + int i; + isl_size n; isl_basic_map *bmap; - if (!list) - return NULL; n = isl_basic_map_list_n_basic_map(list); + if (n < 0) + goto error; if (n < 1) isl_die(isl_basic_map_list_get_ctx(list), isl_error_invalid, "expecting non-empty list", goto error); @@ -9778,14 +10191,15 @@ __isl_give isl_set *isl_basic_set_list_union( __isl_take isl_basic_set_list *list) { - int i, n; + int i; + isl_size n; isl_space *space; isl_basic_set *bset; isl_set *set; - if (!list) - return NULL; n = isl_basic_set_list_n_basic_set(list); + if (n < 0) + goto error; if (n < 1) isl_die(isl_basic_set_list_get_ctx(list), isl_error_invalid, "expecting non-empty list", goto error); @@ -9812,12 +10226,13 @@ */ __isl_give isl_set *isl_set_list_union(__isl_take isl_set_list *list) { - int i, n; + int i; + isl_size n; isl_set *set; - if (!list) - return NULL; n = isl_set_list_n_set(list); + if (n < 0) + goto error; if (n < 1) isl_die(isl_set_list_get_ctx(list), isl_error_invalid, "expecting non-empty list", goto error); @@ -9840,14 +10255,14 @@ __isl_give isl_basic_map *isl_basic_map_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { - isl_space *dim_result = NULL; + isl_space *space_result = NULL; struct isl_basic_map *bmap; unsigned in1, in2, out1, out2, nparam, total, pos; struct isl_dim_map *dim_map1, *dim_map2; if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0) goto error; - dim_result = isl_space_product(isl_space_copy(bmap1->dim), + space_result = isl_space_product(isl_space_copy(bmap1->dim), isl_space_copy(bmap2->dim)); in1 = isl_basic_map_dim(bmap1, isl_dim_in); @@ -9868,7 +10283,7 @@ isl_dim_map_div(dim_map1, bmap1, pos += out2); isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div); - bmap = isl_basic_map_alloc_space(dim_result, + bmap = isl_basic_map_alloc_space(space_result, bmap1->n_div + bmap2->n_div, bmap1->n_eq + bmap2->n_eq, bmap1->n_ineq + bmap2->n_ineq); @@ -9901,22 +10316,24 @@ __isl_give isl_basic_map *isl_basic_map_domain_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { + isl_space *space1, *space2; isl_space *space_result = NULL; isl_basic_map *bmap; - unsigned in1, in2, out, nparam, total, pos; + isl_size in1, in2, out, nparam; + unsigned total, pos; struct isl_dim_map *dim_map1, *dim_map2; - - if (!bmap1 || !bmap2) - goto error; - - space_result = isl_space_domain_product(isl_space_copy(bmap1->dim), - isl_space_copy(bmap2->dim)); in1 = isl_basic_map_dim(bmap1, isl_dim_in); in2 = isl_basic_map_dim(bmap2, isl_dim_in); out = isl_basic_map_dim(bmap1, isl_dim_out); nparam = isl_basic_map_dim(bmap1, isl_dim_param); + if (in1 < 0 || in2 < 0 || out < 0 || nparam < 0) + goto error; + space1 = isl_basic_map_get_space(bmap1); + space2 = isl_basic_map_get_space(bmap2); + space_result = isl_space_domain_product(space1, space2); + total = nparam + in1 + in2 + out + bmap1->n_div + bmap2->n_div; dim_map1 = isl_dim_map_alloc(bmap1->ctx, total); dim_map2 = isl_dim_map_alloc(bmap1->ctx, total); @@ -9947,27 +10364,27 @@ __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2) { isl_bool rational; - isl_space *dim_result = NULL; + isl_space *space_result = NULL; isl_basic_map *bmap; - unsigned in, out1, out2, nparam, total, pos; + isl_size in, out1, out2, nparam; + unsigned total, pos; struct isl_dim_map *dim_map1, *dim_map2; rational = isl_basic_map_is_rational(bmap1); if (rational >= 0 && rational) rational = isl_basic_map_is_rational(bmap2); - if (!bmap1 || !bmap2 || rational < 0) + in = isl_basic_map_dim(bmap1, isl_dim_in); + out1 = isl_basic_map_dim(bmap1, isl_dim_out); + out2 = isl_basic_map_dim(bmap2, isl_dim_out); + nparam = isl_basic_map_dim(bmap1, isl_dim_param); + if (in < 0 || out1 < 0 || out2 < 0 || nparam < 0 || rational < 0) goto error; if (isl_basic_map_check_equal_params(bmap1, bmap2) < 0) goto error; - dim_result = isl_space_range_product(isl_space_copy(bmap1->dim), + space_result = isl_space_range_product(isl_space_copy(bmap1->dim), isl_space_copy(bmap2->dim)); - - in = isl_basic_map_dim(bmap1, isl_dim_in); - out1 = isl_basic_map_dim(bmap1, isl_dim_out); - out2 = isl_basic_map_dim(bmap2, isl_dim_out); - nparam = isl_basic_map_dim(bmap1, isl_dim_param); total = nparam + in + out1 + out2 + bmap1->n_div + bmap2->n_div; dim_map1 = isl_dim_map_alloc(bmap1->ctx, total); @@ -9981,7 +10398,7 @@ isl_dim_map_div(dim_map1, bmap1, pos += out2); isl_dim_map_div(dim_map2, bmap2, pos += bmap1->n_div); - bmap = isl_basic_map_alloc_space(dim_result, + bmap = isl_basic_map_alloc_space(space_result, bmap1->n_div + bmap2->n_div, bmap1->n_eq + bmap2->n_eq, bmap1->n_ineq + bmap2->n_ineq); @@ -10145,21 +10562,23 @@ __isl_give isl_map *isl_map_factor_domain(__isl_take isl_map *map) { isl_space *space; - int total1, keep1, total2, keep2; - - if (!map) - return NULL; + isl_size total1, keep1, total2, keep2; + + total1 = isl_map_dim(map, isl_dim_in); + total2 = isl_map_dim(map, isl_dim_out); + if (total1 < 0 || total2 < 0) + return isl_map_free(map); if (!isl_space_domain_is_wrapping(map->dim) || !isl_space_range_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total1 = isl_space_dim(space, isl_dim_in); - total2 = isl_space_dim(space, isl_dim_out); space = isl_space_factor_domain(space); keep1 = isl_space_dim(space, isl_dim_in); keep2 = isl_space_dim(space, isl_dim_out); + if (keep1 < 0 || keep2 < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_in, keep1, total1 - keep1); map = isl_map_project_out(map, isl_dim_out, keep2, total2 - keep2); map = isl_map_reset_space(map, space); @@ -10172,21 +10591,23 @@ __isl_give isl_map *isl_map_factor_range(__isl_take isl_map *map) { isl_space *space; - int total1, keep1, total2, keep2; - - if (!map) - return NULL; + isl_size total1, keep1, total2, keep2; + + total1 = isl_map_dim(map, isl_dim_in); + total2 = isl_map_dim(map, isl_dim_out); + if (total1 < 0 || total2 < 0) + return isl_map_free(map); if (!isl_space_domain_is_wrapping(map->dim) || !isl_space_range_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total1 = isl_space_dim(space, isl_dim_in); - total2 = isl_space_dim(space, isl_dim_out); space = isl_space_factor_range(space); keep1 = isl_space_dim(space, isl_dim_in); keep2 = isl_space_dim(space, isl_dim_out); + if (keep1 < 0 || keep2 < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_in, 0, total1 - keep1); map = isl_map_project_out(map, isl_dim_out, 0, total2 - keep2); map = isl_map_reset_space(map, space); @@ -10199,18 +10620,20 @@ __isl_give isl_map *isl_map_domain_factor_domain(__isl_take isl_map *map) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!map) - return NULL; + total = isl_map_dim(map, isl_dim_in); + if (total < 0) + return isl_map_free(map); if (!isl_space_domain_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "domain is not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total = isl_space_dim(space, isl_dim_in); space = isl_space_domain_factor_domain(space); keep = isl_space_dim(space, isl_dim_in); + if (keep < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_in, keep, total - keep); map = isl_map_reset_space(map, space); @@ -10222,18 +10645,20 @@ __isl_give isl_map *isl_map_domain_factor_range(__isl_take isl_map *map) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!map) - return NULL; + total = isl_map_dim(map, isl_dim_in); + if (total < 0) + return isl_map_free(map); if (!isl_space_domain_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "domain is not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total = isl_space_dim(space, isl_dim_in); space = isl_space_domain_factor_range(space); keep = isl_space_dim(space, isl_dim_in); + if (keep < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_in, 0, total - keep); map = isl_map_reset_space(map, space); @@ -10245,18 +10670,20 @@ __isl_give isl_map *isl_map_range_factor_domain(__isl_take isl_map *map) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!map) - return NULL; + total = isl_map_dim(map, isl_dim_out); + if (total < 0) + return isl_map_free(map); if (!isl_space_range_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "range is not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total = isl_space_dim(space, isl_dim_out); space = isl_space_range_factor_domain(space); keep = isl_space_dim(space, isl_dim_out); + if (keep < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_out, keep, total - keep); map = isl_map_reset_space(map, space); @@ -10268,18 +10695,20 @@ __isl_give isl_map *isl_map_range_factor_range(__isl_take isl_map *map) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!map) - return NULL; + total = isl_map_dim(map, isl_dim_out); + if (total < 0) + return isl_map_free(map); if (!isl_space_range_is_wrapping(map->dim)) isl_die(isl_map_get_ctx(map), isl_error_invalid, "range is not a product", return isl_map_free(map)); space = isl_map_get_space(map); - total = isl_space_dim(space, isl_dim_out); space = isl_space_range_factor_range(space); keep = isl_space_dim(space, isl_dim_out); + if (keep < 0) + map = isl_map_free(map); map = isl_map_project_out(map, isl_dim_out, 0, total - keep); map = isl_map_reset_space(map, space); @@ -10314,15 +10743,15 @@ { int i; uint32_t hash = isl_hash_init(); - unsigned total; + isl_size total; if (!bmap) return 0; bmap = isl_basic_map_copy(bmap); bmap = isl_basic_map_normalize(bmap); - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return 0; - total = isl_basic_map_total_dim(bmap); isl_hash_byte(hash, bmap->n_eq & 0xFF); for (i = 0; i < bmap->n_eq; ++i) { uint32_t c_hash; @@ -10384,14 +10813,14 @@ /* Return the number of basic maps in the (current) representation of "map". */ -int isl_map_n_basic_map(__isl_keep isl_map *map) +isl_size isl_map_n_basic_map(__isl_keep isl_map *map) { - return map ? map->n : 0; + return map ? map->n : isl_size_error; } -int isl_set_n_basic_set(__isl_keep isl_set *set) +isl_size isl_set_n_basic_set(__isl_keep isl_set *set) { - return set ? set->n : 0; + return set ? set->n : isl_size_error; } isl_stat isl_map_foreach_basic_map(__isl_keep isl_map *map, @@ -10448,7 +10877,7 @@ __isl_give isl_basic_set *isl_basic_set_lift(__isl_take isl_basic_set *bset) { - isl_space *dim; + isl_space *space; if (!bset) return NULL; @@ -10457,12 +10886,12 @@ if (!bset) return NULL; - dim = isl_basic_set_get_space(bset); - dim = isl_space_lift(dim, bset->n_div); - if (!dim) + space = isl_basic_set_get_space(bset); + space = isl_space_lift(space, bset->n_div); + if (!space) goto error; isl_space_free(bset->dim); - bset->dim = dim; + bset->dim = space; bset->extra -= bset->n_div; bset->n_div = 0; @@ -10477,7 +10906,7 @@ __isl_give isl_set *isl_set_lift(__isl_take isl_set *set) { int i; - isl_space *dim; + isl_space *space; unsigned n_div; set = set_from_map(isl_map_align_divs_internal(set_to_map(set))); @@ -10490,12 +10919,12 @@ return NULL; n_div = set->p[0]->n_div; - dim = isl_set_get_space(set); - dim = isl_space_lift(dim, n_div); - if (!dim) + space = isl_set_get_space(set); + space = isl_space_lift(space, n_div); + if (!space) goto error; isl_space_free(set->dim); - set->dim = dim; + set->dim = space; for (i = 0; i < set->n; ++i) { set->p[i] = isl_basic_set_lift(set->p[i]); @@ -10511,13 +10940,12 @@ int isl_basic_set_size(__isl_keep isl_basic_set *bset) { - unsigned dim; + isl_size dim; int size = 0; - if (!bset) + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) return -1; - - dim = isl_basic_set_total_dim(bset); size += bset->n_eq * (1 + dim); size += bset->n_ineq * (1 + dim); size += bset->n_div * (2 + dim); @@ -10712,11 +11140,13 @@ struct isl_tab *tab = NULL; struct isl_tab_undo *snap; int i; + isl_size total; - if (!bset || !signs) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0 || !signs) return isl_stat_error; - bound = isl_vec_alloc(bset->ctx, 1 + isl_basic_set_total_dim(bset)); + bound = isl_vec_alloc(bset->ctx, 1 + total); tab = isl_tab_from_basic_set(bset, 0); if (!bound || !tab) goto error; @@ -10766,8 +11196,8 @@ { if (!bset || !signs) return isl_stat_error; - isl_assert(bset->ctx, first + n <= isl_basic_set_dim(bset, type), - return isl_stat_error); + if (isl_basic_set_check_range(bset, type, first, n) < 0) + return isl_stat_error; first += pos(bset->dim, type) - 1; return isl_basic_set_vars_get_sign(bset, first, n, signs); @@ -10784,19 +11214,23 @@ static isl_bool div_may_involve_output(__isl_keep isl_basic_map *bmap, int div) { int i; - unsigned n_out, o_out; - unsigned n_div, o_div; + isl_size n_out, n_div; + unsigned o_out, o_div; if (isl_int_is_zero(bmap->div[div][0])) return isl_bool_true; n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (n_out < 0) + return isl_bool_error; o_out = isl_basic_map_offset(bmap, isl_dim_out); if (isl_seq_first_non_zero(bmap->div[div] + 1 + o_out, n_out) != -1) return isl_bool_true; n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_bool_error; o_div = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < n_div; ++i) { @@ -10860,19 +11294,19 @@ { int i, j; isl_ctx *ctx; - unsigned total; - unsigned n_div, o_div; - unsigned n_out, o_out; + isl_size total; + isl_size n_div, n_out; + unsigned o_div, o_out; int less; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + n_out = isl_basic_map_dim(bmap, isl_dim_out); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (total < 0 || n_out < 0 || n_div < 0) return -1; ctx = isl_basic_map_get_ctx(bmap); - total = isl_basic_map_total_dim(bmap); - n_out = isl_basic_map_dim(bmap, isl_dim_out); o_out = isl_basic_map_offset(bmap, isl_dim_out); - n_div = isl_basic_map_dim(bmap, isl_dim_div); o_div = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < bmap->n_ineq; ++i) { if (!isl_int_abs_eq(bmap->ineq[i][o_out + pos], ctx->one)) @@ -10937,15 +11371,15 @@ int pos, int *div, int *ineq) { int j, k, l; - unsigned n_out, o_out; - unsigned n_div, o_div; + isl_size n_div, n_out; + unsigned o_div, o_out; - if (!bmap) + n_out = isl_basic_map_dim(bmap, isl_dim_out); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_out < 0 || n_div < 0) return -1; - n_out = isl_basic_map_dim(bmap, isl_dim_out); o_out = isl_basic_map_offset(bmap, isl_dim_out); - n_div = isl_basic_map_dim(bmap, isl_dim_div); o_div = isl_basic_map_offset(bmap, isl_dim_div); if (ineq) @@ -10992,12 +11426,11 @@ isl_bool isl_basic_map_plain_is_single_valued(__isl_keep isl_basic_map *bmap) { int i; - unsigned n_out; + isl_size n_out; - if (!bmap) - return isl_bool_error; - n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (n_out < 0) + return isl_bool_error; for (i = 0; i < n_out; ++i) { int eq; @@ -11184,16 +11617,18 @@ isl_bool isl_basic_set_is_box(__isl_keep isl_basic_set *bset) { int i, j; - unsigned nvar; + isl_size nvar, n_div; unsigned ovar; - if (!bset) + n_div = isl_basic_set_dim(bset, isl_dim_div); + if (n_div < 0) return isl_bool_error; - - if (isl_basic_set_dim(bset, isl_dim_div) != 0) + if (n_div != 0) return isl_bool_false; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0) + return isl_bool_error; ovar = isl_space_offset(bset->dim, isl_dim_set); for (j = 0; j < nvar; ++j) { int lower = 0, upper = 0; @@ -11307,20 +11742,15 @@ __isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap) { - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + isl_space *space; - bmap->dim = isl_space_wrap(bmap->dim); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_wrap(space); + bmap = isl_basic_map_restore_space(bmap, space); bmap = isl_basic_map_finalize(bmap); return bset_from_bmap(bmap); -error: - isl_basic_map_free(bmap); - return NULL; } /* Given a map A -> B, return the set (A -> B). @@ -11360,32 +11790,22 @@ __isl_give isl_basic_map *isl_basic_map_reset(__isl_take isl_basic_map *bmap, enum isl_dim_type type) { - if (!bmap) - return NULL; - - if (!isl_space_is_named_or_nested(bmap->dim, type)) - return bmap; - - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + isl_space *space; - bmap->dim = isl_space_reset(bmap->dim, type); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_reset(space, type); + bmap = isl_basic_map_restore_space(bmap, space); - bmap = isl_basic_map_finalize(bmap); + bmap = isl_basic_map_mark_final(bmap); return bmap; -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_map *isl_map_reset(__isl_take isl_map *map, enum isl_dim_type type) { int i; + isl_space *space; if (!map) return NULL; @@ -11402,9 +11822,10 @@ if (!map->p[i]) goto error; } - map->dim = isl_space_reset(map->dim, type); - if (!map->dim) - goto error; + + space = isl_map_take_space(map); + space = isl_space_reset(space, type); + map = isl_map_restore_space(map, space); return map; error: @@ -11414,26 +11835,15 @@ __isl_give isl_basic_map *isl_basic_map_flatten(__isl_take isl_basic_map *bmap) { - if (!bmap) - return NULL; - - if (!bmap->dim->nested[0] && !bmap->dim->nested[1]) - return bmap; - - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + isl_space *space; - bmap->dim = isl_space_flatten(bmap->dim); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_flatten(space); + bmap = isl_basic_map_restore_space(bmap, space); - bmap = isl_basic_map_finalize(bmap); + bmap = isl_basic_map_mark_final(bmap); return bmap; -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_basic_set *isl_basic_set_flatten(__isl_take isl_basic_set *bset) @@ -11444,51 +11854,29 @@ __isl_give isl_basic_map *isl_basic_map_flatten_domain( __isl_take isl_basic_map *bmap) { - if (!bmap) - return NULL; - - if (!bmap->dim->nested[0]) - return bmap; - - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + isl_space *space; - bmap->dim = isl_space_flatten_domain(bmap->dim); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_flatten_domain(space); + bmap = isl_basic_map_restore_space(bmap, space); - bmap = isl_basic_map_finalize(bmap); + bmap = isl_basic_map_mark_final(bmap); return bmap; -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_basic_map *isl_basic_map_flatten_range( __isl_take isl_basic_map *bmap) { - if (!bmap) - return NULL; - - if (!bmap->dim->nested[1]) - return bmap; - - bmap = isl_basic_map_cow(bmap); - if (!bmap) - return NULL; + isl_space *space; - bmap->dim = isl_space_flatten_range(bmap->dim); - if (!bmap->dim) - goto error; + space = isl_basic_map_take_space(bmap); + space = isl_space_flatten_range(space); + bmap = isl_basic_map_restore_space(bmap, space); - bmap = isl_basic_map_finalize(bmap); + bmap = isl_basic_map_mark_final(bmap); return bmap; -error: - isl_basic_map_free(bmap); - return NULL; } /* Remove any internal structure from the spaces of domain and range of "map". @@ -11511,12 +11899,13 @@ __isl_give isl_map *isl_set_flatten_map(__isl_take isl_set *set) { - isl_space *dim, *flat_dim; + isl_space *space, *flat_space; isl_map *map; - dim = isl_set_get_space(set); - flat_dim = isl_space_flatten(isl_space_copy(dim)); - map = isl_map_identity(isl_space_join(isl_space_reverse(dim), flat_dim)); + space = isl_set_get_space(set); + flat_space = isl_space_flatten(isl_space_copy(space)); + map = isl_map_identity(isl_space_join(isl_space_reverse(space), + flat_space)); map = isl_map_intersect_domain(map, set); return map; @@ -11549,25 +11938,25 @@ } /* Reorder the dimensions of "bmap" according to the given dim_map - * and set the dimension specification to "dim" and + * and set the dimension specification to "space" and * perform Gaussian elimination on the result. */ __isl_give isl_basic_map *isl_basic_map_realign(__isl_take isl_basic_map *bmap, - __isl_take isl_space *dim, __isl_take struct isl_dim_map *dim_map) + __isl_take isl_space *space, __isl_take struct isl_dim_map *dim_map) { isl_basic_map *res; unsigned flags; + isl_size n_div; - bmap = isl_basic_map_cow(bmap); - if (!bmap || !dim || !dim_map) + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0 || !space || !dim_map) goto error; flags = bmap->flags; ISL_FL_CLR(flags, ISL_BASIC_MAP_FINAL); - ISL_FL_CLR(flags, ISL_BASIC_MAP_NORMALIZED); + ISL_FL_CLR(flags, ISL_BASIC_MAP_SORTED); ISL_FL_CLR(flags, ISL_BASIC_MAP_NORMALIZED_DIVS); - res = isl_basic_map_alloc_space(dim, - bmap->n_div, bmap->n_eq, bmap->n_ineq); + res = isl_basic_map_alloc_space(space, n_div, bmap->n_eq, bmap->n_ineq); res = isl_basic_map_add_constraints_dim_map(res, bmap, dim_map); if (res) res->flags = flags; @@ -11575,9 +11964,9 @@ res = isl_basic_map_finalize(res); return res; error: - free(dim_map); + isl_dim_map_free(dim_map); isl_basic_map_free(bmap); - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -11596,23 +11985,25 @@ for (i = 0; i < map->n; ++i) { struct isl_dim_map *dim_map_i; + isl_space *space; dim_map_i = isl_dim_map_extend(dim_map, map->p[i]); - map->p[i] = isl_basic_map_realign(map->p[i], - isl_space_copy(r->dim), dim_map_i); + space = isl_reordering_get_space(r); + map->p[i] = isl_basic_map_realign(map->p[i], space, dim_map_i); if (!map->p[i]) goto error; } - map = isl_map_reset_space(map, isl_space_copy(r->dim)); + map = isl_map_reset_space(map, isl_reordering_get_space(r)); + map = isl_map_unmark_normalized(map); isl_reordering_free(r); - free(dim_map); + isl_dim_map_free(dim_map); return map; error: - free(dim_map); + isl_dim_map_free(dim_map); isl_map_free(map); isl_reordering_free(r); return NULL; @@ -11645,115 +12036,360 @@ if (!aligned) { isl_reordering *exp; - model = isl_space_drop_dims(model, isl_dim_in, - 0, isl_space_dim(model, isl_dim_in)); - model = isl_space_drop_dims(model, isl_dim_out, - 0, isl_space_dim(model, isl_dim_out)); exp = isl_parameter_alignment_reordering(map->dim, model); exp = isl_reordering_extend_space(exp, isl_map_get_space(map)); map = isl_map_realign(map, exp); + } + + isl_space_free(model); + return map; +error: + isl_space_free(model); + isl_map_free(map); + return NULL; +} + +__isl_give isl_set *isl_set_align_params(__isl_take isl_set *set, + __isl_take isl_space *model) +{ + return isl_map_align_params(set, model); +} + +/* Align the parameters of "bmap" to those of "model", introducing + * additional parameters if needed. + */ +__isl_give isl_basic_map *isl_basic_map_align_params( + __isl_take isl_basic_map *bmap, __isl_take isl_space *model) +{ + isl_ctx *ctx; + isl_bool equal_params; + + if (!bmap || !model) + goto error; + + ctx = isl_space_get_ctx(model); + if (!isl_space_has_named_params(model)) + isl_die(ctx, isl_error_invalid, + "model has unnamed parameters", goto error); + if (isl_basic_map_check_named_params(bmap) < 0) + goto error; + equal_params = isl_space_has_equal_params(bmap->dim, model); + if (equal_params < 0) + goto error; + if (!equal_params) { + isl_reordering *exp; + struct isl_dim_map *dim_map; + + exp = isl_parameter_alignment_reordering(bmap->dim, model); + exp = isl_reordering_extend_space(exp, + isl_basic_map_get_space(bmap)); + dim_map = isl_dim_map_from_reordering(exp); + bmap = isl_basic_map_realign(bmap, + isl_reordering_get_space(exp), + isl_dim_map_extend(dim_map, bmap)); + isl_reordering_free(exp); + isl_dim_map_free(dim_map); + } + + isl_space_free(model); + return bmap; +error: + isl_space_free(model); + isl_basic_map_free(bmap); + return NULL; +} + +/* Do "bset" and "space" have the same parameters? + */ +isl_bool isl_basic_set_space_has_equal_params(__isl_keep isl_basic_set *bset, + __isl_keep isl_space *space) +{ + isl_space *bset_space; + + bset_space = isl_basic_set_peek_space(bset); + return isl_space_has_equal_params(bset_space, space); +} + +/* Do "map" and "space" have the same parameters? + */ +isl_bool isl_map_space_has_equal_params(__isl_keep isl_map *map, + __isl_keep isl_space *space) +{ + isl_space *map_space; + + map_space = isl_map_peek_space(map); + return isl_space_has_equal_params(map_space, space); +} + +/* Do "set" and "space" have the same parameters? + */ +isl_bool isl_set_space_has_equal_params(__isl_keep isl_set *set, + __isl_keep isl_space *space) +{ + return isl_map_space_has_equal_params(set_to_map(set), space); +} + +/* Align the parameters of "bset" to those of "model", introducing + * additional parameters if needed. + */ +__isl_give isl_basic_set *isl_basic_set_align_params( + __isl_take isl_basic_set *bset, __isl_take isl_space *model) +{ + return isl_basic_map_align_params(bset, model); +} + +/* Drop all parameters not referenced by "map". + */ +__isl_give isl_map *isl_map_drop_unused_params(__isl_take isl_map *map) +{ + int i; + isl_size n; + + n = isl_map_dim(map, isl_dim_param); + if (isl_map_check_named_params(map) < 0 || n < 0) + return isl_map_free(map); + + for (i = n - 1; i >= 0; i--) { + isl_bool involves; + + involves = isl_map_involves_dims(map, isl_dim_param, i, 1); + if (involves < 0) + return isl_map_free(map); + if (!involves) + map = isl_map_project_out(map, isl_dim_param, i, 1); + } + + return map; +} + +/* Drop all parameters not referenced by "set". + */ +__isl_give isl_set *isl_set_drop_unused_params( + __isl_take isl_set *set) +{ + return set_from_map(isl_map_drop_unused_params(set_to_map(set))); +} + +/* Drop all parameters not referenced by "bmap". + */ +__isl_give isl_basic_map *isl_basic_map_drop_unused_params( + __isl_take isl_basic_map *bmap) +{ + isl_size nparam; + int i; + + nparam = isl_basic_map_dim(bmap, isl_dim_param); + if (nparam < 0 || isl_basic_map_check_named_params(bmap) < 0) + return isl_basic_map_free(bmap); + + for (i = nparam - 1; i >= 0; i--) { + isl_bool involves; + + involves = isl_basic_map_involves_dims(bmap, + isl_dim_param, i, 1); + if (involves < 0) + return isl_basic_map_free(bmap); + if (!involves) + bmap = isl_basic_map_drop(bmap, isl_dim_param, i, 1); + } + + return bmap; +} + +/* Drop all parameters not referenced by "bset". + */ +__isl_give isl_basic_set *isl_basic_set_drop_unused_params( + __isl_take isl_basic_set *bset) +{ + return bset_from_bmap(isl_basic_map_drop_unused_params( + bset_to_bmap(bset))); +} + +/* Given a tuple of identifiers "tuple" in a space that corresponds + * to that of "set", if any of those identifiers appear as parameters + * in "set", then equate those parameters with the corresponding + * set dimensions and project out the parameters. + * The result therefore has no such parameters. + */ +static __isl_give isl_set *equate_params(__isl_take isl_set *set, + __isl_keep isl_multi_id *tuple) +{ + int i; + isl_size n; + isl_space *set_space, *tuple_space; + + set_space = isl_set_peek_space(set); + tuple_space = isl_multi_id_peek_space(tuple); + if (isl_space_check_equal_tuples(tuple_space, set_space) < 0) + return isl_set_free(set); + n = isl_multi_id_size(tuple); + if (n < 0) + return isl_set_free(set); + for (i = 0; i < n; ++i) { + isl_id *id; + int pos; + + id = isl_multi_id_get_at(tuple, i); + if (!id) + return isl_set_free(set); + pos = isl_set_find_dim_by_id(set, isl_dim_param, id); + isl_id_free(id); + if (pos < 0) + continue; + set = isl_set_equate(set, isl_dim_param, pos, isl_dim_set, i); + set = isl_set_project_out(set, isl_dim_param, pos, 1); + } + return set; +} + +/* Bind the set dimensions of "set" to parameters with identifiers + * specified by "tuple", living in the same space as "set". + * + * If no parameters with these identifiers appear in "set" already, + * then the set dimensions are simply reinterpreted as parameters. + * Otherwise, the parameters are first equated to the corresponding + * set dimensions. + */ +__isl_give isl_set *isl_set_bind(__isl_take isl_set *set, + __isl_take isl_multi_id *tuple) +{ + isl_space *space; + + set = equate_params(set, tuple); + space = isl_set_get_space(set); + space = isl_space_bind_set(space, tuple); + isl_multi_id_free(tuple); + set = isl_set_reset_space(set, space); + + return set; +} + +/* Given a tuple of identifiers "tuple" in a space that corresponds + * to the domain of "map", if any of those identifiers appear as parameters + * in "map", then equate those parameters with the corresponding + * input dimensions and project out the parameters. + * The result therefore has no such parameters. + */ +static __isl_give isl_map *map_equate_params(__isl_take isl_map *map, + __isl_keep isl_multi_id *tuple) +{ + int i; + isl_size n; + isl_space *map_space, *tuple_space; + + map_space = isl_map_peek_space(map); + tuple_space = isl_multi_id_peek_space(tuple); + if (isl_space_check_domain_tuples(tuple_space, map_space) < 0) + return isl_map_free(map); + n = isl_multi_id_size(tuple); + if (n < 0) + return isl_map_free(map); + for (i = 0; i < n; ++i) { + isl_id *id; + int pos; + + id = isl_multi_id_get_at(tuple, i); + if (!id) + return isl_map_free(map); + pos = isl_map_find_dim_by_id(map, isl_dim_param, id); + isl_id_free(id); + if (pos < 0) + continue; + map = isl_map_equate(map, isl_dim_param, pos, isl_dim_in, i); + map = isl_map_project_out(map, isl_dim_param, pos, 1); } - - isl_space_free(model); return map; -error: - isl_space_free(model); - isl_map_free(map); - return NULL; -} - -__isl_give isl_set *isl_set_align_params(__isl_take isl_set *set, - __isl_take isl_space *model) -{ - return isl_map_align_params(set, model); } -/* Align the parameters of "bmap" to those of "model", introducing - * additional parameters if needed. +/* Bind the input dimensions of "map" to parameters with identifiers + * specified by "tuple", living in the domain space of "map". + * + * If no parameters with these identifiers appear in "map" already, + * then the input dimensions are simply reinterpreted as parameters. + * Otherwise, the parameters are first equated to the corresponding + * input dimensions. */ -__isl_give isl_basic_map *isl_basic_map_align_params( - __isl_take isl_basic_map *bmap, __isl_take isl_space *model) +__isl_give isl_set *isl_map_bind_domain(__isl_take isl_map *map, + __isl_take isl_multi_id *tuple) { - isl_ctx *ctx; - isl_bool equal_params; - - if (!bmap || !model) - goto error; - - ctx = isl_space_get_ctx(model); - if (!isl_space_has_named_params(model)) - isl_die(ctx, isl_error_invalid, - "model has unnamed parameters", goto error); - if (!isl_space_has_named_params(bmap->dim)) - isl_die(ctx, isl_error_invalid, - "relation has unnamed parameters", goto error); - equal_params = isl_space_has_equal_params(bmap->dim, model); - if (equal_params < 0) - goto error; - if (!equal_params) { - isl_reordering *exp; - struct isl_dim_map *dim_map; + isl_space *space; + isl_set *set; - model = isl_space_drop_dims(model, isl_dim_in, - 0, isl_space_dim(model, isl_dim_in)); - model = isl_space_drop_dims(model, isl_dim_out, - 0, isl_space_dim(model, isl_dim_out)); - exp = isl_parameter_alignment_reordering(bmap->dim, model); - exp = isl_reordering_extend_space(exp, - isl_basic_map_get_space(bmap)); - dim_map = isl_dim_map_from_reordering(exp); - bmap = isl_basic_map_realign(bmap, - exp ? isl_space_copy(exp->dim) : NULL, - isl_dim_map_extend(dim_map, bmap)); - isl_reordering_free(exp); - free(dim_map); - } + map = map_equate_params(map, tuple); + space = isl_map_get_space(map); + space = isl_space_bind_map_domain(space, tuple); + isl_multi_id_free(tuple); + set = set_from_map(isl_map_reset_space(map, space)); - isl_space_free(model); - return bmap; -error: - isl_space_free(model); - isl_basic_map_free(bmap); - return NULL; + return set; } -/* Do "bset" and "space" have the same parameters? +/* Bind the output dimensions of "map" to parameters with identifiers + * specified by "tuple", living in the range space of "map". + * + * Since binding is more easily implemented on the domain, + * bind the input dimensions of the inverse of "map". */ -isl_bool isl_basic_set_space_has_equal_params(__isl_keep isl_basic_set *bset, - __isl_keep isl_space *space) +__isl_give isl_set *isl_map_bind_range(__isl_take isl_map *map, + __isl_take isl_multi_id *tuple) { - isl_space *bset_space; - - bset_space = isl_basic_set_peek_space(bset); - return isl_space_has_equal_params(bset_space, space); + return isl_map_bind_domain(isl_map_reverse(map), tuple); } -/* Do "map" and "space" have the same parameters? +/* Insert a domain corresponding to "tuple" + * into the nullary or unary relation "set". + * The result has an extra initial tuple and is therefore + * either a unary or binary relation. + * Any parameters with identifiers in "tuple" are reinterpreted + * as the corresponding domain dimensions. */ -isl_bool isl_map_space_has_equal_params(__isl_keep isl_map *map, - __isl_keep isl_space *space) +static __isl_give isl_map *unbind_params_insert_domain( + __isl_take isl_set *set, __isl_take isl_multi_id *tuple) { - isl_space *map_space; + isl_space *space; + isl_reordering *r; - map_space = isl_map_peek_space(map); - return isl_space_has_equal_params(map_space, space); + space = isl_set_peek_space(set); + r = isl_reordering_unbind_params_insert_domain(space, tuple); + isl_multi_id_free(tuple); + + return isl_map_realign(set_to_map(set), r); } -/* Do "set" and "space" have the same parameters? +/* Construct a set with "tuple" as domain from the parameter domain "set". + * Any parameters with identifiers in "tuple" are reinterpreted + * as the corresponding set dimensions. */ -isl_bool isl_set_space_has_equal_params(__isl_keep isl_set *set, - __isl_keep isl_space *space) +__isl_give isl_set *isl_set_unbind_params(__isl_take isl_set *set, + __isl_take isl_multi_id *tuple) { - return isl_map_space_has_equal_params(set_to_map(set), space); + isl_bool is_params; + + is_params = isl_set_is_params(set); + if (is_params < 0) + set = isl_set_free(set); + else if (!is_params) + isl_die(isl_set_get_ctx(set), isl_error_invalid, + "expecting parameter domain", set = isl_set_free(set)); + return set_from_map(unbind_params_insert_domain(set, tuple)); } -/* Align the parameters of "bset" to those of "model", introducing - * additional parameters if needed. +/* Construct a map with "domain" as domain and "set" as range. + * Any parameters with identifiers in "domain" are reinterpreted + * as the corresponding domain dimensions. */ -__isl_give isl_basic_set *isl_basic_set_align_params( - __isl_take isl_basic_set *bset, __isl_take isl_space *model) +__isl_give isl_map *isl_set_unbind_params_insert_domain( + __isl_take isl_set *set, __isl_take isl_multi_id *domain) { - return isl_basic_map_align_params(bset, model); + isl_bool is_params; + + is_params = isl_set_is_params(set); + if (is_params < 0) + set = isl_set_free(set); + else if (is_params) + isl_die(isl_set_get_ctx(set), isl_error_invalid, + "expecting proper set", set = isl_set_free(set)); + return unbind_params_insert_domain(set, domain); } __isl_give isl_mat *isl_basic_map_equalities_matrix( @@ -11765,17 +12401,21 @@ struct isl_mat *mat; int i, j, k; int pos; + isl_size total; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return NULL; - mat = isl_mat_alloc(bmap->ctx, bmap->n_eq, - isl_basic_map_total_dim(bmap) + 1); + mat = isl_mat_alloc(bmap->ctx, bmap->n_eq, total + 1); if (!mat) return NULL; for (i = 0; i < bmap->n_eq; ++i) for (j = 0, pos = 0; j < 5; ++j) { int off = isl_basic_map_offset(bmap, c[j]); - for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) { + isl_size dim = isl_basic_map_dim(bmap, c[j]); + if (dim < 0) + return isl_mat_free(mat); + for (k = 0; k < dim; ++k) { isl_int_set(mat->row[i][pos], bmap->eq[i][off + k]); ++pos; @@ -11794,17 +12434,21 @@ struct isl_mat *mat; int i, j, k; int pos; + isl_size total; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return NULL; - mat = isl_mat_alloc(bmap->ctx, bmap->n_ineq, - isl_basic_map_total_dim(bmap) + 1); + mat = isl_mat_alloc(bmap->ctx, bmap->n_ineq, total + 1); if (!mat) return NULL; for (i = 0; i < bmap->n_ineq; ++i) for (j = 0, pos = 0; j < 5; ++j) { int off = isl_basic_map_offset(bmap, c[j]); - for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) { + isl_size dim = isl_basic_map_dim(bmap, c[j]); + if (dim < 0) + return isl_mat_free(mat); + for (k = 0; k < dim; ++k) { isl_int_set(mat->row[i][pos], bmap->ineq[i][off + k]); ++pos; @@ -11815,35 +12459,37 @@ } __isl_give isl_basic_map *isl_basic_map_from_constraint_matrices( - __isl_take isl_space *dim, + __isl_take isl_space *space, __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4, enum isl_dim_type c5) { enum isl_dim_type c[5] = { c1, c2, c3, c4, c5 }; - isl_basic_map *bmap; + isl_basic_map *bmap = NULL; + isl_size dim; unsigned total; unsigned extra; int i, j, k, l; int pos; - if (!dim || !eq || !ineq) + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0 || !eq || !ineq) goto error; if (eq->n_col != ineq->n_col) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "equalities and inequalities matrices should have " "same number of columns", goto error); - total = 1 + isl_space_dim(dim, isl_dim_all); + total = 1 + dim; if (eq->n_col < total) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "number of columns too small", goto error); extra = eq->n_col - total; - bmap = isl_basic_map_alloc_space(isl_space_copy(dim), extra, + bmap = isl_basic_map_alloc_space(isl_space_copy(space), extra, eq->n_row, ineq->n_row); if (!bmap) goto error; @@ -11859,7 +12505,10 @@ goto error; for (j = 0, pos = 0; j < 5; ++j) { int off = isl_basic_map_offset(bmap, c[j]); - for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) { + isl_size dim = isl_basic_map_dim(bmap, c[j]); + if (dim < 0) + goto error; + for (k = 0; k < dim; ++k) { isl_int_set(bmap->eq[l][off + k], eq->row[i][pos]); ++pos; @@ -11872,7 +12521,10 @@ goto error; for (j = 0, pos = 0; j < 5; ++j) { int off = isl_basic_map_offset(bmap, c[j]); - for (k = 0; k < isl_basic_map_dim(bmap, c[j]); ++k) { + isl_size dim = isl_basic_map_dim(bmap, c[j]); + if (dim < 0) + goto error; + for (k = 0; k < dim; ++k) { isl_int_set(bmap->ineq[l][off + k], ineq->row[i][pos]); ++pos; @@ -11880,16 +12532,17 @@ } } - isl_space_free(dim); + isl_space_free(space); isl_mat_free(eq); isl_mat_free(ineq); bmap = isl_basic_map_simplify(bmap); return isl_basic_map_finalize(bmap); error: - isl_space_free(dim); + isl_space_free(space); isl_mat_free(eq); isl_mat_free(ineq); + isl_basic_map_free(bmap); return NULL; } @@ -11942,8 +12595,9 @@ __isl_give isl_basic_map *isl_basic_map_zip(__isl_take isl_basic_map *bmap) { unsigned pos; - unsigned n1; - unsigned n2; + isl_size n_in; + isl_size n1; + isl_size n2; if (!bmap) return NULL; @@ -11951,10 +12605,12 @@ if (!isl_basic_map_can_zip(bmap)) isl_die(bmap->ctx, isl_error_invalid, "basic map cannot be zipped", goto error); - pos = isl_basic_map_offset(bmap, isl_dim_in) + - isl_space_dim(bmap->dim->nested[0], isl_dim_in); + n_in = isl_space_dim(bmap->dim->nested[0], isl_dim_in); n1 = isl_space_dim(bmap->dim->nested[0], isl_dim_out); n2 = isl_space_dim(bmap->dim->nested[1], isl_dim_in); + if (n_in < 0 || n1 < 0 || n2 < 0) + return isl_basic_map_free(bmap); + pos = isl_basic_map_offset(bmap, isl_dim_in) + n_in; bmap = isl_basic_map_cow(bmap); bmap = isl_basic_map_swap_vars(bmap, pos, n1, n2); if (!bmap) @@ -11974,30 +12630,14 @@ */ __isl_give isl_map *isl_map_zip(__isl_take isl_map *map) { - int i; - if (!map) return NULL; if (!isl_map_can_zip(map)) isl_die(map->ctx, isl_error_invalid, "map cannot be zipped", goto error); - - map = isl_map_cow(map); - if (!map) - return NULL; - - for (i = 0; i < map->n; ++i) { - map->p[i] = isl_basic_map_zip(map->p[i]); - if (!map->p[i]) - goto error; - } - - map->dim = isl_space_zip(map->dim); - if (!map->dim) - goto error; - return map; + return isl_map_transform(map, &isl_space_zip, &isl_basic_map_zip); error: isl_map_free(map); return NULL; @@ -12133,173 +12773,6 @@ { return isl_map_change_space(map, &isl_map_can_uncurry, "map cannot be uncurried", &isl_space_uncurry); -} - -/* Construct a basic map mapping the domain of the affine expression - * to a one-dimensional range prescribed by the affine expression. - * If "rational" is set, then construct a rational basic map. - * - * A NaN affine expression cannot be converted to a basic map. - */ -static __isl_give isl_basic_map *isl_basic_map_from_aff2( - __isl_take isl_aff *aff, int rational) -{ - int k; - int pos; - isl_bool is_nan; - isl_local_space *ls; - isl_basic_map *bmap = NULL; - - if (!aff) - return NULL; - is_nan = isl_aff_is_nan(aff); - if (is_nan < 0) - goto error; - if (is_nan) - isl_die(isl_aff_get_ctx(aff), isl_error_invalid, - "cannot convert NaN", goto error); - - ls = isl_aff_get_local_space(aff); - bmap = isl_basic_map_from_local_space(ls); - bmap = isl_basic_map_extend_constraints(bmap, 1, 0); - k = isl_basic_map_alloc_equality(bmap); - if (k < 0) - goto error; - - pos = isl_basic_map_offset(bmap, isl_dim_out); - isl_seq_cpy(bmap->eq[k], aff->v->el + 1, pos); - isl_int_neg(bmap->eq[k][pos], aff->v->el[0]); - isl_seq_cpy(bmap->eq[k] + pos + 1, aff->v->el + 1 + pos, - aff->v->size - (pos + 1)); - - isl_aff_free(aff); - if (rational) - bmap = isl_basic_map_set_rational(bmap); - bmap = isl_basic_map_gauss(bmap, NULL); - bmap = isl_basic_map_finalize(bmap); - return bmap; -error: - isl_aff_free(aff); - isl_basic_map_free(bmap); - return NULL; -} - -/* Construct a basic map mapping the domain of the affine expression - * to a one-dimensional range prescribed by the affine expression. - */ -__isl_give isl_basic_map *isl_basic_map_from_aff(__isl_take isl_aff *aff) -{ - return isl_basic_map_from_aff2(aff, 0); -} - -/* Construct a map mapping the domain of the affine expression - * to a one-dimensional range prescribed by the affine expression. - */ -__isl_give isl_map *isl_map_from_aff(__isl_take isl_aff *aff) -{ - isl_basic_map *bmap; - - bmap = isl_basic_map_from_aff(aff); - return isl_map_from_basic_map(bmap); -} - -/* Construct a basic map mapping the domain the multi-affine expression - * to its range, with each dimension in the range equated to the - * corresponding affine expression. - * If "rational" is set, then construct a rational basic map. - */ -__isl_give isl_basic_map *isl_basic_map_from_multi_aff2( - __isl_take isl_multi_aff *maff, int rational) -{ - int i; - isl_space *space; - isl_basic_map *bmap; - - if (!maff) - return NULL; - - if (isl_space_dim(maff->space, isl_dim_out) != maff->n) - isl_die(isl_multi_aff_get_ctx(maff), isl_error_internal, - "invalid space", goto error); - - space = isl_space_domain(isl_multi_aff_get_space(maff)); - bmap = isl_basic_map_universe(isl_space_from_domain(space)); - if (rational) - bmap = isl_basic_map_set_rational(bmap); - - for (i = 0; i < maff->n; ++i) { - isl_aff *aff; - isl_basic_map *bmap_i; - - aff = isl_aff_copy(maff->p[i]); - bmap_i = isl_basic_map_from_aff2(aff, rational); - - bmap = isl_basic_map_flat_range_product(bmap, bmap_i); - } - - bmap = isl_basic_map_reset_space(bmap, isl_multi_aff_get_space(maff)); - - isl_multi_aff_free(maff); - return bmap; -error: - isl_multi_aff_free(maff); - return NULL; -} - -/* Construct a basic map mapping the domain the multi-affine expression - * to its range, with each dimension in the range equated to the - * corresponding affine expression. - */ -__isl_give isl_basic_map *isl_basic_map_from_multi_aff( - __isl_take isl_multi_aff *ma) -{ - return isl_basic_map_from_multi_aff2(ma, 0); -} - -/* Construct a map mapping the domain the multi-affine expression - * to its range, with each dimension in the range equated to the - * corresponding affine expression. - */ -__isl_give isl_map *isl_map_from_multi_aff(__isl_take isl_multi_aff *maff) -{ - isl_basic_map *bmap; - - bmap = isl_basic_map_from_multi_aff(maff); - return isl_map_from_basic_map(bmap); -} - -/* Construct a basic map mapping a domain in the given space to - * to an n-dimensional range, with n the number of elements in the list, - * where each coordinate in the range is prescribed by the - * corresponding affine expression. - * The domains of all affine expressions in the list are assumed to match - * domain_dim. - */ -__isl_give isl_basic_map *isl_basic_map_from_aff_list( - __isl_take isl_space *domain_dim, __isl_take isl_aff_list *list) -{ - int i; - isl_space *dim; - isl_basic_map *bmap; - - if (!list) - return NULL; - - dim = isl_space_from_domain(domain_dim); - bmap = isl_basic_map_universe(dim); - - for (i = 0; i < list->n; ++i) { - isl_aff *aff; - isl_basic_map *bmap_i; - - aff = isl_aff_copy(list->p[i]); - bmap_i = isl_basic_map_from_aff(aff); - - bmap = isl_basic_map_flat_range_product(bmap, bmap_i); - } - - isl_aff_list_free(list); - return bmap; } __isl_give isl_set *isl_set_equate(__isl_take isl_set *set, @@ -12315,16 +12788,13 @@ { isl_basic_map *bmap = NULL; int i; - - if (!space) - return NULL; + isl_size total; - if (pos1 >= isl_space_dim(space, type1)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "index out of bounds", goto error); - if (pos2 >= isl_space_dim(space, type2)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "index out of bounds", goto error); + total = isl_space_dim(space, isl_dim_all); + if (total < 0 || + isl_space_check_range(space, type1, pos1, 1) < 0 || + isl_space_check_range(space, type2, pos2, 1) < 0) + goto error; if (type1 == type2 && pos1 == pos2) return isl_basic_map_universe(space); @@ -12333,7 +12803,7 @@ i = isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; - isl_seq_clr(bmap->eq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[i], 1 + total); pos1 += isl_basic_map_offset(bmap, type1); pos2 += isl_basic_map_offset(bmap, type2); isl_int_set_si(bmap->eq[i][pos1], -1); @@ -12382,22 +12852,21 @@ { isl_basic_map *bmap = NULL; int i; - - if (!map) - return NULL; + isl_size total; - if (pos1 >= isl_map_dim(map, type1)) - isl_die(map->ctx, isl_error_invalid, - "index out of bounds", goto error); - if (pos2 >= isl_map_dim(map, type2)) - isl_die(map->ctx, isl_error_invalid, - "index out of bounds", goto error); + if (isl_map_check_range(map, type1, pos1, 1) < 0) + return isl_map_free(map); + if (isl_map_check_range(map, type2, pos2, 1) < 0) + return isl_map_free(map); + total = isl_map_dim(map, isl_dim_all); + if (total < 0) + return isl_map_free(map); bmap = isl_basic_map_alloc_space(isl_map_get_space(map), 0, 1, 0); i = isl_basic_map_alloc_equality(bmap); if (i < 0) goto error; - isl_seq_clr(bmap->eq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[i], 1 + total); pos1 += isl_basic_map_offset(bmap, type1); pos2 += isl_basic_map_offset(bmap, type2); isl_int_set_si(bmap->eq[i][pos1], 1); @@ -12422,17 +12891,13 @@ { isl_constraint *c; + if (isl_space_check_range(space, type1, pos1, 1) < 0 || + isl_space_check_range(space, type2, pos2, 1) < 0) + space = isl_space_free(space); if (!space) return NULL; c = isl_constraint_alloc_inequality(isl_local_space_from_space(space)); - - if (pos1 >= isl_constraint_dim(c, type1)) - isl_die(isl_constraint_get_ctx(c), isl_error_invalid, - "index out of bounds", return isl_constraint_free(c)); - if (pos2 >= isl_constraint_dim(c, type2)) - isl_die(isl_constraint_get_ctx(c), isl_error_invalid, - "index out of bounds", return isl_constraint_free(c)); if (type1 == type2 && pos1 == pos2) return c; @@ -12496,25 +12961,21 @@ { isl_basic_map *bmap = NULL; int i; - - if (!space) - return NULL; + isl_size total; - if (pos1 >= isl_space_dim(space, type1)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "index out of bounds", goto error); - if (pos2 >= isl_space_dim(space, type2)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "index out of bounds", goto error); + if (isl_space_check_range(space, type1, pos1, 1) < 0 || + isl_space_check_range(space, type2, pos2, 1) < 0) + goto error; if (type1 == type2 && pos1 == pos2) return isl_basic_map_empty(space); bmap = isl_basic_map_alloc_space(space, 0, 0, 1); + total = isl_basic_map_dim(bmap, isl_dim_all); i = isl_basic_map_alloc_inequality(bmap); - if (i < 0) + if (total < 0 || i < 0) return isl_basic_map_free(bmap); - isl_seq_clr(bmap->ineq[i], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[i], 1 + total); pos1 += isl_basic_map_offset(bmap, type1); pos2 += isl_basic_map_offset(bmap, type2); isl_int_set_si(bmap->ineq[i][pos1], 1); @@ -12627,6 +13088,7 @@ int i; isl_int v; isl_ctx *ctx; + isl_size n_div; if (bset && isl_basic_set_plain_is_empty(bset)) return bset; @@ -12639,7 +13101,10 @@ if (!isl_space_is_equal(bset->dim, subs->ls->dim)) isl_die(ctx, isl_error_invalid, "spaces don't match", goto error); - if (isl_local_space_dim(subs->ls, isl_dim_div) != 0) + n_div = isl_local_space_dim(subs->ls, isl_dim_div); + if (n_div < 0) + goto error; + if (n_div != 0) isl_die(ctx, isl_error_unsupported, "cannot handle divs yet", goto error); if (!isl_int_is_one(subs->v->el[0])) @@ -12704,8 +13169,9 @@ for (i = set->n - 1; i >= 0; --i) { set->p[i] = isl_basic_set_substitute(set->p[i], type, pos, subs); - if (remove_if_empty(set, i) < 0) - goto error; + set = set_from_map(remove_if_empty(set_to_map(set), i)); + if (!set) + return NULL; } return set; @@ -12751,23 +13217,23 @@ * the "n_after" coefficients after the transformed range of dimensions * and the coefficients of the other divs in "bmap". */ -static int set_ma_divs(__isl_keep isl_basic_map *bmap, +static __isl_give isl_basic_map *set_ma_divs(__isl_take isl_basic_map *bmap, __isl_keep isl_multi_aff *ma, int n_before, int n_after, int n_div) { int i; - int n_param; - int n_set; + isl_size n_param; + isl_size n_set; isl_local_space *ls; if (n_div == 0) - return 0; - - ls = isl_aff_get_domain_local_space(ma->p[0]); - if (!ls) - return -1; + return bmap; + ls = isl_aff_get_domain_local_space(ma->u.p[0]); n_param = isl_local_space_dim(ls, isl_dim_param); n_set = isl_local_space_dim(ls, isl_dim_set); + if (n_param < 0 || n_set < 0) + return isl_basic_map_free(bmap); + for (i = 0; i < n_div; ++i) { int o_bmap = 0, o_ls = 0; @@ -12787,15 +13253,16 @@ o_bmap += n_div; o_ls += n_div; isl_seq_clr(bmap->div[i] + o_bmap, bmap->n_div - n_div); - if (isl_basic_map_add_div_constraints(bmap, i) < 0) + bmap = isl_basic_map_add_div_constraints(bmap, i); + if (!bmap) goto error; } isl_local_space_free(ls); - return 0; + return bmap; error: isl_local_space_free(ls); - return -1; + return isl_basic_map_free(bmap); } /* How many stride constraints does "ma" enforce? @@ -12808,7 +13275,7 @@ int strides = 0; for (i = 0; i < ma->n; ++i) - if (!isl_int_is_one(ma->p[i]->v->el[0])) + if (!isl_int_is_one(ma->u.p[i]->v->el[0])) strides++; return strides; @@ -12838,17 +13305,19 @@ { int i, k; int div; - int total; - int n_param; - int n_in; - - total = isl_basic_map_total_dim(bmap); + isl_size total; + isl_size n_param; + isl_size n_in; + + total = isl_basic_map_dim(bmap, isl_dim_all); n_param = isl_multi_aff_dim(ma, isl_dim_param); n_in = isl_multi_aff_dim(ma, isl_dim_in); + if (total < 0 || n_param < 0 || n_in < 0) + return isl_basic_map_free(bmap); for (i = 0; i < ma->n; ++i) { int o_bmap = 0, o_ma = 1; - if (isl_int_is_one(ma->p[i]->v->el[0])) + if (isl_int_is_one(ma->u.p[i]->v->el[0])) continue; div = isl_basic_map_alloc_div(bmap); k = isl_basic_map_alloc_equality(bmap); @@ -12856,23 +13325,23 @@ goto error; isl_int_set_si(bmap->div[div][0], 0); isl_seq_cpy(bmap->eq[k] + o_bmap, - ma->p[i]->v->el + o_ma, 1 + n_param); + ma->u.p[i]->v->el + o_ma, 1 + n_param); o_bmap += 1 + n_param; o_ma += 1 + n_param; isl_seq_clr(bmap->eq[k] + o_bmap, n_before); o_bmap += n_before; isl_seq_cpy(bmap->eq[k] + o_bmap, - ma->p[i]->v->el + o_ma, n_in); + ma->u.p[i]->v->el + o_ma, n_in); o_bmap += n_in; o_ma += n_in; isl_seq_clr(bmap->eq[k] + o_bmap, n_after); o_bmap += n_after; isl_seq_cpy(bmap->eq[k] + o_bmap, - ma->p[i]->v->el + o_ma, n_div_ma); + ma->u.p[i]->v->el + o_ma, n_div_ma); o_bmap += n_div_ma; o_ma += n_div_ma; isl_seq_clr(bmap->eq[k] + o_bmap, 1 + total - o_bmap); - isl_int_neg(bmap->eq[k][1 + total], ma->p[i]->v->el[0]); + isl_int_neg(bmap->eq[k][1 + total], ma->u.p[i]->v->el[0]); total++; } @@ -12951,7 +13420,7 @@ int i, k; isl_space *space; isl_basic_map *res = NULL; - int n_before, n_after, n_div_bmap, n_div_ma; + isl_size n_before, n_after, n_div_bmap, n_div_ma; isl_int f, c1, c2, g; isl_bool rational; int strides; @@ -12975,7 +13444,9 @@ n_after = 0; } n_div_bmap = isl_basic_map_dim(bmap, isl_dim_div); - n_div_ma = ma->n ? isl_aff_dim(ma->p[0], isl_dim_div) : 0; + n_div_ma = ma->n ? isl_aff_dim(ma->u.p[0], isl_dim_div) : 0; + if (n_before < 0 || n_after < 0 || n_div_bmap < 0 || n_div_ma < 0) + goto error; space = isl_multi_aff_get_domain_space(ma); space = isl_space_set(isl_basic_map_get_space(bmap), type, space); @@ -12990,23 +13461,28 @@ if (isl_basic_map_alloc_div(res) < 0) goto error; - if (set_ma_divs(res, ma, n_before, n_after, n_div_ma) < 0) + res = set_ma_divs(res, ma, n_before, n_after, n_div_ma); + if (!res) goto error; for (i = 0; i < bmap->n_eq; ++i) { k = isl_basic_map_alloc_equality(res); if (k < 0) goto error; - isl_seq_preimage(res->eq[k], bmap->eq[i], ma, n_before, - n_after, n_div_ma, n_div_bmap, f, c1, c2, g, 0); + if (isl_seq_preimage(res->eq[k], bmap->eq[i], ma, n_before, + n_after, n_div_ma, n_div_bmap, + f, c1, c2, g, 0) < 0) + goto error; } for (i = 0; i < bmap->n_ineq; ++i) { k = isl_basic_map_alloc_inequality(res); if (k < 0) + goto error; + if (isl_seq_preimage(res->ineq[k], bmap->ineq[i], ma, n_before, + n_after, n_div_ma, n_div_bmap, + f, c1, c2, g, 0) < 0) goto error; - isl_seq_preimage(res->ineq[k], bmap->ineq[i], ma, n_before, - n_after, n_div_ma, n_div_bmap, f, c1, c2, g, 0); } for (i = 0; i < bmap->n_div; ++i) { @@ -13014,9 +13490,10 @@ isl_int_set_si(res->div[n_div_ma + i][0], 0); continue; } - isl_seq_preimage(res->div[n_div_ma + i], bmap->div[i], ma, + if (isl_seq_preimage(res->div[n_div_ma + i], bmap->div[i], ma, n_before, n_after, n_div_ma, n_div_bmap, - f, c1, c2, g, 1); + f, c1, c2, g, 1) < 0) + goto error; } if (strides) @@ -13129,9 +13606,9 @@ space = isl_multi_aff_get_domain_space(ma); space = isl_space_set(isl_map_get_space(map), type, space); - isl_space_free(map->dim); - map->dim = space; - if (!map->dim) + isl_space_free(isl_map_take_space(map)); + map = isl_map_restore_space(map, space); + if (!map) goto error; isl_multi_aff_free(ma); @@ -13293,9 +13770,8 @@ if (isl_map_check_named_params(map) < 0) goto error; - if (!isl_space_has_named_params(pma->dim)) - isl_die(map->ctx, isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (isl_pw_multi_aff_check_named_params(pma) < 0) + goto error; map = isl_map_align_params(map, isl_pw_multi_aff_get_space(pma)); pma = isl_pw_multi_aff_align_params(pma, isl_map_get_space(map)); @@ -13351,18 +13827,26 @@ * We create a separate isl_multi_aff to effectuate this change * in order to avoid spurious splitting of the map along the pieces * of "mpa". + * If "mpa" has a non-trivial explicit domain, however, + * then the full substitution should be performed. */ __isl_give isl_map *isl_map_preimage_multi_pw_aff(__isl_take isl_map *map, enum isl_dim_type type, __isl_take isl_multi_pw_aff *mpa) { - int n; + isl_size n; + isl_bool full; isl_pw_multi_aff *pma; - if (!map || !mpa) + n = isl_map_dim(map, type); + if (n < 0 || !mpa) goto error; - n = isl_map_dim(map, type); - if (!isl_map_involves_dims(map, type, 0, n)) { + full = isl_map_involves_dims(map, type, 0, n); + if (full >= 0 && !full) + full = isl_multi_pw_aff_has_non_trivial_domain(mpa); + if (full < 0) + goto error; + if (!full) { isl_space *space; isl_multi_aff *ma; @@ -13406,14 +13890,14 @@ __isl_keep isl_basic_set *bset) { isl_ctx *ctx; - unsigned total; + isl_size total; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; ctx = isl_basic_set_get_ctx(bset); - total = 1 + isl_basic_set_dim(bset, isl_dim_all); - return isl_mat_sub_alloc6(ctx, bset->eq, 0, bset->n_eq, 0, total); + return isl_mat_sub_alloc6(ctx, bset->eq, 0, bset->n_eq, 0, 1 + total); } /* Are the "n" "coefficients" starting at "first" of the integer division @@ -13443,12 +13927,13 @@ __isl_keep isl_basic_map *bmap2, int pos2) { isl_bool equal; - unsigned total; - - if (!bmap1 || !bmap2) + isl_size total, total2; + + total = isl_basic_map_dim(bmap1, isl_dim_all); + total2 = isl_basic_map_dim(bmap2, isl_dim_all); + if (total < 0 || total2 < 0) return isl_bool_error; - total = isl_basic_map_total_dim(bmap1); - if (total != isl_basic_map_total_dim(bmap2)) + if (total != total2) isl_die(isl_basic_map_get_ctx(bmap1), isl_error_invalid, "incomparable div expressions", return isl_bool_error); equal = isl_basic_map_equal_div_expr_part(bmap1, pos1, bmap2, pos2, @@ -13490,7 +13975,7 @@ { isl_ctx *ctx; int pos; - unsigned total; + isl_size total; if (!inner || !bset) return isl_bool_error; @@ -13502,6 +13987,8 @@ return isl_int_is_nonneg(ctx->normalize_gcd); total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) + return isl_bool_error; pos = isl_seq_first_non_zero(bset->ineq[ineq] + 1, total); return isl_int_is_pos(bset->ineq[ineq][1 + pos]); } @@ -13564,9 +14051,8 @@ if (trans->n_row != trans->n_col) isl_die(trans->ctx, isl_error_invalid, "expecting square transformation matrix", goto error); - if (first + trans->n_row > isl_basic_map_dim(bmap, type)) - isl_die(trans->ctx, isl_error_invalid, - "oversized transformation matrix", goto error); + if (isl_basic_map_check_range(bmap, type, first, trans->n_row) < 0) + goto error; pos = isl_basic_map_offset(bmap, type) + first; @@ -13580,7 +14066,7 @@ isl_mat_copy(trans)) < 0) goto error; - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS); isl_mat_free(trans); diff --git a/gcc/isl/isl_map_list.c b/gcc/isl/isl_map_list.c index 5e9305f..cb94c35 100644 --- a/gcc/isl/isl_map_list.c +++ a/gcc/isl/isl_map_list.c @@ -6,8 +6,8 @@ #include -#undef BASE -#define BASE basic_map +#undef EL_BASE +#define EL_BASE basic_map #include @@ -16,8 +16,8 @@ #include -#undef BASE -#define BASE map +#undef EL_BASE +#define EL_BASE map #include @@ -26,7 +26,7 @@ #include -#undef BASE -#define BASE union_map +#undef EL_BASE +#define EL_BASE union_map #include diff --git a/gcc/isl/isl_map_private.h b/gcc/isl/isl_map_private.h index cfe7272..248327a 100644 --- a/gcc/isl/isl_map_private.h +++ a/gcc/isl/isl_map_private.h @@ -40,7 +40,7 @@ #define ISL_BASIC_MAP_NO_IMPLICIT (1 << 2) #define ISL_BASIC_MAP_NO_REDUNDANT (1 << 3) #define ISL_BASIC_MAP_RATIONAL (1 << 4) -#define ISL_BASIC_MAP_NORMALIZED (1 << 5) +#define ISL_BASIC_MAP_SORTED (1 << 5) #define ISL_BASIC_MAP_NORMALIZED_DIVS (1 << 6) #define ISL_BASIC_MAP_ALL_EQUALITIES (1 << 7) #define ISL_BASIC_MAP_REDUCED_COEFFICIENTS (1 << 8) @@ -49,7 +49,7 @@ #define ISL_BASIC_SET_NO_IMPLICIT (1 << 2) #define ISL_BASIC_SET_NO_REDUNDANT (1 << 3) #define ISL_BASIC_SET_RATIONAL (1 << 4) -#define ISL_BASIC_SET_NORMALIZED (1 << 5) +#define ISL_BASIC_SET_SORTED (1 << 5) #define ISL_BASIC_SET_NORMALIZED_DIVS (1 << 6) #define ISL_BASIC_SET_ALL_EQUALITIES (1 << 7) #define ISL_BASIC_SET_REDUCED_COEFFICIENTS (1 << 8) @@ -120,9 +120,6 @@ __isl_give isl_basic_set *isl_basic_set_alloc(isl_ctx *ctx, unsigned nparam, unsigned dim, unsigned extra, unsigned n_eq, unsigned n_ineq); -__isl_give isl_basic_set *isl_basic_set_extend(__isl_take isl_basic_set *base, - unsigned nparam, unsigned dim, unsigned extra, - unsigned n_eq, unsigned n_ineq); __isl_give isl_basic_set *isl_basic_set_extend_constraints( __isl_take isl_basic_set *base, unsigned n_eq, unsigned n_ineq); __isl_give isl_basic_set *isl_basic_set_finalize( @@ -169,15 +166,23 @@ __isl_keep isl_space *isl_basic_map_peek_space( __isl_keep const isl_basic_map *bmap); __isl_keep isl_space *isl_basic_set_peek_space(__isl_keep isl_basic_set *bset); +__isl_keep isl_space *isl_map_peek_space(__isl_keep const isl_map *map); +__isl_keep isl_space *isl_set_peek_space(__isl_keep isl_set *set); __isl_give isl_basic_set *isl_basic_set_reset_space( __isl_take isl_basic_set *bset, __isl_take isl_space *dim); __isl_give isl_basic_map *isl_basic_map_reset_space( __isl_take isl_basic_map *bmap, __isl_take isl_space *dim); __isl_give isl_map *isl_map_reset_space(__isl_take isl_map *map, - __isl_take isl_space *dim); - -unsigned isl_basic_map_offset(struct isl_basic_map *bmap, + __isl_take isl_space *space); +__isl_give isl_map *isl_map_reset_equal_dim_space(__isl_take isl_map *map, + __isl_take isl_space *space); + +isl_size isl_basic_map_var_offset(__isl_keep isl_basic_map *bmap, + enum isl_dim_type type); +isl_size isl_basic_set_var_offset(__isl_keep isl_basic_set *bset, + enum isl_dim_type type); +unsigned isl_basic_map_offset(__isl_keep isl_basic_map *bmap, enum isl_dim_type type); unsigned isl_basic_set_offset(__isl_keep isl_basic_set *bset, enum isl_dim_type type); @@ -192,7 +197,7 @@ __isl_keep isl_basic_set *bset); __isl_give isl_basic_map *isl_basic_map_extend_space( - __isl_take isl_basic_map *base, __isl_take isl_space *dim, + __isl_take isl_basic_map *base, __isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq); __isl_give isl_basic_set *isl_basic_set_extend_space( __isl_take isl_basic_set *base, @@ -213,19 +218,23 @@ unsigned extra, unsigned n_eq, unsigned n_ineq); __isl_give isl_set *isl_set_alloc_space(__isl_take isl_space *dim, int n, unsigned flags); -__isl_give isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *dim, +__isl_give isl_basic_map *isl_basic_map_alloc_space(__isl_take isl_space *space, unsigned extra, unsigned n_eq, unsigned n_ineq); __isl_give isl_map *isl_map_alloc_space(__isl_take isl_space *dim, int n, unsigned flags); int isl_basic_map_alloc_equality(struct isl_basic_map *bmap); int isl_basic_set_alloc_equality(struct isl_basic_set *bset); -int isl_basic_set_free_inequality(struct isl_basic_set *bset, unsigned n); -int isl_basic_map_free_equality(struct isl_basic_map *bmap, unsigned n); -int isl_basic_set_free_equality(struct isl_basic_set *bset, unsigned n); +__isl_give isl_basic_set *isl_basic_set_free_inequality( + __isl_take isl_basic_set *bset, unsigned n); +__isl_give isl_basic_map *isl_basic_map_free_equality( + __isl_take isl_basic_map *bmap, unsigned n); +__isl_give isl_basic_set *isl_basic_set_free_equality( + __isl_take isl_basic_set *bset, unsigned n); int isl_basic_set_alloc_inequality(__isl_keep isl_basic_set *bset); int isl_basic_map_alloc_inequality(__isl_keep isl_basic_map *bmap); -int isl_basic_map_free_inequality(struct isl_basic_map *bmap, unsigned n); +__isl_give isl_basic_map *isl_basic_map_free_inequality( + __isl_take isl_basic_map *bmap, unsigned n); int isl_basic_map_alloc_div(struct isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_insert_div( __isl_take isl_basic_map *bmap, int pos, __isl_keep isl_vec *div); @@ -250,8 +259,10 @@ __isl_give isl_basic_set *isl_basic_set_tighten_outward( __isl_take isl_basic_set *bset, __isl_keep isl_vec *vec); -int isl_inequality_negate(struct isl_basic_map *bmap, unsigned pos); +__isl_give isl_basic_map *isl_inequality_negate(__isl_take isl_basic_map *bmap, + unsigned pos); +isl_bool isl_basic_map_has_single_reference(__isl_keep isl_basic_map *bmap); __isl_give isl_basic_set *isl_basic_set_cow(__isl_take isl_basic_set *bset); __isl_give isl_basic_map *isl_basic_map_cow(__isl_take isl_basic_map *bmap); __isl_give isl_set *isl_set_cow(__isl_take isl_set *set); @@ -267,8 +278,8 @@ __isl_give isl_basic_set *isl_basic_set_set_to_empty( __isl_take isl_basic_set *bset); struct isl_basic_set *isl_basic_set_order_divs(struct isl_basic_set *bset); -void isl_basic_map_swap_div(struct isl_basic_map *bmap, int a, int b); -void isl_basic_set_swap_div(struct isl_basic_set *bset, int a, int b); +__isl_give isl_basic_map *isl_basic_map_swap_div(__isl_take isl_basic_map *bmap, + int a, int b); __isl_give isl_basic_map *isl_basic_map_order_divs( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_order_divs(__isl_take isl_map *map); @@ -284,6 +295,10 @@ __isl_give isl_basic_map *isl_basic_map_sort_divs( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_sort_divs(__isl_take isl_map *map); +__isl_give isl_basic_map *isl_basic_map_gauss5(__isl_take isl_basic_map *bmap, + int *progress, + isl_stat (*swap)(unsigned a, unsigned b, void *user), + isl_stat (*drop)(unsigned n, void *user), void *user); __isl_give isl_basic_map *isl_basic_map_gauss(__isl_take isl_basic_map *bmap, int *progress); __isl_give isl_basic_set *isl_basic_set_gauss( @@ -317,6 +332,8 @@ __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_drop_constraint_involving_unknown_divs( __isl_take isl_map *map); +__isl_give isl_basic_map *isl_basic_map_drop_constraints_involving( + __isl_take isl_basic_map *bmap, unsigned first, unsigned n); __isl_give isl_basic_set *isl_basic_set_drop_constraints_involving( __isl_take isl_basic_set *bset, unsigned first, unsigned n); __isl_give isl_basic_set *isl_basic_set_drop(__isl_take isl_basic_set *bset, @@ -354,11 +371,14 @@ __isl_give isl_map *isl_map_eliminate(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_set *isl_set_eliminate(__isl_take isl_set *set, + enum isl_dim_type type, unsigned first, unsigned n); +__isl_give isl_map *isl_map_project_onto(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n); -int isl_basic_map_add_div_constraint(__isl_keep isl_basic_map *bmap, - unsigned div, int sign); -int isl_basic_map_add_div_constraints(struct isl_basic_map *bmap, unsigned div); +__isl_give isl_basic_map *isl_basic_map_add_div_constraint( + __isl_take isl_basic_map *bmap, unsigned div, int sign); +__isl_give isl_basic_map *isl_basic_map_add_div_constraints( + __isl_take isl_basic_map *bmap, unsigned div); __isl_give isl_basic_map *isl_basic_map_add_known_div_constraints( __isl_take isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_drop_redundant_divs( @@ -388,6 +408,9 @@ __isl_give isl_basic_map *isl_basic_map_from_multi_aff2( __isl_take isl_multi_aff *maff, int rational); +__isl_give isl_map *isl_map_from_multi_aff_internal( + __isl_take isl_multi_aff *ma); +__isl_give isl_map *isl_map_from_pw_aff_internal(__isl_take isl_pw_aff *pa); struct isl_mat; @@ -419,10 +442,6 @@ isl_bool isl_basic_set_eq_is_stride(__isl_keep isl_basic_set *bset, int i); -int isl_basic_map_add_div_constraints_var(__isl_keep isl_basic_map *bmap, - unsigned pos, isl_int *div); -int isl_basic_set_add_div_constraints_var(__isl_keep isl_basic_set *bset, - unsigned pos, isl_int *div); isl_bool isl_basic_map_is_div_constraint(__isl_keep isl_basic_map *bmap, isl_int *constraint, unsigned div); isl_bool isl_basic_set_is_div_constraint(__isl_keep isl_basic_set *bset, @@ -457,6 +476,13 @@ __isl_give isl_map *isl_map_inline_foreach_basic_map(__isl_take isl_map *map, __isl_give isl_basic_map *(*fn)(__isl_take isl_basic_map *bmap)); +isl_stat isl_basic_set_check_no_params(__isl_keep isl_basic_set *bset); +isl_stat isl_basic_set_check_no_locals(__isl_keep isl_basic_set *bset); + +isl_stat isl_basic_set_check_range(__isl_keep isl_basic_set *bset, + enum isl_dim_type type, unsigned first, unsigned n); +isl_stat isl_basic_map_check_range(__isl_keep isl_basic_map *bmap, + enum isl_dim_type type, unsigned first, unsigned n); isl_stat isl_map_check_named_params(__isl_keep isl_map *map); isl_bool isl_map_has_equal_params(__isl_keep isl_map *map1, @@ -489,6 +515,7 @@ isl_bool isl_basic_map_plain_is_single_valued(__isl_keep isl_basic_map *bmap); isl_bool isl_map_is_set(__isl_keep isl_map *map); +isl_bool isl_map_is_params(__isl_keep isl_map *map); isl_bool isl_basic_set_plain_dim_is_fixed(__isl_keep isl_basic_set *bset, unsigned dim, isl_int *val); @@ -528,12 +555,11 @@ __isl_give isl_basic_map *isl_basic_map_shift_div( __isl_take isl_basic_map *bmap, int div, int pos, isl_int shift); -__isl_give isl_basic_map_list *isl_map_get_basic_map_list( - __isl_keep isl_map *map); - int isl_basic_set_count_upto(__isl_keep isl_basic_set *bset, isl_int max, isl_int *count); int isl_set_count_upto(__isl_keep isl_set *set, isl_int max, isl_int *count); + +isl_stat isl_map_check_equal_tuples(__isl_keep isl_map *map); __isl_give isl_mat *isl_basic_set_extract_equalities( __isl_keep isl_basic_set *bset); diff --git a/gcc/isl/isl_map_simplify.c b/gcc/isl/isl_map_simplify.c index 06806d9..a0edea6 100644 --- a/gcc/isl/isl_map_simplify.c +++ a/gcc/isl/isl_map_simplify.c @@ -49,10 +49,10 @@ { int i; isl_int gcd; - unsigned total = isl_basic_map_total_dim(bmap); + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); - if (!bmap) - return NULL; + if (total < 0) + return isl_basic_map_free(bmap); isl_int_init(gcd); for (i = bmap->n_eq - 1; i >= 0; --i) { @@ -62,7 +62,8 @@ bmap = isl_basic_map_set_to_empty(bmap); break; } - isl_basic_map_drop_equality(bmap, i); + if (isl_basic_map_drop_equality(bmap, i) < 0) + goto error; continue; } if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) @@ -83,7 +84,8 @@ bmap = isl_basic_map_set_to_empty(bmap); break; } - isl_basic_map_drop_inequality(bmap, i); + if (isl_basic_map_drop_inequality(bmap, i) < 0) + goto error; continue; } if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) @@ -96,6 +98,10 @@ isl_int_clear(gcd); return bmap; +error: + isl_int_clear(gcd); + isl_basic_map_free(bmap); + return NULL; } __isl_give isl_basic_set *isl_basic_set_normalize_constraints( @@ -177,9 +183,12 @@ __isl_take isl_basic_map *bmap, int div) { int i; - unsigned total = 1 + isl_basic_map_total_dim(bmap); + isl_size total; - for (i = 0; i < total; ++i) { + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); + for (i = 0; i < 1 + total; ++i) { isl_bool reduce; reduce = needs_reduction(bmap, div, i); @@ -234,23 +243,28 @@ * The difference {a/m}/d in the argument satisfies 0 <= {a/m}/d < 1/d * and can therefore not influence the result of the floor. */ -static void normalize_div_expression(__isl_keep isl_basic_map *bmap, int div) +static __isl_give isl_basic_map *normalize_div_expression( + __isl_take isl_basic_map *bmap, int div) { - unsigned total = isl_basic_map_total_dim(bmap); + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); isl_ctx *ctx = bmap->ctx; + if (total < 0) + return isl_basic_map_free(bmap); if (isl_int_is_zero(bmap->div[div][0])) - return; + return bmap; isl_seq_gcd(bmap->div[div] + 2, total, &ctx->normalize_gcd); isl_int_gcd(ctx->normalize_gcd, ctx->normalize_gcd, bmap->div[div][0]); if (isl_int_is_one(ctx->normalize_gcd)) - return; + return bmap; isl_int_fdiv_q(bmap->div[div][1], bmap->div[div][1], ctx->normalize_gcd); isl_int_divexact(bmap->div[div][0], bmap->div[div][0], ctx->normalize_gcd); isl_seq_scale_down(bmap->div[div] + 2, bmap->div[div] + 2, ctx->normalize_gcd, total); + + return bmap; } /* Remove any common factor in numerator and denominator of a div expression, @@ -277,24 +291,27 @@ return bmap; for (i = 0; i < bmap->n_div; ++i) - normalize_div_expression(bmap, i); + bmap = normalize_div_expression(bmap, i); return bmap; } /* Assumes divs have been ordered if keep_divs is set. */ -static void eliminate_var_using_equality(struct isl_basic_map *bmap, +static __isl_give isl_basic_map *eliminate_var_using_equality( + __isl_take isl_basic_map *bmap, unsigned pos, isl_int *eq, int keep_divs, int *progress) { - unsigned total; - unsigned space_total; + isl_size total; + isl_size v_div; int k; int last_div; - total = isl_basic_map_total_dim(bmap); - space_total = isl_space_dim(bmap->dim, isl_dim_all); - last_div = isl_seq_last_non_zero(eq + 1 + space_total, bmap->n_div); + total = isl_basic_map_dim(bmap, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (total < 0 || v_div < 0) + return isl_basic_map_free(bmap); + last_div = isl_seq_last_non_zero(eq + 1 + v_div, bmap->n_div); for (k = 0; k < bmap->n_eq; ++k) { if (bmap->eq[k] == eq) continue; @@ -313,7 +330,8 @@ *progress = 1; isl_seq_elim(bmap->ineq[k], eq, 1+pos, 1+total, NULL); isl_seq_normalize(bmap->ctx, bmap->ineq[k], 1 + total); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); + ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); + ISL_F_CLR(bmap, ISL_BASIC_MAP_SORTED); } for (k = 0; k < bmap->n_div; ++k) { @@ -333,11 +351,14 @@ if (last_div == -1 || (keep_divs && last_div < k)) { isl_seq_elim(bmap->div[k]+1, eq, 1+pos, 1+total, &bmap->div[k][0]); - normalize_div_expression(bmap, k); + bmap = normalize_div_expression(bmap, k); + if (!bmap) + return NULL; } else isl_seq_clr(bmap->div[k], 1 + total); - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); } + + return bmap; } /* Assumes divs have been ordered if keep_divs is set. @@ -345,9 +366,14 @@ static __isl_give isl_basic_map *eliminate_div(__isl_take isl_basic_map *bmap, isl_int *eq, unsigned div, int keep_divs) { - unsigned pos = isl_space_dim(bmap->dim, isl_dim_all) + div; + isl_size v_div; + unsigned pos; - eliminate_var_using_equality(bmap, pos, eq, keep_divs, NULL); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); + pos = v_div + div; + bmap = eliminate_var_using_equality(bmap, pos, eq, keep_divs, NULL); bmap = isl_basic_map_drop_div(bmap, div); @@ -362,10 +388,15 @@ { int k; int last_div; - unsigned space_total = isl_space_dim(bmap->dim, isl_dim_all); - unsigned pos = space_total + div; + isl_size v_div; + unsigned pos; + + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_bool_error; + pos = v_div + div; - last_div = isl_seq_last_non_zero(eq + 1 + space_total, bmap->n_div); + last_div = isl_seq_last_non_zero(eq + 1 + v_div, bmap->n_div); if (last_div < 0 || last_div <= div) return isl_bool_true; @@ -394,7 +425,7 @@ if (!bmap) return NULL; - off = 1 + isl_space_dim(bmap->dim, isl_dim_all); + off = isl_basic_map_offset(bmap, isl_dim_div); for (d = bmap->n_div - 1; d >= 0 ; --d) { for (i = 0; i < bmap->n_eq; ++i) { @@ -435,7 +466,7 @@ return NULL; ctx = bmap->ctx; - off = 1 + isl_space_dim(bmap->dim, isl_dim_all); + off = isl_basic_map_offset(bmap, isl_dim_div); for (d = bmap->n_div - 1; d >= 0 ; --d) { for (i = 0; i < bmap->n_eq; ++i) @@ -514,7 +545,8 @@ static __isl_give isl_basic_map *set_div_from_eq(__isl_take isl_basic_map *bmap, int div, int eq, int *progress) { - unsigned total, o_div; + isl_size total; + unsigned o_div; isl_bool involves; if (!bmap) @@ -530,32 +562,56 @@ return bmap; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); o_div = isl_basic_map_offset(bmap, isl_dim_div); isl_seq_neg(bmap->div[div] + 1, bmap->eq[eq], 1 + total); isl_int_set_si(bmap->div[div][1 + o_div + div], 0); isl_int_set(bmap->div[div][0], bmap->eq[eq][o_div + div]); if (progress) *progress = 1; - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); return bmap; } -__isl_give isl_basic_map *isl_basic_map_gauss(__isl_take isl_basic_map *bmap, - int *progress) +/* Perform fangcheng (Gaussian elimination) on the equality + * constraints of "bmap". + * That is, put them into row-echelon form, starting from the last column + * backward and use them to eliminate the corresponding coefficients + * from all constraints. + * + * If "progress" is not NULL, then it gets set if the elimination + * result in any changes. + * The elimination process may result in some equality constraints + * getting interchanged or removed. + * If "swap" or "drop" are not NULL, then they get called when + * two equality constraints get interchanged or + * when a number of final equality constraints get removed. + * As a special case, if the input turns out to be empty, + * then drop gets called with the number of removed equality + * constraints set to the total number of equality constraints. + * If "swap" or "drop" are not NULL, then the local variables (if any) + * are assumed to be in a valid order. + */ +__isl_give isl_basic_map *isl_basic_map_gauss5(__isl_take isl_basic_map *bmap, + int *progress, + isl_stat (*swap)(unsigned a, unsigned b, void *user), + isl_stat (*drop)(unsigned n, void *user), void *user) { int k; int done; int last_var; unsigned total_var; - unsigned total; + isl_size total; + unsigned n_drop; - bmap = isl_basic_map_order_divs(bmap); + if (!swap && !drop) + bmap = isl_basic_map_order_divs(bmap); - if (!bmap) - return NULL; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); - total = isl_basic_map_total_dim(bmap); total_var = total - bmap->n_div; last_var = total - 1; @@ -569,13 +625,16 @@ } if (last_var < 0) break; - if (k != done) + if (k != done) { swap_equality(bmap, k, done); + if (swap && swap(k, done, user) < 0) + return isl_basic_map_free(bmap); + } if (isl_int_is_neg(bmap->eq[done][1+last_var])) isl_seq_neg(bmap->eq[done], bmap->eq[done], 1+total); - eliminate_var_using_equality(bmap, last_var, bmap->eq[done], 1, - progress); + bmap = eliminate_var_using_equality(bmap, last_var, + bmap->eq[done], 1, progress); if (last_var >= total_var) bmap = set_div_from_eq(bmap, last_var - total_var, @@ -588,10 +647,21 @@ for (k = done; k < bmap->n_eq; ++k) { if (isl_int_is_zero(bmap->eq[k][0])) continue; + if (drop && drop(bmap->n_eq, user) < 0) + return isl_basic_map_free(bmap); return isl_basic_map_set_to_empty(bmap); } - isl_basic_map_free_equality(bmap, bmap->n_eq-done); + n_drop = bmap->n_eq - done; + bmap = isl_basic_map_free_equality(bmap, n_drop); + if (drop && drop(n_drop, user) < 0) + return isl_basic_map_free(bmap); return bmap; +} + +__isl_give isl_basic_map *isl_basic_map_gauss(__isl_take isl_basic_map *bmap, + int *progress) +{ + return isl_basic_map_gauss5(bmap, progress, NULL, NULL, NULL); } __isl_give isl_basic_set *isl_basic_set_gauss( @@ -625,7 +695,7 @@ unsigned int size; int bits; isl_int ***index; - unsigned total; + isl_size total; }; /* Fill in the "ci" data structure for holding the inequalities of "bmap". @@ -637,8 +707,10 @@ ci->index = NULL; if (!bmap) + return isl_stat_error; + ci->total = isl_basic_map_dim(bmap, isl_dim_all); + if (ci->total < 0) return isl_stat_error; - ci->total = isl_basic_set_total_dim(bmap); if (bmap->n_ineq == 0) return isl_stat_ok; ci->size = round_up(4 * (bmap->n_ineq + 1) / 3 - 1); @@ -750,7 +822,7 @@ int k, l, h; int bits; struct isl_blk eq; - unsigned total_var; + isl_size v_div; unsigned total; struct isl_ctx *ctx; @@ -758,8 +830,10 @@ if (!bmap || bmap->n_div <= 1) return bmap; - total_var = isl_space_dim(bmap->dim, isl_dim_all); - total = total_var + bmap->n_div; + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); + total = v_div + bmap->n_div; ctx = bmap->ctx; for (k = bmap->n_div - 1; k >= 0; --k) @@ -804,13 +878,13 @@ if (!elim_for[l]) continue; k = elim_for[l] - 1; - isl_int_set_si(eq.data[1+total_var+k], -1); - isl_int_set_si(eq.data[1+total_var+l], 1); + isl_int_set_si(eq.data[1 + v_div + k], -1); + isl_int_set_si(eq.data[1 + v_div + l], 1); bmap = eliminate_div(bmap, eq.data, l, 1); if (!bmap) break; - isl_int_set_si(eq.data[1+total_var+k], 0); - isl_int_set_si(eq.data[1+total_var+l], 0); + isl_int_set_si(eq.data[1 + v_div + k], 0); + isl_int_set_si(eq.data[1 + v_div + l], 0); } isl_blk_free(ctx, eq); @@ -823,15 +897,17 @@ static int n_pure_div_eq(struct isl_basic_map *bmap) { int i, j; - unsigned total; + isl_size v_div; - total = isl_space_dim(bmap->dim, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return -1; for (i = 0, j = bmap->n_div-1; i < bmap->n_eq; ++i) { - while (j >= 0 && isl_int_is_zero(bmap->eq[i][1 + total + j])) + while (j >= 0 && isl_int_is_zero(bmap->eq[i][1 + v_div + j])) --j; if (j < 0) break; - if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total, j) != -1) + if (isl_seq_first_non_zero(bmap->eq[i] + 1 + v_div, j) != -1) return 0; } return i; @@ -889,7 +965,7 @@ int *progress) { int i, j, k; - int total; + isl_size v_div; int div_eq; struct isl_mat *B; struct isl_vec *d; @@ -912,14 +988,16 @@ if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_NORMALIZED_DIVS)) return bmap; - total = isl_space_dim(bmap->dim, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); div_eq = n_pure_div_eq(bmap); + if (v_div < 0 || div_eq < 0) + return isl_basic_map_free(bmap); if (div_eq == 0) return bmap; if (div_eq < bmap->n_eq) { B = isl_mat_sub_alloc6(bmap->ctx, bmap->eq, div_eq, - bmap->n_eq - div_eq, 0, 1 + total); + bmap->n_eq - div_eq, 0, 1 + v_div); C = isl_mat_variable_compression(B, &C2); if (!C || !C2) goto error; @@ -935,11 +1013,11 @@ if (!d) goto error; for (i = 0, j = bmap->n_div-1; i < div_eq; ++i) { - while (j >= 0 && isl_int_is_zero(bmap->eq[i][1 + total + j])) + while (j >= 0 && isl_int_is_zero(bmap->eq[i][1 + v_div + j])) --j; - isl_int_set(d->block.data[i], bmap->eq[i][1 + total + j]); + isl_int_set(d->block.data[i], bmap->eq[i][1 + v_div + j]); } - B = isl_mat_sub_alloc6(bmap->ctx, bmap->eq, 0, div_eq, 0, 1 + total); + B = isl_mat_sub_alloc6(bmap->ctx, bmap->eq, 0, div_eq, 0, 1 + v_div); if (C) { B = isl_mat_product(B, C); @@ -970,11 +1048,12 @@ dropped = 0; for (j = bmap->n_div - 1; j >= 0; --j) { for (i = 0; i < bmap->n_eq; ++i) - if (!isl_int_is_zero(bmap->eq[i][1 + total + j])) + if (!isl_int_is_zero(bmap->eq[i][1 + v_div + j])) break; if (i < bmap->n_eq) { bmap = isl_basic_map_drop_div(bmap, j); - isl_basic_map_drop_equality(bmap, i); + if (isl_basic_map_drop_equality(bmap, i) < 0) + goto error; ++dropped; } } @@ -996,11 +1075,11 @@ if (isl_int_is_one(T->row[i][i])) continue; k = isl_basic_map_alloc_div(bmap); - pos[i] = 1 + total + k; - isl_seq_clr(bmap->div[k] + 1, 1 + total + bmap->n_div); + pos[i] = 1 + v_div + k; + isl_seq_clr(bmap->div[k] + 1, 1 + v_div + bmap->n_div); isl_int_set(bmap->div[k][0], T->row[i][i]); if (C2) - isl_seq_cpy(bmap->div[k] + 1, C2->row[i], 1 + total); + isl_seq_cpy(bmap->div[k] + 1, C2->row[i], 1 + v_div); else isl_int_set_si(bmap->div[k][1 + i], 1); for (j = 0; j < i; ++j) { @@ -1008,13 +1087,13 @@ continue; if (pos[j] < T->n_row && C2) isl_seq_submul(bmap->div[k] + 1, T->row[i][j], - C2->row[pos[j]], 1 + total); + C2->row[pos[j]], 1 + v_div); else isl_int_neg(bmap->div[k][1 + pos[j]], T->row[i][j]); } j = isl_basic_map_alloc_equality(bmap); - isl_seq_neg(bmap->eq[j], bmap->div[k]+1, 1+total+bmap->n_div); + isl_seq_neg(bmap->eq[j], bmap->div[k]+1, 1+v_div+bmap->n_div); isl_int_set(bmap->eq[j][pos[i]], bmap->div[k][0]); } free(pos); @@ -1038,7 +1117,7 @@ static __isl_give isl_basic_map *set_div_from_lower_bound( __isl_take isl_basic_map *bmap, int div, int ineq) { - unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all); + unsigned total = isl_basic_map_offset(bmap, isl_dim_div); isl_seq_neg(bmap->div[div] + 1, bmap->ineq[ineq], total + bmap->n_div); isl_int_set(bmap->div[div][0], bmap->ineq[ineq][total + div]); @@ -1059,7 +1138,7 @@ int div, int ineq) { int j; - unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all); + unsigned total = isl_basic_map_offset(bmap, isl_dim_div); /* Not defined in terms of unknown divs */ for (j = 0; j < bmap->n_div; ++j) { @@ -1095,7 +1174,7 @@ static isl_bool better_div_constraint(__isl_keep isl_basic_map *bmap, int div, int ineq) { - unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all); + unsigned total = isl_basic_map_offset(bmap, isl_dim_div); int last_div; int last_ineq; @@ -1130,7 +1209,7 @@ int *progress) { int i; - unsigned total = 1 + isl_space_dim(bmap->dim, isl_dim_all); + unsigned total = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < bmap->n_div; ++i) { isl_bool set_div; @@ -1162,10 +1241,10 @@ { struct isl_constraint_index ci; int k, l, h; - unsigned total = isl_basic_map_total_dim(bmap); + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); isl_int sum; - if (!bmap || bmap->n_ineq <= 1) + if (total < 0 || bmap->n_ineq <= 1) return bmap; if (create_constraint_index(&ci, bmap) < 0) @@ -1188,7 +1267,7 @@ --k; } isl_int_init(sum); - for (k = 0; k < bmap->n_ineq-1; ++k) { + for (k = 0; bmap && k < bmap->n_ineq-1; ++k) { isl_seq_neg(bmap->ineq[k]+1, bmap->ineq[k]+1, total); h = hash_index(&ci, bmap, k); isl_seq_neg(bmap->ineq[k]+1, bmap->ineq[k]+1, total); @@ -1292,7 +1371,7 @@ return NULL; ctx = isl_basic_map_get_ctx(bmap); - total = 1 + isl_space_dim(bmap->dim, isl_dim_all); + total = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < bmap->n_div; ++i) { if (isl_int_is_zero(bmap->div[i][0])) @@ -1328,8 +1407,9 @@ } bmap = isl_basic_map_extend_constraints(bmap, 0, 1); - if (isl_basic_map_add_div_constraint(bmap, i, s) < 0) - return isl_basic_map_free(bmap); + bmap = isl_basic_map_add_div_constraint(bmap, i, s); + if (!bmap) + return NULL; } } @@ -1382,7 +1462,7 @@ if (!bmap) return isl_bool_error; - pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div; + pos = isl_basic_map_offset(bmap, isl_dim_div) + div; if (isl_int_eq(constraint[pos], bmap->div[div][0])) { int neg; @@ -1428,8 +1508,12 @@ static isl_bool div_is_redundant(__isl_keep isl_basic_map *bmap, int div) { int i; - unsigned pos = 1 + isl_space_dim(bmap->dim, isl_dim_all) + div; + isl_size v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + unsigned pos = 1 + v_div + div; + if (v_div < 0) + return isl_bool_error; + for (i = 0; i < bmap->n_eq; ++i) if (!isl_int_is_zero(bmap->eq[i][pos])) return isl_bool_false; @@ -1464,9 +1548,11 @@ __isl_take isl_basic_map *bmap) { int i; + isl_size v_div; - if (!bmap) - return NULL; + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); for (i = bmap->n_div-1; i >= 0; --i) { isl_bool redundant; @@ -1476,6 +1562,8 @@ return isl_basic_map_free(bmap); if (!redundant) continue; + bmap = isl_basic_map_drop_constraints_involving(bmap, + v_div + i, 1); bmap = isl_basic_map_drop_div(bmap, i); } return bmap; @@ -1540,14 +1628,14 @@ { int d; int i, j, k; - unsigned total; + isl_size total; int need_gauss = 0; if (n == 0) return bmap; - if (!bmap) - return NULL; - total = isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); bmap = isl_basic_map_cow(bmap); for (d = pos + n - 1; d >= 0 && d >= pos; --d) @@ -1565,8 +1653,10 @@ for (i = 0; i < bmap->n_eq; ++i) { if (isl_int_is_zero(bmap->eq[i][1+d])) continue; - eliminate_var_using_equality(bmap, d, bmap->eq[i], 0, NULL); - isl_basic_map_drop_equality(bmap, i); + bmap = eliminate_var_using_equality(bmap, d, + bmap->eq[i], 0, NULL); + if (isl_basic_map_drop_equality(bmap, i) < 0) + return isl_basic_map_free(bmap); need_gauss = 1; break; } @@ -1620,7 +1710,6 @@ break; } } - ISL_F_CLR(bmap, ISL_BASIC_MAP_NORMALIZED); if (need_gauss) bmap = isl_basic_map_gauss(bmap, NULL); return bmap; @@ -1652,9 +1741,8 @@ if (n == 0) return bmap; - if (first + n > isl_basic_map_dim(bmap, type) || first + n < first) - isl_die(bmap->ctx, isl_error_invalid, - "index out of bounds", goto error); + if (isl_basic_map_check_range(bmap, type, first, n) < 0) + return isl_basic_map_free(bmap); if (ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL)) { first += isl_basic_map_offset(bmap, type) - 1; @@ -1667,9 +1755,6 @@ bmap = isl_basic_map_insert_dims(bmap, type, first, n); bmap = isl_basic_map_reset_space(bmap, space); return bmap; -error: - isl_basic_map_free(bmap); - return NULL; } __isl_give isl_basic_set *isl_basic_set_eliminate( @@ -1694,7 +1779,8 @@ __isl_take isl_basic_map *bmap) { isl_bool known; - int i, n_div, o_div; + isl_size n_div; + int i, o_div; known = isl_basic_map_divs_known(bmap); if (known < 0) @@ -1703,6 +1789,8 @@ return bmap; n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); o_div = isl_basic_map_offset(bmap, isl_dim_div) - 1; for (i = 0; i < n_div; ++i) { @@ -1714,9 +1802,9 @@ bmap = remove_dependent_vars(bmap, o_div + i); bmap = isl_basic_map_drop_constraints_involving_dims(bmap, isl_dim_div, i, 1); - if (!bmap) - return NULL; n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); i = -1; } @@ -1820,6 +1908,7 @@ { int i; int *elim; + isl_size dim; if (!bset || !context) goto error; @@ -1830,10 +1919,11 @@ } bset = isl_basic_set_cow(bset); - if (!bset) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) goto error; - elim = isl_alloc_array(bset->ctx, int, isl_basic_set_n_dim(bset)); + elim = isl_alloc_array(bset->ctx, int, dim); if (!elim) goto error; set_compute_elimination_index(context, elim); @@ -1864,7 +1954,7 @@ __isl_keep isl_basic_set *context, int *row) { struct isl_constraint_index ci; - int n_ineq; + isl_size n_ineq, cols; unsigned total; int k; @@ -1876,7 +1966,10 @@ return isl_stat_error; n_ineq = isl_mat_rows(ineq); - total = isl_mat_cols(ineq) - 1; + cols = isl_mat_cols(ineq); + if (n_ineq < 0 || cols < 0) + return isl_stat_error; + total = cols - 1; for (k = 0; k < n_ineq; ++k) { int l; isl_bool redundant; @@ -1994,9 +2087,12 @@ static __isl_give isl_basic_map *drop_unrelated_constraints( __isl_take isl_basic_map *bmap, int *relevant) { - int i, dim; + int i; + isl_size dim; dim = isl_basic_map_dim(bmap, isl_dim_all); + if (dim < 0) + return isl_basic_map_free(bmap); for (i = 0; i < dim; ++i) if (!relevant[i]) break; @@ -2059,9 +2155,11 @@ static int *alloc_groups(__isl_keep isl_basic_set *context) { isl_ctx *ctx; - int dim; + isl_size dim; dim = isl_basic_set_dim(context, isl_dim_set); + if (dim < 0) + return NULL; ctx = isl_basic_set_get_ctx(context); return isl_calloc_array(ctx, int, dim); } @@ -2089,14 +2187,13 @@ __isl_give isl_basic_map *isl_basic_map_drop_unrelated_constraints( __isl_take isl_basic_map *bmap, __isl_take int *group) { - int dim; + isl_size dim; int i; int last; - - if (!bmap) - return NULL; dim = isl_basic_map_dim(bmap, isl_dim_all); + if (dim < 0) + return isl_basic_map_free(bmap); last = -1; for (i = 0; i < dim; ++i) @@ -2139,10 +2236,11 @@ __isl_take isl_basic_set *context, __isl_keep isl_basic_set *bset) { int *group; - int dim; + isl_size dim; int i, j; - if (!context || !bset) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (!context || dim < 0) return isl_basic_set_free(context); group = alloc_groups(context); @@ -2150,7 +2248,6 @@ if (!group) return isl_basic_set_free(context); - dim = isl_basic_set_dim(bset, isl_dim_set); for (i = 0; i < dim; ++i) { for (j = 0; j < bset->n_eq; ++j) if (!isl_int_is_zero(bset->eq[j][1 + i])) @@ -2185,10 +2282,13 @@ __isl_take isl_basic_set *context, __isl_keep isl_mat *ineq, int *row) { int *group; - int dim; - int i, j, n; + isl_size dim; + int i, j; + isl_size n; - if (!context || !ineq) + dim = isl_basic_set_dim(context, isl_dim_set); + n = isl_mat_rows(ineq); + if (dim < 0 || n < 0) return isl_basic_set_free(context); group = alloc_groups(context); @@ -2196,8 +2296,6 @@ if (!group) return isl_basic_set_free(context); - dim = isl_basic_set_dim(context, isl_dim_set); - n = isl_mat_rows(ineq); for (i = 0; i < dim; ++i) { for (j = 0; j < n; ++j) { if (row[j] < 0) @@ -2394,8 +2492,7 @@ if (tab->con[n_eq + r].is_redundant) continue; test = isl_basic_set_dup(combined); - if (isl_inequality_negate(test, r) < 0) - test = isl_basic_set_free(test); + test = isl_inequality_negate(test, r); test = isl_basic_set_update_from_tab(test, tab); is_empty = isl_basic_set_is_empty(test); isl_basic_set_free(test); @@ -2426,15 +2523,15 @@ */ static __isl_give isl_mat *extract_ineq(__isl_keep isl_basic_set *bset) { - unsigned total; + isl_size total; isl_ctx *ctx; isl_mat *ineq; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; ctx = isl_basic_set_get_ctx(bset); - total = isl_basic_set_total_dim(bset); ineq = isl_mat_sub_alloc6(ctx, bset->ineq, 0, bset->n_ineq, 0, 1 + total); @@ -2488,7 +2585,8 @@ { isl_ctx *ctx; isl_mat *ineq; - int i, n_row, n_col; + int i; + isl_size n_row, n_col; isl_int rem; ineq = extract_ineq(bset); @@ -2506,6 +2604,8 @@ ctx = isl_mat_get_ctx(ineq); n_row = isl_mat_rows(ineq); n_col = isl_mat_cols(ineq); + if (n_row < 0 || n_col < 0) + goto error; isl_int_init(rem); for (i = 0; i < n_row; ++i) { isl_seq_gcd(ineq->row[i] + 1, n_col - 1, &ctx->normalize_gcd); @@ -2540,12 +2640,12 @@ static __isl_give isl_basic_set *project_onto_involved( __isl_take isl_basic_set *bset, __isl_keep isl_basic_set *template) { - int i, n; - - if (!bset || !template) - return isl_basic_set_free(bset); + int i; + isl_size n; n = isl_basic_set_dim(template, isl_dim_set); + if (n < 0 || !template) + return isl_basic_set_free(bset); for (i = 0; i < n; ++i) { isl_bool involved; @@ -2592,9 +2692,10 @@ isl_mat *T; isl_basic_set *aff; isl_basic_set *aff_context; - unsigned total; + isl_size total; - if (!bset || !context) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0 || !context) goto error; context = drop_irrelevant_constraints(context, bset); @@ -2618,7 +2719,6 @@ isl_basic_set_free(aff); return uset_gist_uncompressed(bset, context); } - total = isl_basic_set_total_dim(bset); eq = isl_mat_sub_alloc6(bset->ctx, aff->eq, 0, aff->n_eq, 0, 1 + total); eq = isl_mat_cow(eq); T = isl_mat_variable_compression(eq, NULL); @@ -2654,7 +2754,7 @@ static int n_div_eq(__isl_keep isl_basic_map *bmap) { int i; - int total, n_div; + isl_size total, n_div; if (!bmap) return -1; @@ -2664,6 +2764,8 @@ total = isl_basic_map_dim(bmap, isl_dim_all); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (total < 0 || n_div < 0) + return -1; total -= n_div; for (i = 0; i < bmap->n_eq; ++i) @@ -2681,12 +2783,14 @@ __isl_take isl_space *space, __isl_take isl_mat *eq) { int i, k; + isl_size total; isl_basic_map *bmap = NULL; - if (!space || !eq) + total = isl_space_dim(space, isl_dim_all); + if (total < 0 || !eq) goto error; - if (1 + isl_space_dim(space, isl_dim_all) != eq->n_col) + if (1 + total != eq->n_col) isl_die(isl_space_get_ctx(space), isl_error_internal, "unexpected number of columns", goto error); @@ -2800,12 +2904,14 @@ __isl_keep isl_basic_map *bmap, int bmap_n_eq, __isl_keep isl_basic_map *context, int context_n_eq) { - int total, n_div; + isl_size total, n_div; isl_ctx *ctx; isl_mat *A, *B, *T, *V; total = isl_basic_map_dim(context, isl_dim_all); n_div = isl_basic_map_dim(context, isl_dim_div); + if (total < 0 || n_div < 0) + return NULL; total -= n_div; ctx = isl_basic_map_get_ctx(bmap); @@ -2821,7 +2927,10 @@ T = isl_mat_product(V, T); n_div = isl_basic_map_dim(bmap, isl_dim_div); - T = isl_mat_diagonal(T, isl_mat_identity(ctx, n_div)); + if (n_div < 0) + T = isl_mat_free(T); + else + T = isl_mat_diagonal(T, isl_mat_identity(ctx, n_div)); A = isl_mat_sub_alloc6(ctx, bmap->eq, 0, bmap_n_eq, 0, 1 + total + n_div); @@ -2926,15 +3035,14 @@ __isl_take isl_basic_map *bmap, int n, __isl_keep isl_mat *A) { int i; - int total, n_div; + isl_size total, n_div; int any = 0; isl_int gcd; - - if (!bmap || !A) - return isl_basic_map_free(bmap); total = isl_basic_map_dim(bmap, isl_dim_all); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (total < 0 || n_div < 0 || !A) + return isl_basic_map_free(bmap); total -= n_div; isl_int_init(gcd); @@ -3035,7 +3143,8 @@ { isl_basic_set *bset, *eq; isl_basic_map *eq_bmap; - unsigned total, n_div, extra, n_eq, n_ineq; + isl_size total, n_div, n_div_bmap; + unsigned extra, n_eq, n_ineq; if (!bmap || !context) goto error; @@ -3057,13 +3166,14 @@ bmap = isl_basic_map_remove_redundancies(bmap); context = isl_basic_map_remove_redundancies(context); - if (!context) - goto error; - context = isl_basic_map_align_divs(context, bmap); + n_div = isl_basic_map_dim(context, isl_dim_div); total = isl_basic_map_dim(bmap, isl_dim_all); - extra = n_div - isl_basic_map_dim(bmap, isl_dim_div); + n_div_bmap = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0 || total < 0 || n_div_bmap < 0) + goto error; + extra = n_div - n_div_bmap; bset = isl_basic_map_underlying_set(isl_basic_map_copy(bmap)); bset = isl_basic_set_add_dims(bset, isl_dim_set, extra); @@ -3081,10 +3191,8 @@ n_ineq = bset->n_ineq; eq = isl_basic_set_copy(bset); eq = isl_basic_set_cow(eq); - if (isl_basic_set_free_inequality(eq, n_ineq) < 0) - eq = isl_basic_set_free(eq); - if (isl_basic_set_free_equality(bset, n_eq) < 0) - bset = isl_basic_set_free(bset); + eq = isl_basic_set_free_inequality(eq, n_ineq); + bset = isl_basic_set_free_equality(bset, n_eq); eq_bmap = isl_basic_map_overlying_set(eq, isl_basic_map_copy(bmap)); eq_bmap = gist_strides(eq_bmap, context); @@ -3164,13 +3272,15 @@ __isl_take isl_basic_map *bmap, __isl_keep isl_basic_map *context) { int i1, i2; - unsigned total, extra; + isl_size total, bmap_total; + unsigned extra; - if (!bmap || !context) + total = isl_basic_map_dim(context, isl_dim_all); + bmap_total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0 || bmap_total < 0) return isl_basic_map_free(bmap); - total = isl_basic_map_total_dim(context); - extra = isl_basic_map_total_dim(bmap) - total; + extra = bmap_total - total; i1 = bmap->n_ineq - 1; i2 = context->n_ineq - 1; @@ -3219,13 +3329,15 @@ __isl_take isl_basic_map *bmap, __isl_keep isl_basic_map *context) { int i1, i2; - unsigned total, extra; + isl_size total, bmap_total; + unsigned extra; - if (!bmap || !context) + total = isl_basic_map_dim(context, isl_dim_all); + bmap_total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0 || bmap_total < 0) return isl_basic_map_free(bmap); - total = isl_basic_map_total_dim(context); - extra = isl_basic_map_total_dim(bmap) - total; + extra = bmap_total - total; i1 = bmap->n_eq - 1; i2 = context->n_eq - 1; @@ -3442,7 +3554,7 @@ { int equal; int is_universe; - int single_disjunct_map, single_disjunct_context; + isl_size n_disjunct_map, n_disjunct_context; isl_bool subset; isl_basic_map *hull; @@ -3462,9 +3574,11 @@ if (equal) return replace_by_universe(map, context); - single_disjunct_map = isl_map_n_basic_map(map) == 1; - single_disjunct_context = isl_map_n_basic_map(context) == 1; - if (!single_disjunct_map || !single_disjunct_context) { + n_disjunct_map = isl_map_n_basic_map(map); + n_disjunct_context = isl_map_n_basic_map(context); + if (n_disjunct_map < 0 || n_disjunct_context < 0) + goto error; + if (n_disjunct_map != 1 || n_disjunct_context != 1) { subset = isl_map_is_subset(context, map); if (subset < 0) goto error; @@ -3475,7 +3589,7 @@ context = isl_map_compute_divs(context); if (!context) goto error; - if (single_disjunct_context) { + if (n_disjunct_context == 1) { hull = isl_map_simple_hull(context); } else { isl_ctx *ctx; @@ -3583,7 +3697,7 @@ { struct isl_vec *v = NULL; int *elim = NULL; - unsigned total; + isl_size total; int i; if (!bmap1 || !bmap2) @@ -3596,6 +3710,8 @@ return isl_bool_false; total = isl_space_dim(bmap1->dim, isl_dim_all); + if (total < 0) + return isl_bool_error; if (total == 0) return isl_bool_false; v = isl_vec_alloc(bmap1->ctx, 1 + total); @@ -3783,11 +3899,11 @@ intersect = isl_map_plain_is_universe(map1); if (intersect < 0 || intersect) - return intersect < 0 ? isl_bool_error : isl_bool_false; + return isl_bool_not(intersect); intersect = isl_map_plain_is_universe(map2); if (intersect < 0 || intersect) - return intersect < 0 ? isl_bool_error : isl_bool_false; + return isl_bool_not(intersect); intersect = isl_map_plain_is_equal(map1, map2); if (intersect < 0 || intersect) @@ -3825,11 +3941,11 @@ intersect = isl_basic_map_plain_is_universe(bmap1); if (intersect < 0 || intersect) - return intersect < 0 ? isl_bool_error : isl_bool_false; + return isl_bool_not(intersect); intersect = isl_basic_map_plain_is_universe(bmap2); if (intersect < 0 || intersect) - return intersect < 0 ? isl_bool_error : isl_bool_false; + return isl_bool_not(intersect); test = isl_basic_map_intersect(isl_basic_map_copy(bmap1), isl_basic_map_copy(bmap2)); @@ -3865,11 +3981,34 @@ static int is_zero_or_one(isl_int v) { return isl_int_is_zero(v) || isl_int_is_one(v) || isl_int_is_negone(v); +} + +/* Are the "n" coefficients starting at "first" of inequality constraints + * "i" and "j" of "bmap" opposite to each other? + */ +static int is_opposite_part(__isl_keep isl_basic_map *bmap, int i, int j, + int first, int n) +{ + return isl_seq_is_neg(bmap->ineq[i] + first, bmap->ineq[j] + first, n); +} + +/* Are inequality constraints "i" and "j" of "bmap" opposite to each other, + * apart from the constant term? + */ +static isl_bool is_opposite(__isl_keep isl_basic_map *bmap, int i, int j) +{ + isl_size total; + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; + return is_opposite_part(bmap, i, j, 1, total); } /* Check if we can combine a given div with lower bound l and upper * bound u with some other div and if so return that other div. - * Otherwise return -1. + * Otherwise, return a position beyond the integer divisions. + * Return -1 on error. * * We first check that * - the bounds are opposites of each other (except for the constant @@ -3897,30 +4036,35 @@ * If so, we return b so that "a + m b" can be replaced by * a single div "c = a + m b". */ -static int div_find_coalesce(struct isl_basic_map *bmap, int *pairs, +static int div_find_coalesce(__isl_keep isl_basic_map *bmap, int *pairs, unsigned div, unsigned l, unsigned u) { int i, j; - unsigned dim; - int coalesce = -1; + unsigned n_div; + isl_size v_div; + int coalesce; + isl_bool opp; - if (bmap->n_div <= 1) - return -1; - dim = isl_space_dim(bmap->dim, isl_dim_all); - if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + dim, div) != -1) - return -1; - if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + dim + div + 1, - bmap->n_div - div - 1) != -1) - return -1; - if (!isl_seq_is_neg(bmap->ineq[l] + 1, bmap->ineq[u] + 1, - dim + bmap->n_div)) + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div <= 1) + return n_div; + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) return -1; + if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + v_div, div) != -1) + return n_div; + if (isl_seq_first_non_zero(bmap->ineq[l] + 1 + v_div + div + 1, + n_div - div - 1) != -1) + return n_div; + opp = is_opposite(bmap, l, u); + if (opp < 0 || !opp) + return opp < 0 ? -1 : n_div; - for (i = 0; i < bmap->n_div; ++i) { + for (i = 0; i < n_div; ++i) { if (isl_int_is_zero(bmap->div[i][0])) continue; - if (!isl_int_is_zero(bmap->div[i][1 + 1 + dim + div])) - return -1; + if (!isl_int_is_zero(bmap->div[i][1 + 1 + v_div + div])) + return n_div; } isl_int_add(bmap->ineq[l][0], bmap->ineq[l][0], bmap->ineq[u][0]); @@ -3930,40 +4074,41 @@ bmap = isl_basic_map_copy(bmap); bmap = isl_basic_map_set_to_empty(bmap); isl_basic_map_free(bmap); - return -1; + return n_div; } isl_int_add_ui(bmap->ineq[l][0], bmap->ineq[l][0], 1); - for (i = 0; i < bmap->n_div; ++i) { + coalesce = n_div; + for (i = 0; i < n_div; ++i) { if (i == div) continue; if (!pairs[i]) continue; - for (j = 0; j < bmap->n_div; ++j) { + for (j = 0; j < n_div; ++j) { if (isl_int_is_zero(bmap->div[j][0])) continue; - if (!isl_int_is_zero(bmap->div[j][1 + 1 + dim + i])) + if (!isl_int_is_zero(bmap->div[j][1 + 1 + v_div + i])) break; } - if (j < bmap->n_div) + if (j < n_div) continue; for (j = 0; j < bmap->n_ineq; ++j) { int valid; if (j == l || j == u) continue; - if (isl_int_is_zero(bmap->ineq[j][1 + dim + div])) { - if (is_zero_or_one(bmap->ineq[j][1 + dim + i])) + if (isl_int_is_zero(bmap->ineq[j][1 + v_div + div])) { + if (is_zero_or_one(bmap->ineq[j][1 + v_div + i])) continue; break; } - if (isl_int_is_zero(bmap->ineq[j][1 + dim + i])) + if (isl_int_is_zero(bmap->ineq[j][1 + v_div + i])) break; - isl_int_mul(bmap->ineq[j][1 + dim + div], - bmap->ineq[j][1 + dim + div], + isl_int_mul(bmap->ineq[j][1 + v_div + div], + bmap->ineq[j][1 + v_div + div], bmap->ineq[l][0]); - valid = isl_int_eq(bmap->ineq[j][1 + dim + div], - bmap->ineq[j][1 + dim + i]); - isl_int_divexact(bmap->ineq[j][1 + dim + div], - bmap->ineq[j][1 + dim + div], + valid = isl_int_eq(bmap->ineq[j][1 + v_div + div], + bmap->ineq[j][1 + v_div + i]); + isl_int_divexact(bmap->ineq[j][1 + v_div + div], + bmap->ineq[j][1 + v_div + div], bmap->ineq[l][0]); if (!valid) break; @@ -4081,9 +4226,13 @@ static isl_bool int_between_bounds(__isl_keep isl_basic_map *bmap, int i, int l, int u, struct test_ineq_data *data) { - unsigned offset, n_div; + unsigned offset; + isl_size n_div; + offset = isl_basic_map_offset(bmap, isl_dim_div); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_bool_error; isl_int_gcd(data->g, bmap->ineq[l][offset + i], bmap->ineq[u][offset + i]); @@ -4133,19 +4282,20 @@ { isl_ctx *ctx; struct test_ineq_data data = { NULL, NULL }; - unsigned off, n_div; + unsigned off; + isl_size n_div; int remove = -1; isl_int_init(data.g); isl_int_init(data.fl); isl_int_init(data.fu); - if (!bmap) + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) goto error; ctx = isl_basic_map_get_ctx(bmap); off = isl_basic_map_offset(bmap, isl_dim_div); - n_div = isl_basic_map_dim(bmap, isl_dim_div); data.v = isl_vec_alloc(ctx, off + n_div); if (!data.v) goto error; @@ -4268,13 +4418,16 @@ { isl_ctx *ctx; isl_int m; - unsigned dim, total; + isl_size v_div; + unsigned total; int i; ctx = isl_basic_map_get_ctx(bmap); - dim = isl_space_dim(bmap->dim, isl_dim_all); - total = 1 + dim + bmap->n_div; + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0) + return isl_basic_map_free(bmap); + total = 1 + v_div + bmap->n_div; isl_int_init(m); isl_int_add(m, bmap->ineq[l][0], bmap->ineq[u][0]); @@ -4283,19 +4436,19 @@ for (i = 0; i < bmap->n_ineq; ++i) { if (i == l || i == u) continue; - if (isl_int_is_zero(bmap->ineq[i][1 + dim + div2])) + if (isl_int_is_zero(bmap->ineq[i][1 + v_div + div2])) continue; - if (isl_int_is_zero(bmap->ineq[i][1 + dim + div1])) { - if (isl_int_is_pos(bmap->ineq[i][1 + dim + div2])) + if (isl_int_is_zero(bmap->ineq[i][1 + v_div + div1])) { + if (isl_int_is_pos(bmap->ineq[i][1 + v_div + div2])) isl_seq_combine(bmap->ineq[i], m, bmap->ineq[i], ctx->one, bmap->ineq[l], total); else isl_seq_combine(bmap->ineq[i], m, bmap->ineq[i], ctx->one, bmap->ineq[u], total); } - isl_int_set(bmap->ineq[i][1 + dim + div2], - bmap->ineq[i][1 + dim + div1]); - isl_int_set_si(bmap->ineq[i][1 + dim + div1], 0); + isl_int_set(bmap->ineq[i][1 + v_div + div2], + bmap->ineq[i][1 + v_div + div1]); + isl_int_set_si(bmap->ineq[i][1 + v_div + div1], 0); } isl_int_clear(m); @@ -4323,23 +4476,29 @@ __isl_take isl_basic_map *bmap, int *pairs, int n) { int i, l, u; - unsigned dim; + isl_size v_div; + isl_size n_div; - dim = isl_space_dim(bmap->dim, isl_dim_all); + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (v_div < 0 || n_div < 0) + return isl_basic_map_free(bmap); - for (i = 0; i < bmap->n_div; ++i) { + for (i = 0; i < n_div; ++i) { if (!pairs[i]) continue; for (l = 0; l < bmap->n_ineq; ++l) { - if (!isl_int_is_one(bmap->ineq[l][1 + dim + i])) + if (!isl_int_is_one(bmap->ineq[l][1 + v_div + i])) continue; for (u = 0; u < bmap->n_ineq; ++u) { int c; - if (!isl_int_is_negone(bmap->ineq[u][1+dim+i])) + if (!isl_int_is_negone(bmap->ineq[u][1+v_div+i])) continue; c = div_find_coalesce(bmap, pairs, i, l, u); if (c < 0) + goto error; + if (c >= n_div) continue; free(pairs); bmap = coalesce_divs(bmap, i, c, l, u); @@ -4354,6 +4513,10 @@ } return drop_more_redundant_divs(bmap, pairs, n); +error: + free(pairs); + isl_basic_map_free(bmap); + return NULL; } /* Are the "n" coefficients starting at "first" of inequality constraints @@ -4363,37 +4526,19 @@ int first, int n) { return isl_seq_eq(bmap->ineq[i] + first, bmap->ineq[j] + first, n); -} - -/* Are the "n" coefficients starting at "first" of inequality constraints - * "i" and "j" of "bmap" opposite to each other? - */ -static int is_opposite_part(__isl_keep isl_basic_map *bmap, int i, int j, - int first, int n) -{ - return isl_seq_is_neg(bmap->ineq[i] + first, bmap->ineq[j] + first, n); -} - -/* Are inequality constraints "i" and "j" of "bmap" opposite to each other, - * apart from the constant term? - */ -static isl_bool is_opposite(__isl_keep isl_basic_map *bmap, int i, int j) -{ - unsigned total; - - total = isl_basic_map_dim(bmap, isl_dim_all); - return is_opposite_part(bmap, i, j, 1, total); } /* Are inequality constraints "i" and "j" of "bmap" equal to each other, * apart from the constant term and the coefficient at position "pos"? */ -static int is_parallel_except(__isl_keep isl_basic_map *bmap, int i, int j, +static isl_bool is_parallel_except(__isl_keep isl_basic_map *bmap, int i, int j, int pos) { - unsigned total; + isl_size total; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; return is_parallel_part(bmap, i, j, 1, pos - 1) && is_parallel_part(bmap, i, j, pos + 1, total - pos); } @@ -4401,12 +4546,14 @@ /* Are inequality constraints "i" and "j" of "bmap" opposite to each other, * apart from the constant term and the coefficient at position "pos"? */ -static int is_opposite_except(__isl_keep isl_basic_map *bmap, int i, int j, +static isl_bool is_opposite_except(__isl_keep isl_basic_map *bmap, int i, int j, int pos) { - unsigned total; + isl_size total; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; return is_opposite_part(bmap, i, j, 1, pos - 1) && is_opposite_part(bmap, i, j, pos + 1, total - pos); } @@ -4433,13 +4580,16 @@ int div) { int i; - unsigned n_div, o_div; + isl_size n_div; + unsigned o_div; isl_bool known; known = isl_basic_map_div_is_known(bmap, div); if (known < 0 || known) return isl_bool_not(known); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_bool_error; if (n_div == 1) return isl_bool_true; o_div = isl_basic_map_offset(bmap, isl_dim_div); @@ -4578,7 +4728,8 @@ * ceil((-c1 - c)/n) = ceil((c0 - c)/n) * * If so, return the index of inequality f(x) + c0 >= 0. - * Otherwise, return -1. + * Otherwise, return bmap->n_ineq. + * Return -1 on error. */ static int lower_bound_is_cst(__isl_keep isl_basic_map *bmap, int div, int ineq) { @@ -4590,23 +4741,32 @@ o_div = isl_basic_map_offset(bmap, isl_dim_div); for (i = 0; i < bmap->n_ineq && (lower < 0 || upper < 0); ++i) { + isl_bool par, opp; + if (i == ineq) continue; if (!isl_int_is_zero(bmap->ineq[i][o_div + div])) continue; - if (lower < 0 && - is_parallel_except(bmap, ineq, i, o_div + div)) { + par = isl_bool_false; + if (lower < 0) + par = is_parallel_except(bmap, ineq, i, o_div + div); + if (par < 0) + return -1; + if (par) { lower = i; continue; } - if (upper < 0 && - is_opposite_except(bmap, ineq, i, o_div + div)) { + opp = isl_bool_false; + if (upper < 0) + opp = is_opposite_except(bmap, ineq, i, o_div + div); + if (opp < 0) + return -1; + if (opp) upper = i; - } } if (lower < 0 || upper < 0) - return -1; + return bmap->n_ineq; isl_int_init(l); isl_int_init(u); @@ -4619,7 +4779,7 @@ isl_int_clear(l); isl_int_clear(u); - return equal ? lower : -1; + return equal ? lower : bmap->n_ineq; } /* Given a lower bound constraint "ineq" on the existentially quantified @@ -4705,20 +4865,24 @@ __isl_take isl_basic_map *bmap) { int i, j; - unsigned off; + isl_size off; int *pairs = NULL; int n = 0; + int n_ineq; if (!bmap) goto error; if (bmap->n_div == 0) return bmap; - off = isl_space_dim(bmap->dim, isl_dim_all); + off = isl_basic_map_var_offset(bmap, isl_dim_div); + if (off < 0) + return isl_basic_map_free(bmap); pairs = isl_calloc_array(bmap->ctx, int, bmap->n_div); if (!pairs) goto error; + n_ineq = isl_basic_map_n_inequality(bmap); for (i = 0; i < bmap->n_div; ++i) { int pos, neg; int last_pos, last_neg; @@ -4781,7 +4945,9 @@ return set_eq_and_try_again(bmap, last_pos, pairs); lower = lower_bound_is_cst(bmap, i, last_pos); - if (lower >= 0) + if (lower < 0) + goto error; + if (lower < n_ineq) return fix_cst_lower(bmap, i, last_pos, lower, pairs); continue; @@ -4830,13 +4996,13 @@ */ static isl_stat preimage(isl_int *c, __isl_keep isl_mat *T) { - int n; + isl_size n; isl_ctx *ctx; isl_vec *v; - if (!T) - return isl_stat_error; n = isl_mat_rows(T); + if (n < 0) + return isl_stat_error; if (isl_seq_first_non_zero(c, n) == -1) return isl_stat_ok; ctx = isl_mat_get_ctx(T); @@ -4860,21 +5026,20 @@ __isl_take isl_basic_map *bmap, unsigned pos, __isl_take isl_mat *T) { int i; - unsigned n, total; + isl_size n_row, n_col; bmap = isl_basic_map_cow(bmap); - if (!bmap || !T) + n_row = isl_mat_rows(T); + n_col = isl_mat_cols(T); + if (!bmap || n_row < 0 || n_col < 0) goto error; - n = isl_mat_cols(T); - if (n != isl_mat_rows(T)) + if (n_col != n_row) isl_die(isl_mat_get_ctx(T), isl_error_invalid, "expecting square matrix", goto error); - total = isl_basic_map_dim(bmap, isl_dim_all); - if (pos + n > total || pos + n < pos) - isl_die(isl_mat_get_ctx(T), isl_error_invalid, - "invalid range", goto error); + if (isl_basic_map_check_range(bmap, isl_dim_all, pos, n_col) < 0) + goto error; for (i = 0; i < bmap->n_eq; ++i) if (preimage(bmap->eq[i] + 1 + pos, T) < 0) @@ -4943,7 +5108,8 @@ { int first; int i; - unsigned o_div, n_div; + unsigned o_div; + isl_size n_div; int l; isl_ctx *ctx; isl_mat *T; @@ -4964,6 +5130,8 @@ o_div = isl_basic_map_offset(bmap, isl_dim_div); n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (n_div < 0) + return isl_basic_map_free(bmap); for (i = 0; i < bmap->n_eq; ++i) { l = isl_seq_first_non_zero(bmap->eq[i] + o_div + first, @@ -4999,12 +5167,14 @@ /* Does "bmap" satisfy any equality that involves more than 2 variables * and/or has coefficients different from -1 and 1? */ -static int has_multiple_var_equality(__isl_keep isl_basic_map *bmap) +static isl_bool has_multiple_var_equality(__isl_keep isl_basic_map *bmap) { int i; - unsigned total; + isl_size total; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; for (i = 0; i < bmap->n_eq; ++i) { int j, k; @@ -5014,7 +5184,7 @@ continue; if (!isl_int_is_one(bmap->eq[i][1 + j]) && !isl_int_is_negone(bmap->eq[i][1 + j])) - return 1; + return isl_bool_true; j += 1; k = isl_seq_first_non_zero(bmap->eq[i] + 1 + j, total - j); @@ -5023,15 +5193,15 @@ j += k; if (!isl_int_is_one(bmap->eq[i][1 + j]) && !isl_int_is_negone(bmap->eq[i][1 + j])) - return 1; + return isl_bool_true; j += 1; k = isl_seq_first_non_zero(bmap->eq[i] + 1 + j, total - j); if (k >= 0) - return 1; + return isl_bool_true; } - return 0; + return isl_bool_false; } /* Remove any common factor g from the constraint coefficients in "v". @@ -5080,6 +5250,11 @@ * We therefore call isl_basic_map_detect_inequality_pairs, * which checks for such pairs of inequalities as well as eliminate_divs_eq * and isl_basic_map_gauss if such a pair was found. + * + * Tightening may also result in some other constraints becoming + * (rationally) redundant with respect to the tightened constraint + * (in combination with other constraints). The basic map may + * therefore no longer be assumed to have no redundant constraints. * * Note that this function may leave the result in an inconsistent state. * In particular, the constraints may not be gaussed. @@ -5091,7 +5266,8 @@ __isl_give isl_basic_map *isl_basic_map_reduce_coefficients( __isl_take isl_basic_map *bmap) { - unsigned total; + isl_size total; + isl_bool multi; isl_ctx *ctx; isl_vec *v; isl_mat *eq, *T, *T2; @@ -5106,10 +5282,15 @@ return bmap; if (bmap->n_eq == 0) return bmap; - if (!has_multiple_var_equality(bmap)) + multi = has_multiple_var_equality(bmap); + if (multi < 0) + return isl_basic_map_free(bmap); + if (!multi) return bmap; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_basic_map_free(bmap); ctx = isl_basic_map_get_ctx(bmap); v = isl_vec_alloc(ctx, 1 + total); if (!v) @@ -5150,6 +5331,7 @@ if (tightened) { int progress = 0; + ISL_F_CLR(bmap, ISL_BASIC_MAP_NO_REDUNDANT); bmap = isl_basic_map_detect_inequality_pairs(bmap, &progress); if (progress) { bmap = eliminate_divs_eq(bmap, &progress); @@ -5182,15 +5364,15 @@ __isl_take isl_basic_map *bmap, int div, int pos, isl_int shift) { int i; - unsigned total; + isl_size total, n_div; if (isl_int_is_zero(shift)) return bmap; - if (!bmap) - return NULL; - total = isl_basic_map_dim(bmap, isl_dim_all); - total -= isl_basic_map_dim(bmap, isl_dim_div); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + total -= n_div; + if (total < 0 || n_div < 0) + return isl_basic_map_free(bmap); isl_int_addmul(bmap->div[div][1 + pos], shift, bmap->div[div][0]); diff --git a/gcc/isl/isl_map_subtract.c b/gcc/isl/isl_map_subtract.c index df16ea9..fc6e9b6 100644 --- a/gcc/isl/isl_map_subtract.c +++ a/gcc/isl/isl_map_subtract.c @@ -51,16 +51,20 @@ { int i; unsigned dim; - unsigned tab_total; - unsigned bmap_total; + isl_size tab_total; + isl_size bmap_n_div; + isl_size bmap_total; isl_vec *v; if (!tab || !bmap) return isl_stat_error; - tab_total = isl_basic_map_total_dim(tab->bmap); - bmap_total = isl_basic_map_total_dim(bmap); - dim = isl_space_dim(tab->bmap->dim, isl_dim_all); + tab_total = isl_basic_map_dim(tab->bmap, isl_dim_all); + bmap_total = isl_basic_map_dim(bmap, isl_dim_all); + bmap_n_div = isl_basic_map_dim(bmap, isl_dim_div); + dim = bmap_total - bmap_n_div; + if (tab_total < 0 || bmap_total < 0 || bmap_n_div < 0) + return isl_stat_error; if (isl_tab_extend_cons(tab, 2 * bmap->n_eq + bmap->n_ineq) < 0) return isl_stat_error; @@ -70,11 +74,11 @@ return isl_stat_error; for (i = 0; i < bmap->n_eq; ++i) { - expand_constraint(v, dim, bmap->eq[i], div_map, bmap->n_div); + expand_constraint(v, dim, bmap->eq[i], div_map, bmap_n_div); if (isl_tab_add_ineq(tab, v->el) < 0) goto error; isl_seq_neg(bmap->eq[i], bmap->eq[i], 1 + bmap_total); - expand_constraint(v, dim, bmap->eq[i], div_map, bmap->n_div); + expand_constraint(v, dim, bmap->eq[i], div_map, bmap_n_div); if (isl_tab_add_ineq(tab, v->el) < 0) goto error; isl_seq_neg(bmap->eq[i], bmap->eq[i], 1 + bmap_total); @@ -83,7 +87,7 @@ } for (i = 0; i < bmap->n_ineq; ++i) { - expand_constraint(v, dim, bmap->ineq[i], div_map, bmap->n_div); + expand_constraint(v, dim, bmap->ineq[i], div_map, bmap_n_div); if (isl_tab_add_ineq(tab, v->el) < 0) goto error; if (tab->empty) @@ -110,17 +114,21 @@ __isl_keep isl_basic_map *bmap, int *div_map, int c, int oppose) { unsigned dim; - unsigned tab_total; - unsigned bmap_total; + isl_size tab_total; + isl_size bmap_n_div; + isl_size bmap_total; isl_vec *v; isl_stat r; if (!tab || !bmap) return isl_stat_error; - tab_total = isl_basic_map_total_dim(tab->bmap); - bmap_total = isl_basic_map_total_dim(bmap); - dim = isl_space_dim(tab->bmap->dim, isl_dim_all); + tab_total = isl_basic_map_dim(tab->bmap, isl_dim_all); + bmap_total = isl_basic_map_dim(bmap, isl_dim_all); + bmap_n_div = isl_basic_map_dim(bmap, isl_dim_div); + dim = bmap_total - bmap_n_div; + if (tab_total < 0 || bmap_total < 0 || bmap_n_div < 0) + return isl_stat_error; v = isl_vec_alloc(bmap->ctx, 1 + tab_total); if (!v) @@ -132,7 +140,7 @@ 1 + bmap_total); if (oppose) isl_int_sub_ui(bmap->eq[c/2][0], bmap->eq[c/2][0], 1); - expand_constraint(v, dim, bmap->eq[c/2], div_map, bmap->n_div); + expand_constraint(v, dim, bmap->eq[c/2], div_map, bmap_n_div); r = isl_tab_add_ineq(tab, v->el); if (oppose) isl_int_add_ui(bmap->eq[c/2][0], bmap->eq[c/2][0], 1); @@ -146,7 +154,7 @@ 1 + bmap_total); isl_int_sub_ui(bmap->ineq[c][0], bmap->ineq[c][0], 1); } - expand_constraint(v, dim, bmap->ineq[c], div_map, bmap->n_div); + expand_constraint(v, dim, bmap->ineq[c], div_map, bmap_n_div); r = isl_tab_add_ineq(tab, v->el); if (oppose) { isl_int_add_ui(bmap->ineq[c][0], bmap->ineq[c][0], 1); @@ -164,7 +172,7 @@ { int i, j; struct isl_vec *vec; - unsigned total; + isl_size total; unsigned dim; if (!bmap) @@ -177,7 +185,9 @@ if (!*div_map) return isl_stat_error; - total = isl_basic_map_total_dim(tab->bmap); + total = isl_basic_map_dim(tab->bmap, isl_dim_all); + if (total < 0) + return isl_stat_error; dim = total - tab->bmap->n_div; vec = isl_vec_alloc(bmap->ctx, 2 + total + bmap->n_div); if (!vec) @@ -187,7 +197,8 @@ isl_seq_cpy(vec->el, bmap->div[i], 2 + dim); isl_seq_clr(vec->el + 2 + dim, tab->bmap->n_div); for (j = 0; j < i; ++j) - isl_int_set(vec->el[2 + dim + (*div_map)[j]], + isl_int_add(vec->el[2 + dim + (*div_map)[j]], + vec->el[2 + dim + (*div_map)[j]], bmap->div[i][2 + dim + j]); for (j = 0; j < tab->bmap->n_div; ++j) if (isl_seq_eq(tab->bmap->div[j], @@ -662,7 +673,7 @@ struct isl_is_empty_diff_collector *edc; edc = (struct isl_is_empty_diff_collector *)dc; - edc->empty = 0; + edc->empty = isl_bool_false; isl_basic_map_free(bmap); return isl_stat_error; @@ -717,13 +728,18 @@ */ isl_bool isl_basic_map_plain_is_singleton(__isl_keep isl_basic_map *bmap) { + isl_size total; + if (!bmap) return isl_bool_error; if (bmap->n_div) return isl_bool_false; if (bmap->n_ineq) return isl_bool_false; - return bmap->n_eq == isl_basic_map_total_dim(bmap); + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; + return bmap->n_eq == total; } /* Return true if "map" contains a single element. @@ -745,14 +761,14 @@ __isl_keep isl_basic_map *bmap) { int j; - unsigned dim; + isl_size dim; struct isl_vec *point; isl_int m; - if (!bmap) + dim = isl_basic_map_dim(bmap, isl_dim_all); + if (dim < 0) return NULL; - dim = isl_basic_map_total_dim(bmap); isl_assert(bmap->ctx, bmap->n_eq == dim, return NULL); point = isl_vec_alloc(bmap->ctx, 1 + dim); if (!point) diff --git a/gcc/isl/isl_mat.c b/gcc/isl/isl_mat.c index ab117f0..38f3038 100644 --- a/gcc/isl/isl_mat.c +++ a/gcc/isl/isl_mat.c @@ -252,14 +252,14 @@ return NULL; } -int isl_mat_rows(__isl_keep isl_mat *mat) +isl_size isl_mat_rows(__isl_keep isl_mat *mat) { - return mat ? mat->n_row : -1; + return mat ? mat->n_row : isl_size_error; } -int isl_mat_cols(__isl_keep isl_mat *mat) +isl_size isl_mat_cols(__isl_keep isl_mat *mat) { - return mat ? mat->n_col : -1; + return mat ? mat->n_col : isl_size_error; } /* Check that "col" is a valid column position for "mat". @@ -423,26 +423,26 @@ /* Is "mat" a (possibly scaled) identity matrix? */ -int isl_mat_is_scaled_identity(__isl_keep isl_mat *mat) +isl_bool isl_mat_is_scaled_identity(__isl_keep isl_mat *mat) { int i; if (!mat) - return -1; + return isl_bool_error; if (mat->n_row != mat->n_col) - return 0; + return isl_bool_false; for (i = 0; i < mat->n_row; ++i) { if (isl_seq_first_non_zero(mat->row[i], i) != -1) - return 0; + return isl_bool_false; if (isl_int_ne(mat->row[0][0], mat->row[i][i])) - return 0; + return isl_bool_false; if (isl_seq_first_non_zero(mat->row[i] + i + 1, mat->n_col - (i + 1)) != -1) - return 0; + return isl_bool_false; } - return 1; + return isl_bool_true; } __isl_give isl_vec *isl_mat_vec_product(__isl_take isl_mat *mat, @@ -718,16 +718,17 @@ */ static __isl_give isl_mat *eliminate(__isl_take isl_mat *mat, int row, int col) { - int k, nr, nc; + int k; + isl_size nr, nc; isl_ctx *ctx; - - if (!mat) - return NULL; - ctx = isl_mat_get_ctx(mat); nr = isl_mat_rows(mat); nc = isl_mat_cols(mat); + if (nr < 0 || nc < 0) + return isl_mat_free(mat); + ctx = isl_mat_get_ctx(mat); + for (k = 0; k < nr; ++k) { if (k == row) continue; @@ -754,13 +755,13 @@ */ __isl_give isl_mat *isl_mat_reverse_gauss(__isl_take isl_mat *mat) { - int k, row, last, nr, nc; - - if (!mat) - return NULL; + int k, row, last; + isl_size nr, nc; nr = isl_mat_rows(mat); nc = isl_mat_cols(mat); + if (nr < 0 || nc < 0) + return isl_mat_free(mat); last = nc - 1; for (row = nr - 1; row >= 0; --row) { @@ -793,13 +794,13 @@ */ __isl_give isl_mat *isl_mat_lexnonneg_rows(__isl_take isl_mat *mat) { - int i, nr, nc; - - if (!mat) - return NULL; + int i; + isl_size nr, nc; nr = isl_mat_rows(mat); nc = isl_mat_cols(mat); + if (nr < 0 || nc < 0) + return isl_mat_free(mat); for (i = 0; i < nr; ++i) { int pos; @@ -842,16 +843,16 @@ return H->n_col; } -/* Return the rank of "mat", or -1 in case of error. +/* Return the rank of "mat", or isl_size_error in case of error. */ -int isl_mat_rank(__isl_keep isl_mat *mat) +isl_size isl_mat_rank(__isl_keep isl_mat *mat) { int rank; isl_mat *H; H = isl_mat_left_hermite(isl_mat_copy(mat), 0, NULL, NULL); if (!H) - return -1; + return isl_size_error; rank = hermite_first_zero_col(H, 0, H->n_row); isl_mat_free(H); @@ -1360,15 +1361,15 @@ ctx = bset->ctx; bset = isl_basic_set_cow(bset); - if (!bset) + if (isl_basic_set_check_no_params(bset) < 0) goto error; - isl_assert(ctx, bset->dim->nparam == 0, goto error); isl_assert(ctx, 1+bset->dim->n_out == mat->n_row, goto error); isl_assert(ctx, mat->n_col > 0, goto error); if (mat->n_col > mat->n_row) { - bset = isl_basic_set_extend(bset, 0, mat->n_col-1, 0, 0, 0); + bset = isl_basic_set_add_dims(bset, isl_dim_set, + mat->n_col - mat->n_row); if (!bset) goto error; } else if (mat->n_col < mat->n_row) { @@ -1391,7 +1392,7 @@ ISL_F_CLR(bset, ISL_BASIC_SET_NO_IMPLICIT); ISL_F_CLR(bset, ISL_BASIC_SET_NO_REDUNDANT); - ISL_F_CLR(bset, ISL_BASIC_SET_NORMALIZED); + ISL_F_CLR(bset, ISL_BASIC_SET_SORTED); ISL_F_CLR(bset, ISL_BASIC_SET_NORMALIZED_DIVS); ISL_F_CLR(bset, ISL_BASIC_SET_ALL_EQUALITIES); @@ -2043,19 +2044,22 @@ __isl_give isl_mat *isl_mat_row_basis_extension( __isl_take isl_mat *mat1, __isl_take isl_mat *mat2) { - int n_row; - int r1, r, n1; + isl_size n_row; + int r1, r; + isl_size n1; isl_mat *H, *Q; n1 = isl_mat_rows(mat1); H = isl_mat_concat(mat1, mat2); H = isl_mat_left_hermite(H, 0, NULL, &Q); - if (!H || !Q) + if (n1 < 0 || !H || !Q) goto error; r1 = hermite_first_zero_col(H, 0, n1); r = hermite_first_zero_col(H, r1, H->n_row); n_row = isl_mat_rows(Q); + if (n_row < 0) + goto error; Q = isl_mat_drop_rows(Q, r, n_row - r); Q = isl_mat_drop_rows(Q, 0, r1); @@ -2076,7 +2080,7 @@ isl_bool isl_mat_has_linearly_independent_rows(__isl_keep isl_mat *mat1, __isl_keep isl_mat *mat2) { - int r1, r2, r; + isl_size r1, r2, r; isl_mat *mat; r1 = isl_mat_rank(mat1); @@ -2095,5 +2099,5 @@ isl_mat_free(mat); if (r < 0) return isl_bool_error; - return r == r1 + r2; + return isl_bool_ok(r == r1 + r2); } diff --git a/gcc/isl/isl_mat_private.h b/gcc/isl/isl_mat_private.h index 1a3f69e..774ea16 100644 --- a/gcc/isl/isl_mat_private.h +++ a/gcc/isl/isl_mat_private.h @@ -1,3 +1,6 @@ +#ifndef ISL_MAT_PRIVATE_H +#define ISL_MAT_PRIVATE_H + #include #include @@ -47,7 +50,7 @@ __isl_give isl_mat *isl_mat_lexnonneg_rows(__isl_take isl_mat *mat); -int isl_mat_is_scaled_identity(__isl_keep isl_mat *mat); +isl_bool isl_mat_is_scaled_identity(__isl_keep isl_mat *mat); isl_stat isl_mat_row_gcd(__isl_keep isl_mat *mat, int row, isl_int *gcd); @@ -62,3 +65,5 @@ int isl_mat_get_element(__isl_keep isl_mat *mat, int row, int col, isl_int *v); __isl_give isl_mat *isl_mat_set_element(__isl_take isl_mat *mat, int row, int col, isl_int v); + +#endif diff --git a/gcc/isl/isl_morph.c b/gcc/isl/isl_morph.c index 563f579..b9e6107 100644 --- a/gcc/isl/isl_morph.c +++ a/gcc/isl/isl_morph.c @@ -103,17 +103,20 @@ /* Is "morph" an identity on the parameters? */ -static int identity_on_parameters(__isl_keep isl_morph *morph) +static isl_bool identity_on_parameters(__isl_keep isl_morph *morph) { - int is_identity; - unsigned nparam; + isl_bool is_identity; + isl_size nparam, nparam_ran; isl_mat *sub; nparam = isl_morph_dom_dim(morph, isl_dim_param); - if (nparam != isl_morph_ran_dim(morph, isl_dim_param)) - return 0; + nparam_ran = isl_morph_ran_dim(morph, isl_dim_param); + if (nparam < 0 || nparam_ran < 0) + return isl_bool_error; + if (nparam != nparam_ran) + return isl_bool_false; if (nparam == 0) - return 1; + return isl_bool_true; sub = isl_mat_sub_alloc(morph->map, 0, 1 + nparam, 0, 1 + nparam); is_identity = isl_mat_is_scaled_identity(sub); isl_mat_free(sub); @@ -133,9 +136,9 @@ isl_space *dom, *ran, *space; isl_local_space *ls; isl_multi_aff *ma; - unsigned nparam, nvar; + isl_size nparam, nvar; int i; - int is_identity; + isl_bool is_identity; if (!morph) return NULL; @@ -155,6 +158,8 @@ nparam = isl_multi_aff_dim(ma, isl_dim_param); nvar = isl_multi_aff_dim(ma, isl_dim_out); + if (nparam < 0 || nvar < 0) + ma = isl_multi_aff_free(ma); for (i = 0; i < nvar; ++i) { isl_val *val; isl_vec *v; @@ -190,18 +195,18 @@ return isl_space_copy(morph->ran->dim); } -unsigned isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type) +isl_size isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type) { if (!morph) - return 0; + return isl_size_error; return isl_basic_set_dim(morph->dom, type); } -unsigned isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type) +isl_size isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type) { if (!morph) - return 0; + return isl_size_error; return isl_basic_set_dim(morph->ran, type); } @@ -264,12 +269,14 @@ */ __isl_give isl_morph *isl_morph_dom_params(__isl_take isl_morph *morph) { - unsigned n; + isl_size n; morph = isl_morph_cow(morph); if (!morph) return NULL; n = isl_basic_set_dim(morph->dom, isl_dim_set); + if (n < 0) + return isl_morph_free(morph); morph = isl_morph_remove_dom_dims(morph, isl_dim_set, 0, n); if (!morph) return NULL; @@ -285,12 +292,14 @@ */ __isl_give isl_morph *isl_morph_ran_params(__isl_take isl_morph *morph) { - unsigned n; + isl_size n; morph = isl_morph_cow(morph); if (!morph) return NULL; n = isl_basic_set_dim(morph->ran, isl_dim_set); + if (n < 0) + return isl_morph_free(morph); morph = isl_morph_remove_ran_dims(morph, isl_dim_set, 0, n); if (!morph) return NULL; @@ -302,6 +311,20 @@ return NULL; } +/* Replace the identifier of the tuple of the range of the morph by "id". + */ +static __isl_give isl_morph *isl_morph_set_ran_tuple_id( + __isl_take isl_morph *morph, __isl_keep isl_id *id) +{ + morph = isl_morph_cow(morph); + if (!morph) + return NULL; + morph->ran = isl_basic_set_set_tuple_id(morph->ran, isl_id_copy(id)); + if (!morph->ran) + return isl_morph_free(morph); + return morph; +} + void isl_morph_print_internal(__isl_take isl_morph *morph, FILE *out) { if (!morph) @@ -322,12 +345,12 @@ { isl_mat *id; isl_basic_set *universe; - unsigned total; + isl_size total; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; - total = isl_basic_set_total_dim(bset); id = isl_mat_identity(bset->ctx, 1 + total); universe = isl_basic_set_universe(isl_space_copy(bset->dim)); @@ -342,12 +365,12 @@ { isl_mat *id; isl_basic_set *empty; - unsigned total; + isl_size total; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; - total = isl_basic_set_total_dim(bset); id = isl_mat_identity(bset->ctx, 1 + total); empty = isl_basic_set_empty(isl_space_copy(bset->dim)); @@ -363,12 +386,13 @@ { int i, k; isl_basic_set *eq; - unsigned total; + isl_size total; - isl_assert(bset->ctx, bset->n_div == 0, return NULL); + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0 || isl_basic_set_check_no_locals(bset) < 0) + return NULL; - total = isl_basic_set_total_dim(bset); - eq = isl_basic_set_alloc_space(isl_space_copy(bset->dim), 0, n, 0); + eq = isl_basic_set_alloc_space(isl_basic_set_get_space(bset), 0, n, 0); if (!eq) return NULL; for (i = 0; i < n; ++i) { @@ -385,8 +409,7 @@ } /* Given a basic set, exploit the equalities in the basic set to construct - * a morphism that maps the basic set to a lower-dimensional space - * with identifier "id". + * a morphism that maps the basic set to a lower-dimensional space. * Specifically, the morphism reduces the number of dimensions of type "type". * * We first select the equalities of interest, that is those that involve @@ -410,14 +433,14 @@ * Both matrices are extended to map the full original space to the full * compressed space. */ -__isl_give isl_morph *isl_basic_set_variable_compression_with_id( - __isl_keep isl_basic_set *bset, enum isl_dim_type type, - __isl_keep isl_id *id) +__isl_give isl_morph *isl_basic_set_variable_compression( + __isl_keep isl_basic_set *bset, enum isl_dim_type type) { unsigned otype; - unsigned ntype; + isl_size ntype; unsigned orest; unsigned nrest; + isl_size total; int f_eq, n_eq; isl_space *space; isl_mat *E, *Q, *C; @@ -429,12 +452,16 @@ if (isl_basic_set_plain_is_empty(bset)) return isl_morph_empty(bset); - isl_assert(bset->ctx, bset->n_div == 0, return NULL); + if (isl_basic_set_check_no_locals(bset) < 0) + return NULL; - otype = 1 + isl_space_offset(bset->dim, type); ntype = isl_basic_set_dim(bset, type); + total = isl_basic_set_dim(bset, isl_dim_all); + if (ntype < 0 || total < 0) + return NULL; + otype = isl_basic_set_offset(bset, type); orest = otype + ntype; - nrest = isl_basic_set_total_dim(bset) - (orest - 1); + nrest = total - (orest - 1); for (f_eq = 0; f_eq < bset->n_eq; ++f_eq) if (isl_seq_first_non_zero(bset->eq[f_eq] + orest, nrest) == -1) @@ -461,7 +488,6 @@ space = isl_space_copy(bset->dim); space = isl_space_drop_dims(space, type, 0, ntype); space = isl_space_add_dims(space, type, ntype - n_eq); - space = isl_space_set_tuple_id(space, isl_dim_set, isl_id_copy(id)); ran = isl_basic_set_universe(space); dom = copy_equalities(bset, f_eq, n_eq); @@ -469,14 +495,18 @@ } /* Given a basic set, exploit the equalities in the basic set to construct - * a morphism that maps the basic set to a lower-dimensional space. - * Specifically, the morphism reduces the number of dimensions of type "type". + * a morphism that maps the basic set to a lower-dimensional space + * with identifier "id". + * Specifically, the morphism reduces the number of set dimensions. */ -__isl_give isl_morph *isl_basic_set_variable_compression( - __isl_keep isl_basic_set *bset, enum isl_dim_type type) +__isl_give isl_morph *isl_basic_set_variable_compression_with_id( + __isl_keep isl_basic_set *bset, __isl_keep isl_id *id) { - return isl_basic_set_variable_compression_with_id(bset, type, - &isl_id_none); + isl_morph *morph; + + morph = isl_basic_set_variable_compression(bset, isl_dim_set); + morph = isl_morph_set_ran_tuple_id(morph, id); + return morph; } /* Construct a parameter compression for "bset". @@ -498,9 +528,9 @@ __isl_give isl_morph *isl_basic_set_parameter_compression( __isl_keep isl_basic_set *bset) { - unsigned nparam; - unsigned nvar; - unsigned n_div; + isl_size nparam; + isl_size nvar; + isl_size n_div; int n_eq; isl_mat *H, *B; isl_mat *map, *inv; @@ -518,6 +548,8 @@ nparam = isl_basic_set_dim(bset, isl_dim_param); nvar = isl_basic_set_dim(bset, isl_dim_set); n_div = isl_basic_set_dim(bset, isl_dim_div); + if (nparam < 0 || nvar < 0 || n_div < 0) + return NULL; if (isl_seq_first_non_zero(bset->eq[bset->n_eq - 1] + 1 + nparam, nvar + n_div) == -1) diff --git a/gcc/isl/isl_morph.h b/gcc/isl/isl_morph.h index 8ded753..ef8b876 100644 --- a/gcc/isl/isl_morph.h +++ a/gcc/isl/isl_morph.h @@ -12,6 +12,7 @@ #define ISL_MORHP_H #include +#include #include #include #include @@ -48,8 +49,8 @@ __isl_give isl_space *isl_morph_get_ran_space(__isl_keep isl_morph *morph); __isl_give isl_multi_aff *isl_morph_get_var_multi_aff( __isl_keep isl_morph *morph); -unsigned isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type); -unsigned isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type); +isl_size isl_morph_dom_dim(__isl_keep isl_morph *morph, enum isl_dim_type type); +isl_size isl_morph_ran_dim(__isl_keep isl_morph *morph, enum isl_dim_type type); __isl_give isl_morph *isl_morph_remove_dom_dims(__isl_take isl_morph *morph, enum isl_dim_type type, unsigned first, unsigned n); @@ -68,8 +69,7 @@ __isl_give isl_morph *isl_basic_set_variable_compression( __isl_keep isl_basic_set *bset, enum isl_dim_type type); __isl_give isl_morph *isl_basic_set_variable_compression_with_id( - __isl_keep isl_basic_set *bset, enum isl_dim_type type, - __isl_keep isl_id *id); + __isl_keep isl_basic_set *bset, __isl_keep isl_id *id); __isl_give isl_morph *isl_basic_set_parameter_compression( __isl_keep isl_basic_set *bset); __isl_give isl_morph *isl_basic_set_full_compression( diff --git a/gcc/isl/isl_multi_apply_templ.c b/gcc/isl/isl_multi_apply_templ.c index 44fcb9a..870f267 100644 --- a/gcc/isl/isl_multi_apply_templ.c +++ a/gcc/isl/isl_multi_apply_templ.c @@ -34,8 +34,8 @@ goto error; for (i = 0; i < multi->n; ++i) { - multi->p[i] = fn(multi->p[i], FN(APPLY_DOM,copy)(set)); - if (!multi->p[i]) + multi->u.p[i] = fn(multi->u.p[i], FN(APPLY_DOM,copy)(set)); + if (!multi->u.p[i]) goto error; } diff --git a/gcc/isl/isl_multi_cmp.c b/gcc/isl/isl_multi_cmp.c index a99d370..27ab6dc 100644 --- a/gcc/isl/isl_multi_cmp.c +++ a/gcc/isl/isl_multi_cmp.c @@ -31,7 +31,7 @@ return cmp; for (i = 0; i < multi1->n; ++i) { - cmp = FN(EL,plain_cmp)(multi1->p[i], multi2->p[i]); + cmp = FN(EL,plain_cmp)(multi1->u.p[i], multi2->u.p[i]); if (cmp != 0) return cmp; } diff --git a/gcc/isl/isl_multi_coalesce.c b/gcc/isl/isl_multi_coalesce.c index aef59e8..588e107 100644 --- a/gcc/isl/isl_multi_coalesce.c +++ a/gcc/isl/isl_multi_coalesce.c @@ -23,12 +23,12 @@ return NULL; for (i = 0; i < multi->n; ++i) { - EL *el = FN(EL,copy)(multi->p[i]); + EL *el = FN(EL,copy)(multi->u.p[i]); el = FN(EL,coalesce)(el); if (!el) return FN(MULTI(BASE),free)(multi); - FN(EL,free)(multi->p[i]); - multi->p[i] = el; + FN(EL,free)(multi->u.p[i]); + multi->u.p[i] = el; } return multi; diff --git a/gcc/isl/isl_multi_dims.c b/gcc/isl/isl_multi_dims.c index 93e98ad..a2775ea 100644 --- a/gcc/isl/isl_multi_dims.c +++ a/gcc/isl/isl_multi_dims.c @@ -23,17 +23,21 @@ if (!multi) return isl_bool_error; - if (multi->n == 0 || n == 0) + if (n == 0) return isl_bool_false; for (i = 0; i < multi->n; ++i) { isl_bool involves; - involves = FN(EL,involves_dims)(multi->p[i], type, first, n); + involves = FN(EL,involves_dims)(multi->u.p[i], type, first, n); if (involves < 0 || involves) return involves; } + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + return FN(MULTI(BASE),involves_explicit_domain_dims)(multi, + type, first, n); + return isl_bool_false; } @@ -59,10 +63,16 @@ multi->space = isl_space_insert_dims(multi->space, type, first, n); if (!multi->space) return FN(MULTI(BASE),free)(multi); + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + multi = FN(MULTI(BASE),insert_explicit_domain_dims)(multi, + type, first, n); + if (!multi) + return NULL; for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,insert_dims)(multi->p[i], type, first, n); - if (!multi->p[i]) + multi->u.p[i] = FN(EL,insert_dims)(multi->u.p[i], + type, first, n); + if (!multi->u.p[i]) return FN(MULTI(BASE),free)(multi); } @@ -72,9 +82,11 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),add_dims)(__isl_take MULTI(BASE) *multi, enum isl_dim_type type, unsigned n) { - unsigned pos; + isl_size pos; pos = FN(MULTI(BASE),dim)(multi, type); + if (pos < 0) + return FN(MULTI(BASE),free)(multi); return FN(MULTI(BASE),insert_dims)(multi, type, pos, n); } @@ -85,11 +97,13 @@ __isl_give MULTI(BASE) *FN(MULTI(BASE),project_domain_on_params)( __isl_take MULTI(BASE) *multi) { - unsigned n; + isl_size n; isl_bool involves; isl_space *space; n = FN(MULTI(BASE),dim)(multi, isl_dim_in); + if (n < 0) + return FN(MULTI(BASE),free)(multi); involves = FN(MULTI(BASE),involves_dims)(multi, isl_dim_in, 0, n); if (involves < 0) return FN(MULTI(BASE),free)(multi); diff --git a/gcc/isl/isl_multi_floor.c b/gcc/isl/isl_multi_floor.c index d869e65..b9a8898 100644 --- a/gcc/isl/isl_multi_floor.c +++ a/gcc/isl/isl_multi_floor.c @@ -20,8 +20,8 @@ return NULL; for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,floor)(multi->p[i]); - if (!multi->p[i]) + multi->u.p[i] = FN(EL,floor)(multi->u.p[i]); + if (!multi->u.p[i]) return FN(MULTI(BASE),free)(multi); } diff --git a/gcc/isl/isl_multi_hash.c b/gcc/isl/isl_multi_hash.c index b4bb6c3..0c7ebdf 100644 --- a/gcc/isl/isl_multi_hash.c +++ a/gcc/isl/isl_multi_hash.c @@ -22,7 +22,7 @@ hash = isl_hash_init(); for (i = 0; i < multi->n; ++i) { uint32_t el_hash; - el_hash = FN(EL,get_hash)(multi->p[i]); + el_hash = FN(EL,get_hash)(multi->u.p[i]); isl_hash_hash(hash, el_hash); } diff --git a/gcc/isl/isl_multi_intersect.c b/gcc/isl/isl_multi_intersect.c index b934102..a147ec8 100644 --- a/gcc/isl/isl_multi_intersect.c +++ a/gcc/isl/isl_multi_intersect.c @@ -10,20 +10,142 @@ #include +/* Does the space of "domain" correspond to that of the domain of "multi"? + * The parameters do not need to be aligned. + */ +static isl_bool FN(MULTI(BASE),compatible_domain)( + __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain) +{ + isl_bool ok; + isl_space *space, *domain_space; + + domain_space = FN(DOM,get_space)(domain); + space = FN(MULTI(BASE),get_space)(multi); + ok = isl_space_has_domain_tuples(domain_space, space); + isl_space_free(space); + isl_space_free(domain_space); + + return ok; +} + +/* Check that the space of "domain" corresponds to + * that of the domain of "multi", ignoring parameters. + */ +static isl_stat FN(MULTI(BASE),check_compatible_domain)( + __isl_keep MULTI(BASE) *multi, __isl_keep DOM *domain) +{ + isl_bool ok; + + ok = FN(MULTI(BASE),compatible_domain)(multi, domain); + if (ok < 0) + return isl_stat_error; + if (!ok) + isl_die(FN(DOM,get_ctx)(domain), isl_error_invalid, + "incompatible spaces", return isl_stat_error); + + return isl_stat_ok; +} + +/* Intersect the explicit domain of "multi" with "domain". + * + * The parameters of "multi" and "domain" are assumed to have been aligned. + * + * In the case of an isl_multi_union_pw_aff object, the explicit domain + * is allowed to have only constraints on the parameters, while + * "domain" contains actual domain elements. In this case, + * "domain" is intersected with those parameter constraints and + * then used as the explicit domain of "multi". + */ +static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_aligned)( + __isl_take MULTI(BASE) *multi, __isl_take DOM *domain) +{ + isl_bool is_params; + DOM *multi_dom; + + if (FN(MULTI(BASE),check_compatible_domain)(multi, domain) < 0) + goto error; + if (FN(MULTI(BASE),check_has_explicit_domain)(multi) < 0) + goto error; + is_params = FN(DOM,is_params)(multi->u.dom); + if (is_params < 0) + goto error; + multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi); + if (!is_params) { + domain = FN(DOM,intersect)(multi_dom, domain); + } else { + isl_set *params; + + params = FN(DOM,params)(multi_dom); + domain = FN(DOM,intersect_params)(domain, params); + } + multi = FN(MULTI(BASE),set_explicit_domain)(multi, domain); + return multi; +error: + FN(MULTI(BASE),free)(multi); + FN(DOM,free)(domain); + return NULL; +} + +/* Intersect the explicit domain of "multi" with "domain". + * First align the parameters, if needed. + */ +static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect)( + __isl_take MULTI(BASE) *multi, __isl_take DOM *domain) +{ + return FN(FN(MULTI(BASE),align_params),DOMBASE)(multi, domain, + FN(MULTI(BASE),domain_intersect_aligned)); +} + /* Intersect the domain of "multi" with "domain". + * + * If "multi" has an explicit domain, then only this domain + * needs to be intersected. */ __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_domain)( __isl_take MULTI(BASE) *multi, __isl_take DOM *domain) { + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + return FN(MULTI(BASE),domain_intersect)(multi, domain); return FN(FN(MULTI(BASE),apply),DOMBASE)(multi, domain, &FN(EL,intersect_domain)); +} + +/* Intersect the parameter domain of the explicit domain of "multi" + * with "domain". + */ +static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params_aligned)( + __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain) +{ + DOM *multi_dom; + + multi_dom = FN(MULTI(BASE),get_explicit_domain)(multi); + multi_dom = FN(DOM,intersect_params)(multi_dom, domain); + multi = FN(MULTI(BASE),set_explicit_domain)(multi, multi_dom); + + return multi; +} + +/* Intersect the parameter domain of the explicit domain of "multi" + * with "domain". + * First align the parameters, if needed. + */ +static __isl_give MULTI(BASE) *FN(MULTI(BASE),domain_intersect_params)( + __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain) +{ + return FN(FN(MULTI(BASE),align_params),set)(multi, domain, + FN(MULTI(BASE),domain_intersect_params_aligned)); } /* Intersect the parameter domain of "multi" with "domain". + * + * If "multi" has an explicit domain, then only this domain + * needs to be intersected. */ __isl_give MULTI(BASE) *FN(MULTI(BASE),intersect_params)( __isl_take MULTI(BASE) *multi, __isl_take isl_set *domain) { + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + return FN(MULTI(BASE),domain_intersect_params)(multi, domain); return FN(MULTI(BASE),apply_set)(multi, domain, &FN(EL,intersect_params)); } diff --git a/gcc/isl/isl_multi_macro.h b/gcc/isl/isl_multi_macro.h index 0200b4d..394494b 100644 --- a/gcc/isl/isl_multi_macro.h +++ a/gcc/isl/isl_multi_macro.h @@ -1,9 +1,7 @@ -#define xCAT(A,B) A ## B -#define CAT(A,B) xCAT(A,B) -#undef EL -#define EL CAT(isl_,BASE) -#define xFN(TYPE,NAME) TYPE ## _ ## NAME -#define FN(TYPE,NAME) xFN(TYPE,NAME) +#undef EL_BASE +#define EL_BASE BASE +#include + #define xMULTI(BASE) isl_multi_ ## BASE #define MULTI(BASE) xMULTI(BASE) #undef DOM diff --git a/gcc/isl/isl_multi_templ.c b/gcc/isl/isl_multi_templ.c index d785030..a78fa33 100644 --- a/gcc/isl/isl_multi_templ.c +++ a/gcc/isl/isl_multi_templ.c @@ -1,6 +1,6 @@ /* * Copyright 2011 Sven Verdoolaege - * Copyright 2012-2013 Ecole Normale Superieure + * Copyright 2012-2014 Ecole Normale Superieure * * Use of this software is governed by the MIT license * @@ -8,6 +8,7 @@ * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France */ +#include #include #include #include @@ -15,29 +16,22 @@ #include #define MULTI_NAME(BASE) "isl_multi_" #BASE -#define xLIST(EL) EL ## _list -#define LIST(EL) xLIST(EL) isl_ctx *FN(MULTI(BASE),get_ctx)(__isl_keep MULTI(BASE) *multi) { return multi ? isl_space_get_ctx(multi->space) : NULL; } -__isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi) +/* Return the space of "multi". + */ +__isl_keep isl_space *FN(MULTI(BASE),peek_space)(__isl_keep MULTI(BASE) *multi) { - return multi ? isl_space_copy(multi->space) : NULL; + return multi ? multi->space : NULL; } -/* Return the position of the dimension of the given type and name - * in "multi". - * Return -1 if no such dimension can be found. - */ -int FN(MULTI(BASE),find_dim_by_name)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type, const char *name) +__isl_give isl_space *FN(MULTI(BASE),get_space)(__isl_keep MULTI(BASE) *multi) { - if (!multi) - return -1; - return isl_space_find_dim_by_name(multi->space, type, name); + return isl_space_copy(FN(MULTI(BASE),peek_space)(multi)); } __isl_give isl_space *FN(MULTI(BASE),get_domain_space)( @@ -46,25 +40,36 @@ return multi ? isl_space_domain(isl_space_copy(multi->space)) : NULL; } +/* Allocate a multi expression living in "space". + * + * If the number of base expressions is zero, then make sure + * there is enough room in the structure for the explicit domain, + * in case the type supports such an explicit domain. + */ __isl_give MULTI(BASE) *FN(MULTI(BASE),alloc)(__isl_take isl_space *space) { isl_ctx *ctx; - int n; + isl_size n; MULTI(BASE) *multi; - if (!space) - return NULL; + n = isl_space_dim(space, isl_dim_out); + if (n < 0) + goto error; ctx = isl_space_get_ctx(space); - n = isl_space_dim(space, isl_dim_out); - multi = isl_calloc(ctx, MULTI(BASE), + if (n > 0) + multi = isl_calloc(ctx, MULTI(BASE), sizeof(MULTI(BASE)) + (n - 1) * sizeof(struct EL *)); + else + multi = isl_calloc(ctx, MULTI(BASE), sizeof(MULTI(BASE))); if (!multi) goto error; multi->space = space; multi->n = n; multi->ref = 1; + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + multi = FN(MULTI(BASE),init_explicit_domain)(multi); return multi; error: isl_space_free(space); @@ -85,7 +90,9 @@ for (i = 0; i < multi->n; ++i) dup = FN(FN(MULTI(BASE),set),BASE)(dup, i, - FN(EL,copy)(multi->p[i])); + FN(EL,copy)(multi->u.p[i])); + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + dup = FN(MULTI(BASE),copy_explicit_domain)(dup, multi); return dup; } @@ -123,111 +130,100 @@ isl_space_free(multi->space); for (i = 0; i < multi->n; ++i) - FN(EL,free)(multi->p[i]); + FN(EL,free)(multi->u.p[i]); + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + FN(MULTI(BASE),free_explicit_domain)(multi); free(multi); return NULL; } -unsigned FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi, +isl_size FN(MULTI(BASE),dim)(__isl_keep MULTI(BASE) *multi, enum isl_dim_type type) { - return multi ? isl_space_dim(multi->space, type) : 0; + return isl_space_dim(FN(MULTI(BASE),peek_space)(multi), type); } -/* Return the position of the first dimension of "type" with id "id". - * Return -1 if there is no such dimension. +/* Return the number of base expressions in "multi". */ -int FN(MULTI(BASE),find_dim_by_id)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type, __isl_keep isl_id *id) +isl_size FN(MULTI(BASE),size)(__isl_keep MULTI(BASE) *multi) { - if (!multi) - return -1; - return isl_space_find_dim_by_id(multi->space, type, id); + return multi ? multi->n : isl_size_error; } -/* Return the id of the given dimension. - */ -__isl_give isl_id *FN(MULTI(BASE),get_dim_id)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type, unsigned pos) -{ - return multi ? isl_space_get_dim_id(multi->space, type, pos) : NULL; -} +#undef TYPE +#define TYPE MULTI(BASE) +static +#include "check_type_range_templ.c" -__isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_name)( - __isl_take MULTI(BASE) *multi, - enum isl_dim_type type, unsigned pos, const char *s) +/* Return a copy of the base expression at position "pos" in "multi". + */ +__isl_give EL *FN(MULTI(BASE),get_at)(__isl_keep MULTI(BASE) *multi, int pos) { - int i; + isl_ctx *ctx; - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) + if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0) return NULL; - - multi->space = isl_space_set_dim_name(multi->space, type, pos, s); - if (!multi->space) - return FN(MULTI(BASE),free)(multi); - - if (type == isl_dim_out) - return multi; - for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,set_dim_name)(multi->p[i], type, pos, s); - if (!multi->p[i]) - return FN(MULTI(BASE),free)(multi); - } - - return multi; -} - -const char *FN(MULTI(BASE),get_tuple_name)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type) -{ - return multi ? isl_space_get_tuple_name(multi->space, type) : NULL; + ctx = FN(MULTI(BASE),get_ctx)(multi); + return FN(EL,copy)(multi->u.p[pos]); } -/* Does the specified tuple have an id? +/* This is an alternative name for the function above. */ -isl_bool FN(MULTI(BASE),has_tuple_id)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type) +__isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi, + int pos) { - if (!multi) - return isl_bool_error; - return isl_space_has_tuple_id(multi->space, type); + return FN(MULTI(BASE),get_at)(multi, pos); } -/* Return the id of the specified tuple. +/* Set the element at position "pos" of "multi" to "el", + * where the position may be empty if "multi" has only a single reference. */ -__isl_give isl_id *FN(MULTI(BASE),get_tuple_id)(__isl_keep MULTI(BASE) *multi, - enum isl_dim_type type) +static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore)( + __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el) { - return multi ? isl_space_get_tuple_id(multi->space, type) : NULL; + multi = FN(MULTI(BASE),cow)(multi); + if (!multi || !el) + goto error; + + if (FN(MULTI(BASE),check_range)(multi, isl_dim_out, pos, 1) < 0) + goto error; + + FN(EL,free)(multi->u.p[pos]); + multi->u.p[pos] = el; + + return multi; +error: + FN(MULTI(BASE),free)(multi); + FN(EL,free)(el); + return NULL; } -__isl_give EL *FN(FN(MULTI(BASE),get),BASE)(__isl_keep MULTI(BASE) *multi, - int pos) +/* Set the element at position "pos" of "multi" to "el", + * where the position may be empty if "multi" has only a single reference. + * However, the space of "multi" is available and is checked + * for compatibility with "el". + */ +static __isl_give MULTI(BASE) *FN(MULTI(BASE),restore_check_space)( + __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el) { - isl_ctx *ctx; + isl_space *space; - if (!multi) - return NULL; - ctx = FN(MULTI(BASE),get_ctx)(multi); - if (pos < 0 || pos >= multi->n) - isl_die(ctx, isl_error_invalid, - "index out of bounds", return NULL); - return FN(EL,copy)(multi->p[pos]); + space = FN(MULTI(BASE),peek_space)(multi); + if (FN(EL,check_match_domain_space)(el, space) < 0) + multi = FN(MULTI(BASE),free)(multi); + return FN(MULTI(BASE),restore)(multi, pos, el); } -__isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)( +/* Replace the base expression at position "pos" in "multi" with "el". + */ +__isl_give MULTI(BASE) *FN(MULTI(BASE),set_at)( __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el) { isl_space *multi_space = NULL; isl_space *el_space = NULL; isl_bool match; - multi = FN(MULTI(BASE),cow)(multi); - if (!multi || !el) - goto error; - multi_space = FN(MULTI(BASE),get_space)(multi); match = FN(EL,matching_params)(el, multi_space); if (match < 0) @@ -239,15 +235,8 @@ multi_space = FN(MULTI(BASE),get_space)(multi); el = FN(EL,align_params)(el, isl_space_copy(multi_space)); } - if (FN(EL,check_match_domain_space)(el, multi_space) < 0) - goto error; - - if (pos < 0 || pos >= multi->n) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "index out of bounds", goto error); - FN(EL,free)(multi->p[pos]); - multi->p[pos] = el; + multi = FN(MULTI(BASE),restore_check_space)(multi, pos, el); isl_space_free(multi_space); isl_space_free(el_space); @@ -259,6 +248,14 @@ isl_space_free(multi_space); isl_space_free(el_space); return NULL; +} + +/* This is an alternative name for the function above. + */ +__isl_give MULTI(BASE) *FN(FN(MULTI(BASE),set),BASE)( + __isl_take MULTI(BASE) *multi, int pos, __isl_take EL *el) +{ + return FN(MULTI(BASE),set_at)(multi, pos, el); } /* Reset the space of "multi". This function is called from isl_pw_templ.c @@ -266,6 +263,10 @@ * directly or through its domain. It therefore passes along both, * which we pass along to the element function since we don't know how * that is represented either. + * + * If "multi" has an explicit domain, then the caller is expected + * to make sure that any modification that would change the dimensions + * of the explicit domain has bee applied before this function is called. */ __isl_give MULTI(BASE) *FN(MULTI(BASE),reset_space_and_domain)( __isl_take MULTI(BASE) *multi, __isl_take isl_space *space, @@ -278,9 +279,15 @@ goto error; for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,reset_domain_space)(multi->p[i], + multi->u.p[i] = FN(EL,reset_domain_space)(multi->u.p[i], isl_space_copy(domain)); - if (!multi->p[i]) + if (!multi->u.p[i]) + goto error; + } + if (FN(MULTI(BASE),has_explicit_domain)(multi)) { + multi = FN(MULTI(BASE),reset_explicit_domain_space)(multi, + isl_space_copy(domain)); + if (!multi) goto error; } isl_space_free(domain); @@ -312,85 +319,6 @@ domain = isl_space_domain(isl_space_copy(space)); return FN(MULTI(BASE),reset_space_and_domain)(multi, space, domain); -} - -/* Set the id of the given dimension of "multi" to "id". - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),set_dim_id)( - __isl_take MULTI(BASE) *multi, - enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) -{ - isl_space *space; - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi || !id) - goto error; - - space = FN(MULTI(BASE),get_space)(multi); - space = isl_space_set_dim_id(space, type, pos, id); - - return FN(MULTI(BASE),reset_space)(multi, space); -error: - isl_id_free(id); - FN(MULTI(BASE),free)(multi); - return NULL; -} - -__isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_name)( - __isl_keep MULTI(BASE) *multi, enum isl_dim_type type, - const char *s) -{ - isl_space *space; - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - space = FN(MULTI(BASE),get_space)(multi); - space = isl_space_set_tuple_name(space, type, s); - - return FN(MULTI(BASE),reset_space)(multi, space); -} - -__isl_give MULTI(BASE) *FN(MULTI(BASE),set_tuple_id)( - __isl_take MULTI(BASE) *multi, enum isl_dim_type type, - __isl_take isl_id *id) -{ - isl_space *space; - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - goto error; - - space = FN(MULTI(BASE),get_space)(multi); - space = isl_space_set_tuple_id(space, type, id); - - return FN(MULTI(BASE),reset_space)(multi, space); -error: - isl_id_free(id); - return NULL; -} - -/* Drop the id on the specified tuple. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),reset_tuple_id)( - __isl_take MULTI(BASE) *multi, enum isl_dim_type type) -{ - isl_space *space; - - if (!multi) - return NULL; - if (!FN(MULTI(BASE),has_tuple_id)(multi, type)) - return multi; - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - space = FN(MULTI(BASE),get_space)(multi); - space = isl_space_reset_tuple_id(space, type); - - return FN(MULTI(BASE),reset_space)(multi, space); } /* Reset the user pointer on all identifiers of parameters and tuples @@ -411,20 +339,21 @@ __isl_take MULTI(BASE) *multi, __isl_take isl_reordering *exp) { int i; + isl_space *space; multi = FN(MULTI(BASE),cow)(multi); if (!multi || !exp) goto error; for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,realign_domain)(multi->p[i], + multi->u.p[i] = FN(EL,realign_domain)(multi->u.p[i], isl_reordering_copy(exp)); - if (!multi->p[i]) + if (!multi->u.p[i]) goto error; } - multi = FN(MULTI(BASE),reset_domain_space)(multi, - isl_space_copy(exp->dim)); + space = isl_reordering_get_space(exp); + multi = FN(MULTI(BASE),reset_domain_space)(multi, space); isl_reordering_free(exp); return multi; @@ -435,6 +364,9 @@ } /* Align the parameters of "multi" to those of "model". + * + * If "multi" has an explicit domain, then align the parameters + * of the domain first. */ __isl_give MULTI(BASE) *FN(MULTI(BASE),align_params)( __isl_take MULTI(BASE) *multi, __isl_take isl_space *model) @@ -462,7 +394,12 @@ isl_die(ctx, isl_error_invalid, "input has unnamed parameters", goto error); - model = isl_space_params(model); + if (FN(MULTI(BASE),has_explicit_domain)(multi)) { + multi = FN(MULTI(BASE),align_explicit_domain_params)(multi, + isl_space_copy(model)); + if (!multi) + goto error; + } exp = isl_parameter_alignment_reordering(multi->space, model); exp = isl_reordering_extend_space(exp, FN(MULTI(BASE),get_domain_space)(multi)); @@ -476,27 +413,40 @@ return NULL; } +/* Create a multi expression in the given space with the elements of "list" + * as base expressions. + * + * Since isl_multi_*_restore_* assumes that the element and + * the multi expression have matching spaces, the alignment + * (if any) needs to be performed beforehand. + */ __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),LIST(BASE))( __isl_take isl_space *space, __isl_take LIST(EL) *list) { int i; - int n; + isl_size n, dim; isl_ctx *ctx; MULTI(BASE) *multi; - if (!space || !list) + dim = isl_space_dim(space, isl_dim_out); + n = FN(FN(LIST(EL),n),BASE)(list); + if (dim < 0 || n < 0) goto error; ctx = isl_space_get_ctx(space); - n = FN(FN(LIST(EL),n),BASE)(list); - if (n != isl_space_dim(space, isl_dim_out)) + if (n != dim) isl_die(ctx, isl_error_invalid, "invalid number of elements in list", goto error); + for (i = 0; i < n; ++i) { + EL *el = FN(LIST(EL),peek)(list, i); + space = isl_space_align_params(space, FN(EL,get_space)(el)); + } multi = FN(MULTI(BASE),alloc)(isl_space_copy(space)); for (i = 0; i < n; ++i) { - multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, - FN(FN(LIST(EL),get),BASE)(list, i)); + EL *el = FN(FN(LIST(EL),get),BASE)(list, i); + el = FN(EL,align_params)(el, isl_space_copy(space)); + multi = FN(MULTI(BASE),restore_check_space)(multi, i, el); } isl_space_free(space); @@ -505,138 +455,18 @@ error: isl_space_free(space); FN(LIST(EL),free)(list); - return NULL; -} - -#ifndef NO_IDENTITY -/* Create a multi expression in the given space that maps each - * input dimension to the corresponding output dimension. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),identity)(__isl_take isl_space *space) -{ - int i, n; - isl_local_space *ls; - MULTI(BASE) *multi; - - if (!space) - return NULL; - - if (isl_space_is_set(space)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "expecting map space", goto error); - - n = isl_space_dim(space, isl_dim_out); - if (n != isl_space_dim(space, isl_dim_in)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "number of input and output dimensions needs to be " - "the same", goto error); - - multi = FN(MULTI(BASE),alloc)(isl_space_copy(space)); - - if (!n) { - isl_space_free(space); - return multi; - } - - space = isl_space_domain(space); - ls = isl_local_space_from_space(space); - - for (i = 0; i < n; ++i) { - EL *el; - el = FN(EL,var_on_domain)(isl_local_space_copy(ls), - isl_dim_set, i); - multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, el); - } - - isl_local_space_free(ls); - - return multi; -error: - isl_space_free(space); return NULL; -} -#endif - -#ifndef NO_ZERO -/* Construct a multi expression in the given space with value zero in - * each of the output dimensions. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),zero)(__isl_take isl_space *space) -{ - int n; - MULTI(BASE) *multi; - - if (!space) - return NULL; - - n = isl_space_dim(space , isl_dim_out); - multi = FN(MULTI(BASE),alloc)(isl_space_copy(space)); - - if (!n) - isl_space_free(space); - else { - int i; - isl_local_space *ls; - EL *el; - - space = isl_space_domain(space); - ls = isl_local_space_from_space(space); - el = FN(EL,zero_on_domain)(ls); - - for (i = 0; i < n; ++i) - multi = FN(FN(MULTI(BASE),set),BASE)(multi, i, - FN(EL,copy)(el)); - - FN(EL,free)(el); - } - - return multi; -} -#endif - -#ifndef NO_FROM_BASE -/* Create a multiple expression with a single output/set dimension - * equal to "el". - * For most multiple expression types, the base type has a single - * output/set dimension and the space of the result is therefore - * the same as the space of the input. - * In the case of isl_multi_union_pw_aff, however, the base type - * lives in a parameter space and we therefore need to add - * a single set dimension. - */ -__isl_give MULTI(BASE) *FN(FN(MULTI(BASE),from),BASE)(__isl_take EL *el) -{ - isl_space *space; - MULTI(BASE) *multi; - - space = FN(EL,get_space(el)); - if (isl_space_is_params(space)) { - space = isl_space_set_from_params(space); - space = isl_space_add_dims(space, isl_dim_set, 1); - } - multi = FN(MULTI(BASE),alloc)(space); - multi = FN(FN(MULTI(BASE),set),BASE)(multi, 0, el); - - return multi; } -#endif __isl_give MULTI(BASE) *FN(MULTI(BASE),drop_dims)( __isl_take MULTI(BASE) *multi, enum isl_dim_type type, unsigned first, unsigned n) { int i; - unsigned dim; multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - dim = FN(MULTI(BASE),dim)(multi, type); - if (first + n > dim || first + n < first) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "index out of bounds", - return FN(MULTI(BASE),free)(multi)); + if (FN(MULTI(BASE),check_range)(multi, type, first, n) < 0) + return FN(MULTI(BASE),free)(multi); multi->space = isl_space_drop_dims(multi->space, type, first, n); if (!multi->space) @@ -644,17 +474,25 @@ if (type == isl_dim_out) { for (i = 0; i < n; ++i) - FN(EL,free)(multi->p[first + i]); + FN(EL,free)(multi->u.p[first + i]); for (i = first; i + n < multi->n; ++i) - multi->p[i] = multi->p[i + n]; + multi->u.p[i] = multi->u.p[i + n]; multi->n -= n; + if (n > 0 && FN(MULTI(BASE),has_explicit_domain)(multi)) + multi = FN(MULTI(BASE),init_explicit_domain)(multi); return multi; } + + if (FN(MULTI(BASE),has_explicit_domain)(multi)) + multi = FN(MULTI(BASE),drop_explicit_domain_dims)(multi, + type, first, n); + if (!multi) + return NULL; for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,drop_dims)(multi->p[i], type, first, n); - if (!multi->p[i]) + multi->u.p[i] = FN(EL,drop_dims)(multi->u.p[i], type, first, n); + if (!multi->u.p[i]) return FN(MULTI(BASE),free)(multi); } @@ -698,24 +536,27 @@ * construct a MULTI(BASE) (A * C) -> [B -> D]. * * The parameters are assumed to have been aligned. + * + * If "multi1" and/or "multi2" has an explicit domain, then + * intersect the domain of the result with these explicit domains. */ static __isl_give MULTI(BASE) *FN(MULTI(BASE),range_product_aligned)( __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2) { - int i, n1, n2; + int i; + isl_size n1, n2; EL *el; isl_space *space; MULTI(BASE) *res; - if (!multi1 || !multi2) + n1 = FN(MULTI(BASE),size)(multi1); + n2 = FN(MULTI(BASE),size)(multi2); + if (n1 < 0 || n2 < 0) goto error; space = isl_space_range_product(FN(MULTI(BASE),get_space)(multi1), FN(MULTI(BASE),get_space)(multi2)); res = FN(MULTI(BASE),alloc)(space); - - n1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out); - n2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out); for (i = 0; i < n1; ++i) { el = FN(FN(MULTI(BASE),get),BASE)(multi1, i); @@ -727,6 +568,11 @@ res = FN(FN(MULTI(BASE),set),BASE)(res, n1 + i, el); } + if (FN(MULTI(BASE),has_explicit_domain)(multi1)) + res = FN(MULTI(BASE),intersect_explicit_domain)(res, multi1); + if (FN(MULTI(BASE),has_explicit_domain)(multi2)) + res = FN(MULTI(BASE),intersect_explicit_domain)(res, multi2); + FN(MULTI(BASE),free)(multi1); FN(MULTI(BASE),free)(multi2); return res; @@ -761,19 +607,21 @@ __isl_take MULTI(BASE) *multi) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!multi) - return NULL; + total = FN(MULTI(BASE),dim)(multi, isl_dim_out); + if (total < 0) + return FN(MULTI(BASE),free)(multi); if (!isl_space_range_is_wrapping(multi->space)) isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, "range is not a product", return FN(MULTI(BASE),free)(multi)); space = FN(MULTI(BASE),get_space)(multi); - total = isl_space_dim(space, isl_dim_out); space = isl_space_range_factor_domain(space); keep = isl_space_dim(space, isl_dim_out); + if (keep < 0) + multi = FN(MULTI(BASE),free)(multi); multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, keep, total - keep); multi = FN(MULTI(BASE),reset_space)(multi, space); @@ -787,19 +635,21 @@ __isl_take MULTI(BASE) *multi) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!multi) - return NULL; + total = FN(MULTI(BASE),dim)(multi, isl_dim_out); + if (total < 0) + return FN(MULTI(BASE),free)(multi); if (!isl_space_range_is_wrapping(multi->space)) isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, "range is not a product", return FN(MULTI(BASE),free)(multi)); space = FN(MULTI(BASE),get_space)(multi); - total = isl_space_dim(space, isl_dim_out); space = isl_space_range_factor_range(space); keep = isl_space_dim(space, isl_dim_out); + if (keep < 0) + multi = FN(MULTI(BASE),free)(multi); multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep); multi = FN(MULTI(BASE),reset_space)(multi, space); @@ -812,78 +662,25 @@ __isl_take MULTI(BASE) *multi) { isl_space *space; - int total, keep; + isl_size total, keep; - if (!multi) - return NULL; + total = FN(MULTI(BASE),dim)(multi, isl_dim_set); + if (total < 0) + return FN(MULTI(BASE),free)(multi); if (!isl_space_is_wrapping(multi->space)) isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, "not a product", return FN(MULTI(BASE),free)(multi)); space = FN(MULTI(BASE),get_space)(multi); - total = isl_space_dim(space, isl_dim_out); space = isl_space_factor_range(space); - keep = isl_space_dim(space, isl_dim_out); - multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_out, 0, total - keep); + keep = isl_space_dim(space, isl_dim_set); + if (keep < 0) + multi = FN(MULTI(BASE),free)(multi); + multi = FN(MULTI(BASE),drop_dims)(multi, isl_dim_set, 0, total - keep); multi = FN(MULTI(BASE),reset_space)(multi, space); return multi; -} - -#ifndef NO_PRODUCT -/* Given two MULTI(BASE)s A -> B and C -> D, - * construct a MULTI(BASE) [A -> C] -> [B -> D]. - * - * The parameters are assumed to have been aligned. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),product_aligned)( - __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2) -{ - int i; - EL *el; - isl_space *space; - MULTI(BASE) *res; - int in1, in2, out1, out2; - - in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in); - in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in); - out1 = FN(MULTI(BASE),dim)(multi1, isl_dim_out); - out2 = FN(MULTI(BASE),dim)(multi2, isl_dim_out); - space = isl_space_product(FN(MULTI(BASE),get_space)(multi1), - FN(MULTI(BASE),get_space)(multi2)); - res = FN(MULTI(BASE),alloc)(isl_space_copy(space)); - space = isl_space_domain(space); - - for (i = 0; i < out1; ++i) { - el = FN(FN(MULTI(BASE),get),BASE)(multi1, i); - el = FN(EL,insert_dims)(el, isl_dim_in, in1, in2); - el = FN(EL,reset_domain_space)(el, isl_space_copy(space)); - res = FN(FN(MULTI(BASE),set),BASE)(res, i, el); - } - - for (i = 0; i < out2; ++i) { - el = FN(FN(MULTI(BASE),get),BASE)(multi2, i); - el = FN(EL,insert_dims)(el, isl_dim_in, 0, in1); - el = FN(EL,reset_domain_space)(el, isl_space_copy(space)); - res = FN(FN(MULTI(BASE),set),BASE)(res, out1 + i, el); - } - - isl_space_free(space); - FN(MULTI(BASE),free)(multi1); - FN(MULTI(BASE),free)(multi2); - return res; -} - -/* Given two MULTI(BASE)s A -> B and C -> D, - * construct a MULTI(BASE) [A -> C] -> [B -> D]. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),product)( - __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2) -{ - return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2, - &FN(MULTI(BASE),product_aligned)); } -#endif __isl_give MULTI(BASE) *FN(MULTI(BASE),flatten_range)( __isl_take MULTI(BASE) *multi) @@ -935,15 +732,14 @@ __isl_take MULTI(BASE) *multi2) { MULTI(BASE) *res; - unsigned dim; + isl_size dim; - if (!multi1 || !multi2) + dim = FN(MULTI(BASE),size)(multi1); + if (dim < 0 || !multi2) goto error; - dim = FN(MULTI(BASE),dim)(multi1, isl_dim_out); - if (pos > dim) - isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid, - "index out of bounds", goto error); + if (FN(MULTI(BASE),check_range)(multi1, isl_dim_out, pos, 0) < 0) + goto error; res = FN(MULTI(BASE),copy)(multi1); res = FN(MULTI(BASE),drop_dims)(res, isl_dim_out, pos, dim - pos); @@ -959,59 +755,26 @@ return NULL; } -#ifndef NO_SPLICE -/* Given two multi expressions, "multi1" - * - * [A1 A2] -> [B1 B2] - * - * where A2 starts at position "in_pos" and B2 starts at position "out_pos", - * and "multi2" - * - * [C] -> [D] - * - * return the multi expression - * - * [A1 C A2] -> [B1 D B2] - * - * We first insert input dimensions to obtain - * - * [A1 C A2] -> [B1 B2] - * - * and - * - * [A1 C A2] -> [D] - * - * and then apply range_splice. +/* Check that "multi1" and "multi2" live in the same space, + * reporting an error if they do not. */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),splice)( - __isl_take MULTI(BASE) *multi1, unsigned in_pos, unsigned out_pos, - __isl_take MULTI(BASE) *multi2) +static isl_stat FN(MULTI(BASE),check_equal_space)( + __isl_keep MULTI(BASE) *multi1, __isl_keep MULTI(BASE) *multi2) { - unsigned n_in1; - unsigned n_in2; + isl_bool equal; if (!multi1 || !multi2) - goto error; + return isl_stat_error; - n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in); - if (in_pos > n_in1) + equal = isl_space_is_equal(multi1->space, multi2->space); + if (equal < 0) + return isl_stat_error; + if (!equal) isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid, - "index out of bounds", goto error); - - n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in); - - multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2); - multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, n_in2, - n_in1 - in_pos); - multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, 0, in_pos); + "spaces don't match", return isl_stat_error); - return FN(MULTI(BASE),range_splice)(multi1, out_pos, multi2); -error: - FN(MULTI(BASE),free)(multi1); - FN(MULTI(BASE),free)(multi2); - return NULL; + return isl_stat_ok; } -#endif /* This function is currently only used from isl_aff.c */ @@ -1022,28 +785,30 @@ /* Pairwise perform "fn" to the elements of "multi1" and "multi2" and * return the result. + * + * If "multi2" has an explicit domain, then + * intersect the domain of the result with this explicit domain. */ static __isl_give MULTI(BASE) *FN(MULTI(BASE),bin_op)( __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2, __isl_give EL *(*fn)(__isl_take EL *, __isl_take EL *)) { int i; - isl_ctx *ctx; multi1 = FN(MULTI(BASE),cow)(multi1); - if (!multi1 || !multi2) + if (FN(MULTI(BASE),check_equal_space)(multi1, multi2) < 0) goto error; - - ctx = FN(MULTI(BASE),get_ctx)(multi1); - if (!isl_space_is_equal(multi1->space, multi2->space)) - isl_die(ctx, isl_error_invalid, - "spaces don't match", goto error); for (i = 0; i < multi1->n; ++i) { - multi1->p[i] = fn(multi1->p[i], FN(EL,copy)(multi2->p[i])); - if (!multi1->p[i]) + multi1->u.p[i] = fn(multi1->u.p[i], + FN(EL,copy)(multi2->u.p[i])); + if (!multi1->u.p[i]) goto error; } + + if (FN(MULTI(BASE),has_explicit_domain)(multi2)) + multi1 = FN(MULTI(BASE),intersect_explicit_domain)(multi1, + multi2); FN(MULTI(BASE),free)(multi2); return multi1; @@ -1051,286 +816,33 @@ FN(MULTI(BASE),free)(multi1); FN(MULTI(BASE),free)(multi2); return NULL; -} - -/* Add "multi2" from "multi1" and return the result. - * - * The parameters of "multi1" and "multi2" are assumed to have been aligned. - */ -static __isl_give MULTI(BASE) *FN(MULTI(BASE),add_aligned)( - __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2) -{ - return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,add)); -} - -/* Add "multi2" from "multi1" and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),add)(__isl_take MULTI(BASE) *multi1, - __isl_take MULTI(BASE) *multi2) -{ - return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2, - &FN(MULTI(BASE),add_aligned)); -} - -/* Subtract "multi2" from "multi1" and return the result. - * - * The parameters of "multi1" and "multi2" are assumed to have been aligned. - */ -static __isl_give MULTI(BASE) *FN(MULTI(BASE),sub_aligned)( - __isl_take MULTI(BASE) *multi1, __isl_take MULTI(BASE) *multi2) -{ - return FN(MULTI(BASE),bin_op)(multi1, multi2, &FN(EL,sub)); -} - -/* Subtract "multi2" from "multi1" and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),sub)(__isl_take MULTI(BASE) *multi1, - __isl_take MULTI(BASE) *multi2) -{ - return FN(MULTI(BASE),align_params_multi_multi_and)(multi1, multi2, - &FN(MULTI(BASE),sub_aligned)); -} - -/* Multiply the elements of "multi" by "v" and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_val)(__isl_take MULTI(BASE) *multi, - __isl_take isl_val *v) -{ - int i; - - if (!multi || !v) - goto error; - - if (isl_val_is_one(v)) { - isl_val_free(v); - return multi; - } - - if (!isl_val_is_rat(v)) - isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational factor", goto error); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,scale_val)(multi->p[i], isl_val_copy(v)); - if (!multi->p[i]) - goto error; - } - - isl_val_free(v); - return multi; -error: - isl_val_free(v); - return FN(MULTI(BASE),free)(multi); -} - -/* Divide the elements of "multi" by "v" and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_val)( - __isl_take MULTI(BASE) *multi, __isl_take isl_val *v) -{ - int i; - - if (!multi || !v) - goto error; - - if (isl_val_is_one(v)) { - isl_val_free(v); - return multi; - } - - if (!isl_val_is_rat(v)) - isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational factor", goto error); - if (isl_val_is_zero(v)) - isl_die(isl_val_get_ctx(v), isl_error_invalid, - "cannot scale down by zero", goto error); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,scale_down_val)(multi->p[i], - isl_val_copy(v)); - if (!multi->p[i]) - goto error; - } - - isl_val_free(v); - return multi; -error: - isl_val_free(v); - return FN(MULTI(BASE),free)(multi); -} - -/* Multiply the elements of "multi" by the corresponding element of "mv" - * and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_multi_val)( - __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv) -{ - int i; - - if (!multi || !mv) - goto error; - - if (!isl_space_tuple_is_equal(multi->space, isl_dim_out, - mv->space, isl_dim_set)) - isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid, - "spaces don't match", goto error); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - goto error; - - for (i = 0; i < multi->n; ++i) { - isl_val *v; - - v = isl_multi_val_get_val(mv, i); - multi->p[i] = FN(EL,scale_val)(multi->p[i], v); - if (!multi->p[i]) - goto error; - } - - isl_multi_val_free(mv); - return multi; -error: - isl_multi_val_free(mv); - return FN(MULTI(BASE),free)(multi); -} - -/* Divide the elements of "multi" by the corresponding element of "mv" - * and return the result. - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),scale_down_multi_val)( - __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv) -{ - int i; - - if (!multi || !mv) - goto error; - - if (!isl_space_tuple_is_equal(multi->space, isl_dim_out, - mv->space, isl_dim_set)) - isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid, - "spaces don't match", goto error); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - for (i = 0; i < multi->n; ++i) { - isl_val *v; - - v = isl_multi_val_get_val(mv, i); - multi->p[i] = FN(EL,scale_down_val)(multi->p[i], v); - if (!multi->p[i]) - goto error; - } - - isl_multi_val_free(mv); - return multi; -error: - isl_multi_val_free(mv); - return FN(MULTI(BASE),free)(multi); } -/* Compute the residues of the elements of "multi" modulo - * the corresponding element of "mv" and return the result. +/* Only used on some multi-expressions. */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),mod_multi_val)( - __isl_take MULTI(BASE) *multi, __isl_take isl_multi_val *mv) -{ - int i; - - if (!multi || !mv) - goto error; - - if (!isl_space_tuple_is_equal(multi->space, isl_dim_out, - mv->space, isl_dim_set)) - isl_die(isl_multi_val_get_ctx(mv), isl_error_invalid, - "spaces don't match", goto error); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - goto error; - - for (i = 0; i < multi->n; ++i) { - isl_val *v; - - v = isl_multi_val_get_val(mv, i); - multi->p[i] = FN(EL,mod_val)(multi->p[i], v); - if (!multi->p[i]) - goto error; - } - - isl_multi_val_free(mv); - return multi; -error: - isl_multi_val_free(mv); - return FN(MULTI(BASE),free)(multi); -} +static isl_bool FN(MULTI(BASE),any)(__isl_keep MULTI(BASE) *multi, + isl_bool (*test)(__isl_keep EL *)) __attribute__ ((unused)); -#ifndef NO_MOVE_DIMS -/* Move the "n" dimensions of "src_type" starting at "src_pos" of "multi" - * to dimensions of "dst_type" at "dst_pos". - * - * We only support moving input dimensions to parameters and vice versa. +/* Does "test" succeed on any base expression of "multi"? */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),move_dims)(__isl_take MULTI(BASE) *multi, - enum isl_dim_type dst_type, unsigned dst_pos, - enum isl_dim_type src_type, unsigned src_pos, unsigned n) +static isl_bool FN(MULTI(BASE),any)(__isl_keep MULTI(BASE) *multi, + isl_bool (*test)(__isl_keep EL *)) { + isl_size n; int i; - - if (!multi) - return NULL; - - if (n == 0 && - !isl_space_is_named_or_nested(multi->space, src_type) && - !isl_space_is_named_or_nested(multi->space, dst_type)) - return multi; - - if (dst_type == isl_dim_out || src_type == isl_dim_out) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "cannot move output/set dimension", - return FN(MULTI(BASE),free)(multi)); - if (dst_type == isl_dim_div || src_type == isl_dim_div) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "cannot move divs", - return FN(MULTI(BASE),free)(multi)); - if (src_pos + n > isl_space_dim(multi->space, src_type)) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_invalid, - "range out of bounds", - return FN(MULTI(BASE),free)(multi)); - if (dst_type == src_type) - isl_die(FN(MULTI(BASE),get_ctx)(multi), isl_error_unsupported, - "moving dims within the same type not supported", - return FN(MULTI(BASE),free)(multi)); - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - multi->space = isl_space_move_dims(multi->space, dst_type, dst_pos, - src_type, src_pos, n); - if (!multi->space) - return FN(MULTI(BASE),free)(multi); + n = FN(MULTI(BASE),size)(multi); + if (n < 0) + return isl_bool_error; - for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,move_dims)(multi->p[i], dst_type, dst_pos, - src_type, src_pos, n); - if (!multi->p[i]) - return FN(MULTI(BASE),free)(multi); + for (i = 0; i < n; ++i) { + isl_bool any = test(multi->u.p[i]); + if (any < 0 || any) + return any; } - return multi; + return isl_bool_false; } -#endif /* Convert a multiple expression defined over a parameter domain * into one that is defined over a zero-dimensional set. @@ -1371,75 +883,17 @@ return equal; for (i = 0; i < multi1->n; ++i) { - equal = FN(EL,plain_is_equal)(multi1->p[i], multi2->p[i]); + equal = FN(EL,plain_is_equal)(multi1->u.p[i], multi2->u.p[i]); if (equal < 0 || !equal) return equal; - } - - return isl_bool_true; -} - -/* Does "multi" involve any NaNs? - */ -isl_bool FN(MULTI(BASE),involves_nan)(__isl_keep MULTI(BASE) *multi) -{ - int i; - - if (!multi) - return isl_bool_error; - if (multi->n == 0) - return isl_bool_false; - - for (i = 0; i < multi->n; ++i) { - isl_bool has_nan = FN(EL,involves_nan)(multi->p[i]); - if (has_nan < 0 || has_nan) - return has_nan; } - return isl_bool_false; -} - -#ifndef NO_DOMAIN -/* Return the shared domain of the elements of "multi". - */ -__isl_give isl_set *FN(MULTI(BASE),domain)(__isl_take MULTI(BASE) *multi) -{ - int i; - isl_set *dom; - - if (!multi) - return NULL; - - dom = isl_set_universe(FN(MULTI(BASE),get_domain_space)(multi)); - for (i = 0; i < multi->n; ++i) { - isl_set *dom_i; - - dom_i = FN(EL,domain)(FN(FN(MULTI(BASE),get),BASE)(multi, i)); - dom = isl_set_intersect(dom, dom_i); - } - - FN(MULTI(BASE),free)(multi); - return dom; -} -#endif - -#ifndef NO_NEG -/* Return the opposite of "multi". - */ -__isl_give MULTI(BASE) *FN(MULTI(BASE),neg)(__isl_take MULTI(BASE) *multi) -{ - int i; - - multi = FN(MULTI(BASE),cow)(multi); - if (!multi) - return NULL; - - for (i = 0; i < multi->n; ++i) { - multi->p[i] = FN(EL,neg)(multi->p[i]); - if (!multi->p[i]) - return FN(MULTI(BASE),free)(multi); + if (FN(MULTI(BASE),has_explicit_domain)(multi1) || + FN(MULTI(BASE),has_explicit_domain)(multi2)) { + equal = FN(MULTI(BASE),equal_explicit_domain)(multi1, multi2); + if (equal < 0 || !equal) + return equal; } - return multi; + return isl_bool_true; } -#endif diff --git a/gcc/isl/isl_multi_templ.h b/gcc/isl/isl_multi_templ.h index 8170892..c5049ad 100644 --- a/gcc/isl/isl_multi_templ.h +++ a/gcc/isl/isl_multi_templ.h @@ -1,13 +1,34 @@ #include #include +/* A multiple expression with base expressions of type EL. + * + * "space" is the space in which the multiple expression lives. + * "n" is the number of base expression and is equal + * to the output or set dimension of "space". + * "p" is an array of size "n" of base expressions. + * The array is only accessible when n > 0. + * "dom" is the explicit domain, if present + * The explicit domain is only accessible when n == 0. + */ struct MULTI(BASE) { int ref; isl_space *space; int n; - EL *p[1]; + struct { +#ifdef EXPLICIT_DOMAIN + DOM *dom; +#endif + EL *p[1]; + } u; }; __isl_give MULTI(BASE) *CAT(MULTI(BASE),_alloc)(__isl_take isl_space *space); +__isl_keep isl_space *FN(MULTI(BASE),peek_space)(__isl_keep MULTI(BASE) *multi); + +#ifdef EXPLICIT_DOMAIN +isl_bool CAT(MULTI(BASE),_has_non_trivial_domain)( + __isl_keep MULTI(BASE) *multi); +#endif diff --git a/gcc/isl/isl_options.c b/gcc/isl/isl_options.c index eb3dd02..f9d253b 100644 --- a/gcc/isl/isl_options.c +++ a/gcc/isl/isl_options.c @@ -134,6 +134,9 @@ convex, ISL_CONVEX_HULL_WRAP, "convex hull algorithm to use") ISL_ARG_BOOL(struct isl_options, coalesce_bounded_wrapping, 0, "coalesce-bounded-wrapping", 1, "bound wrapping during coalescing") +ISL_ARG_BOOL(struct isl_options, coalesce_preserve_locals, 0, + "coalesce-preserve-locals", 0, + "preserve local variables during coalescing") ISL_ARG_INT(struct isl_options, schedule_max_coefficient, 0, "schedule-max-coefficient", "limit", -1, "Only consider schedules " "where the coefficients of the variable and parameter dimensions " @@ -164,7 +167,7 @@ "schedule-separate-components", 1, "separate components in dependence graph") ISL_ARG_BOOL(struct isl_options, schedule_whole_component, 0, - "schedule-whole-component", 1, + "schedule-whole-component", 0, "try and compute schedule for entire component first") ISL_ARG_CHOICE(struct isl_options, schedule_algorithm, 0, "schedule-algorithm", isl_schedule_algorithm_choice, @@ -240,6 +243,11 @@ coalesce_bounded_wrapping) ISL_CTX_GET_BOOL_DEF(isl_options, struct isl_options, isl_options_args, coalesce_bounded_wrapping) + +ISL_CTX_SET_BOOL_DEF(isl_options, struct isl_options, isl_options_args, + coalesce_preserve_locals) +ISL_CTX_GET_BOOL_DEF(isl_options, struct isl_options, isl_options_args, + coalesce_preserve_locals) ISL_CTX_SET_BOOL_DEF(isl_options, struct isl_options, isl_options_args, gbr_only_first) diff --git a/gcc/isl/isl_options_private.h b/gcc/isl/isl_options_private.h index 13f21a7..3a59d2a 100644 --- a/gcc/isl/isl_options_private.h +++ a/gcc/isl/isl_options_private.h @@ -34,6 +34,7 @@ int convex; int coalesce_bounded_wrapping; + int coalesce_preserve_locals; int schedule_max_coefficient; int schedule_max_constant_term; diff --git a/gcc/isl/isl_output.c b/gcc/isl/isl_output.c index 4888bae..866932e 100644 --- a/gcc/isl/isl_output.c +++ a/gcc/isl/isl_output.c @@ -1,7 +1,8 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * Copyright 2010 INRIA Saclay * Copyright 2012-2013 Ecole Normale Superieure + * Copyright 2019 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -9,7 +10,8 @@ * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite, * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France - * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France + * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France + * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA */ #include @@ -23,10 +25,13 @@ #include #include #include +#include #include #include +#include #include #include +#include #include #include #include @@ -59,11 +64,14 @@ struct isl_basic_map *bmap, int ineq, int n, __isl_take isl_printer *p) { int i; - unsigned n_in = isl_basic_map_dim(bmap, isl_dim_in); - unsigned n_out = isl_basic_map_dim(bmap, isl_dim_out); - unsigned nparam = isl_basic_map_dim(bmap, isl_dim_param); + isl_size n_in = isl_basic_map_dim(bmap, isl_dim_in); + isl_size n_out = isl_basic_map_dim(bmap, isl_dim_out); + isl_size nparam = isl_basic_map_dim(bmap, isl_dim_param); isl_int *c = ineq ? bmap->ineq[n] : bmap->eq[n]; + if (n_in < 0 || n_out < 0 || nparam < 0) + return isl_printer_free(p); + p = isl_printer_start_line(p); p = isl_printer_print_int(p, ineq); for (i = 0; i < n_out; ++i) { @@ -112,24 +120,32 @@ static __isl_give isl_printer *isl_basic_map_print_polylib( __isl_keep isl_basic_map *bmap, __isl_take isl_printer *p, int ext) { - unsigned total = isl_basic_map_total_dim(bmap); + isl_size total; + + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_printer_free(p); p = isl_printer_start_line(p); p = isl_printer_print_int(p, bmap->n_eq + bmap->n_ineq); p = isl_printer_print_str(p, " "); p = isl_printer_print_int(p, 1 + total + 1); if (ext) { + isl_size n_in = isl_basic_map_dim(bmap, isl_dim_in); + isl_size n_out = isl_basic_map_dim(bmap, isl_dim_out); + isl_size n_div = isl_basic_map_dim(bmap, isl_dim_div); + isl_size nparam = isl_basic_map_dim(bmap, isl_dim_param); + + if (n_in < 0 || n_out < 0 || n_div < 0 || nparam < 0) + return isl_printer_free(p); + p = isl_printer_print_str(p, " "); - p = isl_printer_print_int(p, - isl_basic_map_dim(bmap, isl_dim_out)); + p = isl_printer_print_int(p, n_out); p = isl_printer_print_str(p, " "); - p = isl_printer_print_int(p, - isl_basic_map_dim(bmap, isl_dim_in)); + p = isl_printer_print_int(p, n_in); p = isl_printer_print_str(p, " "); - p = isl_printer_print_int(p, - isl_basic_map_dim(bmap, isl_dim_div)); + p = isl_printer_print_int(p, n_div); p = isl_printer_print_str(p, " "); - p = isl_printer_print_int(p, - isl_basic_map_dim(bmap, isl_dim_param)); + p = isl_printer_print_int(p, nparam); } p = isl_printer_end_line(p); return print_constraints_polylib(bmap, p); @@ -163,17 +179,20 @@ return isl_map_print_polylib(set_to_map(set), p, ext); } -static int count_same_name(__isl_keep isl_space *dim, +static isl_size count_same_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos, const char *name) { enum isl_dim_type t; - unsigned p, s; + int p; + isl_size s; int count = 0; for (t = isl_dim_param; t <= type && t <= isl_dim_out; ++t) { - s = t == type ? pos : isl_space_dim(dim, t); + s = t == type ? pos : isl_space_dim(space, t); + if (s < 0) + return isl_size_error; for (p = 0; p < s; ++p) { - const char *n = isl_space_get_dim_name(dim, t, p); + const char *n = isl_space_get_dim_name(space, t, p); if (n && !strcmp(n, name)) count++; } @@ -190,7 +209,7 @@ { const char *name; char buffer[20]; - int primes; + isl_size primes; name = type == isl_dim_div ? NULL : isl_space_get_dim_name(space, type, pos); @@ -210,34 +229,39 @@ } primes = count_same_name(space, name == buffer ? isl_dim_div : type, pos, name); + if (primes < 0) + return isl_printer_free(p); p = isl_printer_print_str(p, name); while (primes-- > 0) p = isl_printer_print_str(p, "'"); return p; } -static enum isl_dim_type pos2type(__isl_keep isl_space *dim, unsigned *pos) +static isl_stat pos2type(__isl_keep isl_space *space, + enum isl_dim_type *type, unsigned *pos) { - enum isl_dim_type type; - unsigned n_in = isl_space_dim(dim, isl_dim_in); - unsigned n_out = isl_space_dim(dim, isl_dim_out); - unsigned nparam = isl_space_dim(dim, isl_dim_param); + isl_size n_in = isl_space_dim(space, isl_dim_in); + isl_size n_out = isl_space_dim(space, isl_dim_out); + isl_size nparam = isl_space_dim(space, isl_dim_param); + if (n_in < 0 || n_out < 0 || nparam < 0) + return isl_stat_error; + if (*pos < 1 + nparam) { - type = isl_dim_param; + *type = isl_dim_param; *pos -= 1; } else if (*pos < 1 + nparam + n_in) { - type = isl_dim_in; + *type = isl_dim_in; *pos -= 1 + nparam; } else if (*pos < 1 + nparam + n_in + n_out) { - type = isl_dim_out; + *type = isl_dim_out; *pos -= 1 + nparam + n_in; } else { - type = isl_dim_div; + *type = isl_dim_div; *pos -= 1 + nparam + n_in + n_out; } - return type; + return isl_stat_ok; } /* Can the div expression of the integer division at position "row" of "div" @@ -254,7 +278,7 @@ return isl_bool_false; if (!div) return isl_bool_false; - return !isl_int_is_zero(div->row[pos][0]); + return isl_bool_not(isl_local_div_is_marked_unknown(div, pos)); } static __isl_give isl_printer *print_div(__isl_keep isl_space *dim, @@ -266,11 +290,15 @@ { enum isl_dim_type type; int print_div_def; + + if (!p || !space) + return isl_printer_free(p); if (pos == 0) return isl_printer_print_isl_int(p, c); - type = pos2type(space, &pos); + if (pos2type(space, &type, &pos) < 0) + return isl_printer_free(p); print_div_def = type == isl_dim_div && can_print_div_expr(p, div, pos); if (isl_int_is_one(c)) @@ -325,28 +353,33 @@ static __isl_give isl_printer *print_affine(__isl_take isl_printer *p, __isl_keep isl_space *space, __isl_keep isl_mat *div, isl_int *c) { - unsigned n_div; + isl_size n_div, total; unsigned len; - if (!space || !div) - return isl_printer_free(p); + total = isl_space_dim(space, isl_dim_all); n_div = isl_mat_rows(div); - len = 1 + isl_space_dim(space, isl_dim_all) + n_div; + if (total < 0 || n_div < 0) + return isl_printer_free(p); + len = 1 + total + n_div; return print_affine_of_len(space, div, p, c, len); } -/* offset is the offset of local_dim inside data->type of data->space. +/* offset is the offset of local_space inside data->type of data->space. */ static __isl_give isl_printer *print_nested_var_list(__isl_take isl_printer *p, - __isl_keep isl_space *local_dim, enum isl_dim_type local_type, + __isl_keep isl_space *local_space, enum isl_dim_type local_type, struct isl_print_space_data *data, int offset) { int i; + isl_size dim; - if (data->space != local_dim && local_type == isl_dim_out) - offset += local_dim->n_in; + if (data->space != local_space && local_type == isl_dim_out) + offset += local_space->n_in; - for (i = 0; i < isl_space_dim(local_dim, local_type); ++i) { + dim = isl_space_dim(local_space, local_type); + if (dim < 0) + return isl_printer_free(p); + for (i = 0; i < dim; ++i) { if (i) p = isl_printer_print_str(p, ", "); if (data->print_dim) @@ -371,13 +404,16 @@ struct isl_print_space_data *data, int offset); static __isl_give isl_printer *print_nested_tuple(__isl_take isl_printer *p, - __isl_keep isl_space *local_dim, enum isl_dim_type local_type, + __isl_keep isl_space *local_space, enum isl_dim_type local_type, struct isl_print_space_data *data, int offset) { const char *name = NULL; - unsigned n = isl_space_dim(local_dim, local_type); + isl_size n = isl_space_dim(local_space, local_type); + + if (n < 0) + return isl_printer_free(p); if ((local_type == isl_dim_in || local_type == isl_dim_out)) { - name = isl_space_get_tuple_name(local_dim, local_type); + name = isl_space_get_tuple_name(local_space, local_type); if (name) { if (data->latex) p = isl_printer_print_str(p, "\\mathrm{"); @@ -389,14 +425,14 @@ if (!data->latex || n != 1 || name) p = isl_printer_print_str(p, s_open_list[data->latex]); if ((local_type == isl_dim_in || local_type == isl_dim_out) && - local_dim->nested[local_type - isl_dim_in]) { - if (data->space != local_dim && local_type == isl_dim_out) - offset += local_dim->n_in; + local_space->nested[local_type - isl_dim_in]) { + if (data->space != local_space && local_type == isl_dim_out) + offset += local_space->n_in; p = print_nested_map_dim(p, - local_dim->nested[local_type - isl_dim_in], + local_space->nested[local_type - isl_dim_in], data, offset); } else - p = print_nested_var_list(p, local_dim, local_type, data, + p = print_nested_var_list(p, local_space, local_type, data, offset); if (!data->latex || n != 1 || name) p = isl_printer_print_str(p, s_close_list[data->latex]); @@ -442,15 +478,19 @@ return p; } -static __isl_give isl_printer *print_omega_parameters(__isl_keep isl_space *dim, - __isl_take isl_printer *p) +static __isl_give isl_printer *print_omega_parameters( + __isl_keep isl_space *space, __isl_take isl_printer *p) { - if (isl_space_dim(dim, isl_dim_param) == 0) + isl_size nparam = isl_space_dim(space, isl_dim_param); + + if (nparam < 0) + return isl_printer_free(p); + if (nparam == 0) return p; p = isl_printer_start_line(p); p = isl_printer_print_str(p, "symbolic "); - p = print_var_list(p, dim, isl_dim_param); + p = print_var_list(p, space, isl_dim_param); p = isl_printer_print_str(p, ";"); p = isl_printer_end_line(p); return p; @@ -462,26 +502,31 @@ * If the next constraint is a div constraint, then it is ignored * since div constraints are not printed. */ -static int next_is_opposite(__isl_keep isl_basic_map *bmap, int i, int last) -{ - unsigned total = isl_basic_map_total_dim(bmap); +static isl_bool next_is_opposite(__isl_keep isl_basic_map *bmap, int i, + int last) +{ + int r; + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); unsigned o_div = isl_basic_map_offset(bmap, isl_dim_div); + if (total < 0) + return isl_bool_error; if (i + 1 >= bmap->n_ineq) - return 0; + return isl_bool_false; if (isl_seq_last_non_zero(bmap->ineq[i + 1], 1 + total) != last) - return 0; + return isl_bool_false; if (last >= o_div) { isl_bool is_div; is_div = isl_basic_map_is_div_constraint(bmap, bmap->ineq[i + 1], last - o_div); if (is_div < 0) - return -1; + return isl_bool_error; if (is_div) - return 0; + return isl_bool_false; } - return isl_int_abs_eq(bmap->ineq[i][last], bmap->ineq[i + 1][last]) && - !isl_int_eq(bmap->ineq[i][last], bmap->ineq[i + 1][last]); + r = isl_int_abs_eq(bmap->ineq[i][last], bmap->ineq[i + 1][last]) && + !isl_int_eq(bmap->ineq[i][last], bmap->ineq[i + 1][last]); + return isl_bool_ok(r); } /* Return a string representation of the operator used when @@ -580,40 +625,41 @@ return p; } -/* Can the equality constraints "c" be printed as a modulo constraint? - * In particular, is of the form +/* Given an equality constraint with a non-zero coefficient "c" + * in position "pos", is this term of the form * - * f - a m floor(g/m) = 0, + * a m floor(g/m), * - * with c = -a m the coefficient at position "pos"? + * with c = a m? * Return the position of the corresponding integer division if so. * Return the number of integer divisions if not. - * Return -1 on error. + * Return isl_size_error on error. * * Modulo constraints are currently not printed in C format. * Other than that, "pos" needs to correspond to an integer division * with explicit representation and "c" needs to be a multiple * of the denominator of the integer division. */ -static int print_as_modulo_pos(__isl_keep isl_printer *p, +static isl_size print_as_modulo_pos(__isl_keep isl_printer *p, __isl_keep isl_space *space, __isl_keep isl_mat *div, unsigned pos, isl_int c) { isl_bool can_print; - unsigned n_div; + isl_size n_div; enum isl_dim_type type; - if (!p) - return -1; n_div = isl_mat_rows(div); + if (!p || !space || n_div < 0) + return isl_size_error; if (p->output_format == ISL_FORMAT_C) return n_div; - type = pos2type(space, &pos); + if (pos2type(space, &type, &pos) < 0) + return isl_size_error; if (type != isl_dim_div) return n_div; can_print = can_print_div_expr(p, div, pos); if (can_print < 0) - return -1; + return isl_size_error; if (!can_print) return n_div; if (!isl_int_is_divisible_by(c, div->row[pos][0])) @@ -675,12 +721,12 @@ __isl_keep isl_space *space, __isl_keep isl_mat *div, isl_int *c, int last, int latex) { - unsigned n_div; - int div_pos; + isl_size n_div; + isl_size div_pos; n_div = isl_mat_rows(div); div_pos = print_as_modulo_pos(p, space, div, last, c[last]); - if (div_pos < 0) + if (n_div < 0 || div_pos < 0) return isl_printer_free(p); if (div_pos < n_div) return print_eq_mod_constraint(p, space, div, div_pos, @@ -735,13 +781,13 @@ int i; isl_vec *c = NULL; int rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL); - unsigned total = isl_basic_map_total_dim(bmap); + isl_size total = isl_basic_map_dim(bmap, isl_dim_all); unsigned o_div = isl_basic_map_offset(bmap, isl_dim_div); int first = 1; int dump; - if (!p) - return NULL; + if (total < 0 || !p) + return isl_printer_free(p); bmap = isl_basic_map_copy(bmap); dump = p->dump; if (!dump) @@ -771,6 +817,7 @@ first = 0; } for (i = 0; i < bmap->n_ineq; ++i) { + isl_bool combine; int l = isl_seq_last_non_zero(bmap->ineq[i], 1 + total); int strict; int s; @@ -797,7 +844,10 @@ isl_seq_neg(c->el, bmap->ineq[i], 1 + total); if (strict) isl_int_set_si(c->el[0], 0); - if (!dump && next_is_opposite(bmap, i, l)) { + combine = dump ? isl_bool_false : next_is_opposite(bmap, i, l); + if (combine < 0) + goto error; + if (combine) { op = constraint_op(-s, strict, latex); p = print_half_constraint(p, space, div, c->el, l, op, latex); @@ -850,12 +900,11 @@ { int i; int first = 1; - unsigned n_div; + isl_size n_div; - if (!p || !space || !div) - return isl_printer_free(p); - n_div = isl_mat_rows(div); + if (!p || !space || n_div < 0) + return isl_printer_free(p); for (i = 0; i < n_div; ++i) { if (!print_defined_divs && can_print_div_expr(p, div, i)) @@ -881,11 +930,12 @@ */ static isl_bool need_exists(__isl_keep isl_printer *p, __isl_keep isl_mat *div) { - int i, n; + int i; + isl_size n; - if (!p || !div) - return isl_bool_error; n = isl_mat_rows(div); + if (!p || n < 0) + return isl_bool_error; if (n == 0) return isl_bool_false; if (p->dump) @@ -923,12 +973,13 @@ */ static __isl_give isl_mat *mark_all_unknown(__isl_take isl_mat *div) { - int i, n_div; - - if (!div) - return NULL; + int i; + isl_size n_div; n_div = isl_mat_rows(div); + if (n_div < 0) + return isl_mat_free(div); + for (i = 0; i < n_div; ++i) div = isl_mat_set_element_si(div, i, 0, 0); return div; @@ -1038,9 +1089,12 @@ static __isl_give isl_printer *print_param_tuple(__isl_take isl_printer *p, __isl_keep isl_space *space, struct isl_print_space_data *data) { - if (!p || !space) + isl_size nparam; + + nparam = isl_space_dim(space, isl_dim_param); + if (!p || nparam < 0) return isl_printer_free(p); - if (isl_space_dim(space, isl_dim_param) == 0) + if (nparam == 0) return p; p = print_tuple(space, p, isl_dim_param, data); @@ -1175,6 +1229,16 @@ return print_disjuncts(map, space, p, latex); } +/* Print the disjuncts of a set. + * The names of the variables are taken from "space". + * "latex" is set if the constraints should be printed in LaTeX format. + */ +static __isl_give isl_printer *print_disjuncts_set(__isl_keep isl_set *set, + __isl_keep isl_space *space, __isl_take isl_printer *p, int latex) +{ + return print_disjuncts_map(set_to_map(set), space, p, latex); +} + struct isl_aff_split { isl_basic_map *aff; isl_map *map; @@ -1198,18 +1262,20 @@ static __isl_give isl_basic_map *get_aff(__isl_take isl_basic_map *bmap) { int i, j; - unsigned nparam, n_in, n_out, total; + isl_size nparam, n_in, n_out, total; bmap = isl_basic_map_cow(bmap); if (!bmap) return NULL; - if (isl_basic_map_free_inequality(bmap, bmap->n_ineq) < 0) - goto error; + bmap = isl_basic_map_free_inequality(bmap, bmap->n_ineq); nparam = isl_basic_map_dim(bmap, isl_dim_param); n_in = isl_basic_map_dim(bmap, isl_dim_in); n_out = isl_basic_map_dim(bmap, isl_dim_out); total = isl_basic_map_dim(bmap, isl_dim_all); + if (n_in < 0 || n_out < 0 || nparam < 0 || total < 0) + return isl_basic_map_free(bmap); + for (i = bmap->n_eq - 1; i >= 0; --i) { j = isl_seq_last_non_zero(bmap->eq[i] + 1, total); if (j >= nparam && j < nparam + n_in + n_out && @@ -1241,20 +1307,19 @@ __isl_keep isl_basic_map *aff) { int i, j; - unsigned total; + isl_size v_div; - if (!bmap || !aff) + v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + if (v_div < 0 || !aff) goto error; - - total = isl_space_dim(bmap->dim, isl_dim_all); for (i = bmap->n_eq - 1; i >= 0; --i) { - if (isl_seq_first_non_zero(bmap->eq[i] + 1 + total, + if (isl_seq_first_non_zero(bmap->eq[i] + 1 + v_div, bmap->n_div) != -1) continue; for (j = 0; j < aff->n_eq; ++j) { - if (!isl_seq_eq(bmap->eq[i], aff->eq[j], 1 + total) && - !isl_seq_is_neg(bmap->eq[i], aff->eq[j], 1 + total)) + if (!isl_seq_eq(bmap->eq[i], aff->eq[j], 1 + v_div) && + !isl_seq_is_neg(bmap->eq[i], aff->eq[j], 1 + v_div)) continue; if (isl_basic_map_drop_equality(bmap, i) < 0) goto error; @@ -1319,13 +1384,13 @@ __isl_keep isl_space *dim, enum isl_dim_type type, int pos) { int i; - unsigned total; + isl_size total; - if (!eq) + total = isl_basic_map_dim(eq, isl_dim_all); + if (total < 0) return -1; pos += isl_space_offset(dim, type); - total = isl_basic_map_total_dim(eq); for (i = 0; i < eq->n_eq; ++i) { if (isl_seq_last_non_zero(eq->eq[i] + 1, total) != pos) @@ -1567,22 +1632,46 @@ return isl_stat_ok; } -static __isl_give isl_printer *isl_union_map_print_isl( - __isl_keep isl_union_map *umap, __isl_take isl_printer *p) +/* Print the body of "umap" (everything except the parameter declarations) + * to "p" in isl format. + */ +static __isl_give isl_printer *isl_printer_print_union_map_isl_body( + __isl_take isl_printer *p, __isl_keep isl_union_map *umap) { struct isl_union_print_data data; - struct isl_print_space_data space_data = { 0 }; - isl_space *space; - space = isl_union_map_get_space(umap); - p = print_param_tuple(p, space, &space_data); - isl_space_free(space); p = isl_printer_print_str(p, s_open_set[0]); data.p = p; data.first = 1; isl_union_map_foreach_map(umap, &print_map_body, &data); p = data.p; p = isl_printer_print_str(p, s_close_set[0]); + return p; +} + +/* Print the body of "uset" (everything except the parameter declarations) + * to "p" in isl format. + */ +static __isl_give isl_printer *isl_printer_print_union_set_isl_body( + __isl_take isl_printer *p, __isl_keep isl_union_set *uset) +{ + return isl_printer_print_union_map_isl_body(p, uset_to_umap(uset)); +} + +/* Print the isl_union_map "umap" to "p" in isl format. + */ +static __isl_give isl_printer *isl_union_map_print_isl( + __isl_keep isl_union_map *umap, __isl_take isl_printer *p) +{ + struct isl_print_space_data space_data = { 0 }; + isl_space *space; + + space = isl_union_map_get_space(umap); + p = print_param_tuple(p, space, &space_data); + isl_space_free(space); + + p = isl_printer_print_union_map_isl_body(p, umap); + return p; } @@ -1646,25 +1735,33 @@ return NULL; } -static int upoly_rec_n_non_zero(__isl_keep struct isl_upoly_rec *rec) +static isl_size poly_rec_n_non_zero(__isl_keep isl_poly_rec *rec) { int i; int n; + + if (!rec) + return isl_size_error; - for (i = 0, n = 0; i < rec->n; ++i) - if (!isl_upoly_is_zero(rec->p[i])) + for (i = 0, n = 0; i < rec->n; ++i) { + isl_bool is_zero = isl_poly_is_zero(rec->p[i]); + + if (is_zero < 0) + return isl_size_error; + if (!is_zero) ++n; + } return n; } -static __isl_give isl_printer *upoly_print_cst(__isl_keep struct isl_upoly *up, +static __isl_give isl_printer *poly_print_cst(__isl_keep isl_poly *poly, __isl_take isl_printer *p, int first) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; int neg; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) goto error; neg = !first && isl_int_is_neg(cst->n); @@ -1691,15 +1788,17 @@ } static __isl_give isl_printer *print_base(__isl_take isl_printer *p, - __isl_keep isl_space *dim, __isl_keep isl_mat *div, int var) + __isl_keep isl_space *space, __isl_keep isl_mat *div, int var) { - unsigned total; + isl_size total; - total = isl_space_dim(dim, isl_dim_all); + total = isl_space_dim(space, isl_dim_all); + if (total < 0) + return isl_printer_free(p); if (var < total) - p = print_term(dim, NULL, dim->ctx->one, 1 + var, p, 0); + p = print_term(space, NULL, space->ctx->one, 1 + var, p, 0); else - p = print_div(dim, div, var - total, p); + p = print_div(space, div, var - total, p); return p; } @@ -1722,55 +1821,63 @@ return p; } -/* Print the polynomial "up" defined over the domain space "space" and +/* Print the polynomial "poly" defined over the domain space "space" and * local variables defined by "div" to "p". */ -static __isl_give isl_printer *upoly_print(__isl_keep struct isl_upoly *up, +static __isl_give isl_printer *poly_print(__isl_keep isl_poly *poly, __isl_keep isl_space *space, __isl_keep isl_mat *div, __isl_take isl_printer *p) { - int i, n, first, print_parens; - struct isl_upoly_rec *rec; + int i, first, print_parens; + isl_size n; + isl_bool is_cst; + isl_poly_rec *rec; - if (!p || !up || !space || !div) + is_cst = isl_poly_is_cst(poly); + if (!p || is_cst < 0 || !space || !div) goto error; - if (isl_upoly_is_cst(up)) - return upoly_print_cst(up, p, 1); + if (is_cst) + return poly_print_cst(poly, p, 1); - rec = isl_upoly_as_rec(up); - if (!rec) - goto error; - n = upoly_rec_n_non_zero(rec); + rec = isl_poly_as_rec(poly); + n = poly_rec_n_non_zero(rec); + if (n < 0) + return isl_printer_free(p); print_parens = n > 1; if (print_parens) p = isl_printer_print_str(p, "("); for (i = 0, first = 1; i < rec->n; ++i) { - if (isl_upoly_is_zero(rec->p[i])) + isl_bool is_zero = isl_poly_is_zero(rec->p[i]); + isl_bool is_one = isl_poly_is_one(rec->p[i]); + isl_bool is_negone = isl_poly_is_negone(rec->p[i]); + isl_bool is_cst = isl_poly_is_cst(rec->p[i]); + + if (is_zero < 0 || is_one < 0 || is_negone < 0) + return isl_printer_free(p); + if (is_zero) continue; - if (isl_upoly_is_negone(rec->p[i])) { + if (is_negone) { if (!i) p = isl_printer_print_str(p, "-1"); else if (first) p = isl_printer_print_str(p, "-"); else p = isl_printer_print_str(p, " - "); - } else if (isl_upoly_is_cst(rec->p[i]) && - !isl_upoly_is_one(rec->p[i])) - p = upoly_print_cst(rec->p[i], p, first); + } else if (is_cst && !is_one) + p = poly_print_cst(rec->p[i], p, first); else { if (!first) p = isl_printer_print_str(p, " + "); - if (i == 0 || !isl_upoly_is_one(rec->p[i])) - p = upoly_print(rec->p[i], space, div, p); + if (i == 0 || !is_one) + p = poly_print(rec->p[i], space, div, p); } first = 0; if (i == 0) continue; - if (!isl_upoly_is_one(rec->p[i]) && - !isl_upoly_is_negone(rec->p[i])) + if (!is_one && !is_negone) p = isl_printer_print_str(p, " * "); - p = print_pow(p, space, div, rec->up.var, i); + p = print_pow(p, space, div, rec->poly.var, i); } if (print_parens) p = isl_printer_print_str(p, ")"); @@ -1785,7 +1892,7 @@ { if (!p || !qp) goto error; - p = upoly_print(qp->upoly, qp->dim, qp->div, p); + p = poly_print(qp->poly, qp->dim, qp->div, p); return p; error: isl_printer_free(p); @@ -1820,28 +1927,27 @@ static __isl_give isl_printer *print_qpolynomial_c(__isl_take isl_printer *p, __isl_keep isl_space *space, __isl_keep isl_qpolynomial *qp) { - isl_int den; - - isl_int_init(den); - isl_qpolynomial_get_den(qp, &den); - if (!isl_int_is_one(den)) { - isl_qpolynomial *f; + isl_bool is_one; + isl_val *den; + + den = isl_qpolynomial_get_den(qp); + qp = isl_qpolynomial_copy(qp); + qp = isl_qpolynomial_scale_val(qp, isl_val_copy(den)); + is_one = isl_val_is_one(den); + if (is_one < 0) + p = isl_printer_free(p); + if (!is_one) p = isl_printer_print_str(p, "("); - qp = isl_qpolynomial_copy(qp); - f = isl_qpolynomial_rat_cst_on_domain(isl_space_copy(qp->dim), - den, qp->dim->ctx->one); - qp = isl_qpolynomial_mul(qp, f); - } if (qp) - p = upoly_print(qp->upoly, space, qp->div, p); + p = poly_print(qp->poly, space, qp->div, p); else p = isl_printer_free(p); - if (!isl_int_is_one(den)) { + if (!is_one) { p = isl_printer_print_str(p, ")/"); - p = isl_printer_print_isl_int(p, den); - isl_qpolynomial_free(qp); + p = isl_printer_print_val(p, den); } - isl_int_clear(den); + isl_qpolynomial_free(qp); + isl_val_free(den); return p; } @@ -2017,90 +2123,11 @@ } p = isl_pwf_print_isl_body(p, pwf); p = isl_printer_print_str(p, " }"); - return p; -} - -static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c); - -static __isl_give isl_printer *print_name_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, - __isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos) -{ - if (type == isl_dim_div) { - p = isl_printer_print_str(p, "floord("); - p = print_affine_c(p, dim, bset, bset->div[pos] + 1); - p = isl_printer_print_str(p, ", "); - p = isl_printer_print_isl_int(p, bset->div[pos][0]); - p = isl_printer_print_str(p, ")"); - } else { - const char *name; - - name = isl_space_get_dim_name(dim, type, pos); - if (!name) - name = "UNNAMED"; - p = isl_printer_print_str(p, name); - } - return p; -} - -static __isl_give isl_printer *print_term_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, - __isl_keep isl_basic_set *bset, isl_int c, unsigned pos) -{ - enum isl_dim_type type; - - if (pos == 0) - return isl_printer_print_isl_int(p, c); - - if (isl_int_is_one(c)) - ; - else if (isl_int_is_negone(c)) - p = isl_printer_print_str(p, "-"); - else { - p = isl_printer_print_isl_int(p, c); - p = isl_printer_print_str(p, "*"); - } - type = pos2type(dim, &pos); - p = print_name_c(p, dim, bset, type, pos); - return p; -} - -static __isl_give isl_printer *print_partial_affine_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, - __isl_keep isl_basic_set *bset, isl_int *c, unsigned len) -{ - int i; - int first; - - for (i = 0, first = 1; i < len; ++i) { - int flip = 0; - if (isl_int_is_zero(c[i])) - continue; - if (!first) { - if (isl_int_is_neg(c[i])) { - flip = 1; - isl_int_neg(c[i], c[i]); - p = isl_printer_print_str(p, " - "); - } else - p = isl_printer_print_str(p, " + "); - } - first = 0; - p = print_term_c(p, dim, bset, c[i], i); - if (flip) - isl_int_neg(c[i], c[i]); - } - if (first) - p = isl_printer_print_str(p, "0"); return p; } -static __isl_give isl_printer *print_affine_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset, isl_int *c) -{ - unsigned len = 1 + isl_basic_set_total_dim(bset); - return print_partial_affine_c(p, dim, bset, c, len); -} +static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p, + __isl_keep isl_local_space *ls, isl_int *c); /* We skip the constraint if it is implied by the div expression. * @@ -2108,18 +2135,19 @@ * is updated if the constraint is actually printed. */ static __isl_give isl_printer *print_constraint_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, - __isl_keep isl_basic_set *bset, isl_int *c, const char *op, int *first) + __isl_keep isl_local_space *ls, isl_int *c, const char *op, int *first) { unsigned o_div; - unsigned n_div; + isl_size n_div; int div; - o_div = isl_basic_set_offset(bset, isl_dim_div); - n_div = isl_basic_set_dim(bset, isl_dim_div); + o_div = isl_local_space_offset(ls, isl_dim_div); + n_div = isl_local_space_dim(ls, isl_dim_div); + if (n_div < 0) + return isl_printer_free(p); div = isl_seq_last_non_zero(c + o_div, n_div); if (div >= 0) { - isl_bool is_div = isl_basic_set_is_div_constraint(bset, c, div); + isl_bool is_div = isl_local_space_is_div_constraint(ls, c, div); if (is_div < 0) return isl_printer_free(p); if (is_div) @@ -2129,7 +2157,7 @@ if (!*first) p = isl_printer_print_str(p, " && "); - p = print_affine_c(p, dim, bset, c); + p = print_ls_affine_c(p, ls, c); p = isl_printer_print_str(p, " "); p = isl_printer_print_str(p, op); p = isl_printer_print_str(p, " 0"); @@ -2138,25 +2166,37 @@ return p; } + +static __isl_give isl_printer *print_ls_partial_affine_c( + __isl_take isl_printer *p, __isl_keep isl_local_space *ls, + isl_int *c, unsigned len); static __isl_give isl_printer *print_basic_set_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, __isl_keep isl_basic_set *bset) + __isl_keep isl_space *space, __isl_keep isl_basic_set *bset) { int i, j; int first = 1; - unsigned n_div = isl_basic_set_dim(bset, isl_dim_div); - unsigned total = isl_basic_set_total_dim(bset) - n_div; + isl_size n_div = isl_basic_set_dim(bset, isl_dim_div); + isl_size total = isl_basic_set_dim(bset, isl_dim_all); + isl_mat *div; + isl_local_space *ls; + + if (n_div < 0 || total < 0) + return isl_printer_free(p); + total -= n_div; + div = isl_basic_set_get_divs(bset); + ls = isl_local_space_alloc_div(isl_space_copy(space), div); for (i = 0; i < bset->n_eq; ++i) { j = isl_seq_last_non_zero(bset->eq[i] + 1 + total, n_div); if (j < 0) - p = print_constraint_c(p, dim, bset, + p = print_constraint_c(p, ls, bset->eq[i], "==", &first); else { if (i) p = isl_printer_print_str(p, " && "); p = isl_printer_print_str(p, "("); - p = print_partial_affine_c(p, dim, bset, bset->eq[i], + p = print_ls_partial_affine_c(p, ls, bset->eq[i], 1 + total + j); p = isl_printer_print_str(p, ") % "); p = isl_printer_print_isl_int(p, @@ -2166,13 +2206,13 @@ } } for (i = 0; i < bset->n_ineq; ++i) - p = print_constraint_c(p, dim, bset, bset->ineq[i], ">=", - &first); + p = print_constraint_c(p, ls, bset->ineq[i], ">=", &first); + isl_local_space_free(ls); return p; } static __isl_give isl_printer *print_set_c(__isl_take isl_printer *p, - __isl_keep isl_space *dim, __isl_keep isl_set *set) + __isl_keep isl_space *space, __isl_keep isl_set *set) { int i; @@ -2187,7 +2227,7 @@ p = isl_printer_print_str(p, " || "); if (set->n > 1) p = isl_printer_print_str(p, "("); - p = print_basic_set_c(p, dim, set->p[i]); + p = print_basic_set_c(p, space, set->p[i]); if (set->n > 1) p = isl_printer_print_str(p, ")"); } @@ -2528,15 +2568,15 @@ __isl_keep isl_local_space *ls) { struct isl_print_space_data data = { 0 }; - unsigned n_div; + isl_size n_div; - if (!ls) + n_div = isl_local_space_dim(ls, isl_dim_div); + if (n_div < 0) goto error; p = print_param_tuple(p, ls->dim, &data); p = isl_printer_print_str(p, "{ "); p = isl_print_space(ls->dim, p, 0, &data); - n_div = isl_local_space_dim(ls, isl_dim_div); if (n_div > 0) { p = isl_printer_print_str(p, " : "); p = isl_printer_print_str(p, s_open_exists[0]); @@ -2551,18 +2591,193 @@ return NULL; } -static __isl_give isl_printer *print_aff_body(__isl_take isl_printer *p, - __isl_keep isl_aff *aff) +/* Look for the last of the "n" integer divisions that is used in "aff" and + * that can be printed as a modulo and + * return the position of this integer division. + * Return "n" if no such integer division can be found. + * Return isl_size_error on error. + * + * In particular, look for an integer division that appears in "aff" + * with a coefficient that is a multiple of the denominator + * of the integer division. + * That is, check if the numerator of "aff" is of the form + * + * f(...) + a m floor(g/m) + * + * and return the position of "floor(g/m)". + * + * Note that, unlike print_as_modulo_pos, no check needs to be made + * for whether the integer division can be printed, since it will + * need to be printed as an integer division anyway if it is not printed + * as a modulo. + */ +static isl_size last_modulo(__isl_keep isl_printer *p, __isl_keep isl_aff *aff, + unsigned n) +{ + isl_size o_div; + int i; + + if (n == 0) + return n; + o_div = isl_aff_domain_offset(aff, isl_dim_div); + if (o_div < 0) + return isl_size_error; + for (i = n - 1; i >= 0; --i) { + if (isl_int_is_zero(aff->v->el[1 + o_div + i])) + continue; + if (isl_int_is_divisible_by(aff->v->el[1 + o_div + i], + aff->ls->div->row[i][0])) + return i; + } + + return n; +} + +/* Print the numerator of the affine expression "aff" to "p", + * with the variable names taken from "space". + */ +static __isl_give isl_printer *print_aff_num_base(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff) +{ + isl_size total; + + total = isl_aff_domain_dim(aff, isl_dim_all); + if (total < 0) + return isl_printer_free(p); + p = print_affine_of_len(space, aff->ls->div, p, + aff->v->el + 1, 1 + total); + + return p; +} + +static __isl_give isl_printer *print_aff_num(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff); + +/* Print the modulo term "c" * ("aff" mod "mod") to "p", + * with the variable names taken from "space". + * If "first" is set, then this is the first term of an expression. + */ +static __isl_give isl_printer *print_mod_term(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff, int first, + __isl_take isl_val *c, __isl_keep isl_val *mod) { - unsigned total; + isl_bool is_one, is_neg; + is_neg = isl_val_is_neg(c); + if (is_neg < 0) + p = isl_printer_free(p); + if (!first) { + if (is_neg) + c = isl_val_neg(c); + p = isl_printer_print_str(p, is_neg ? " - " : " + "); + } + is_one = isl_val_is_one(c); + if (is_one < 0) + p = isl_printer_free(p); + if (!is_one) { + p = isl_printer_print_val(p, c); + p = isl_printer_print_str(p, "*("); + } + p = isl_printer_print_str(p, "("); + p = print_aff_num(p, space, aff); + p = isl_printer_print_str(p, ")"); + p = isl_printer_print_str(p, " mod "); + p = isl_printer_print_val(p, mod); + if (!is_one) + p = isl_printer_print_str(p, ")"); + + isl_val_free(c); + + return p; +} + +/* Print the numerator of the affine expression "aff" to "p", + * with the variable names taken from "space", + * given that the numerator of "aff" is of the form + * + * f(...) + a m floor(g/m) + * + * with "floor(g/m)" the integer division at position "last". + * + * First replace "aff" by its numerator and rewrite it as + * + * f(...) + a g - a (g mod m) + * + * Recursively write out (the numerator of) "f(...) + a g" + * (which may involve other modulo expressions) and + * then write out "- a (g mod m)". + */ +static __isl_give isl_printer *print_aff_num_mod(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff, unsigned last) +{ + isl_bool is_zero; + isl_val *a, *m; + isl_aff *div, *term; + + aff = isl_aff_copy(aff); + aff = isl_aff_scale_val(aff, isl_aff_get_denominator_val(aff)); + a = isl_aff_get_coefficient_val(aff, isl_dim_div, last); + aff = isl_aff_set_coefficient_si(aff, isl_dim_div, last, 0); + div = isl_aff_get_div(aff, last); + m = isl_aff_get_denominator_val(div); + a = isl_val_div(a, isl_val_copy(m)); + div = isl_aff_scale_val(div, isl_val_copy(m)); + term = isl_aff_scale_val(isl_aff_copy(div), isl_val_copy(a)); + aff = isl_aff_add(aff, term); + + is_zero = isl_aff_plain_is_zero(aff); + if (is_zero < 0) { + p = isl_printer_free(p); + } else { + if (!is_zero) + p = print_aff_num(p, space, aff); + a = isl_val_neg(a); + p = print_mod_term(p, space, div, is_zero, isl_val_copy(a), m); + } + + isl_val_free(a); + isl_val_free(m); + isl_aff_free(aff); + isl_aff_free(div); + + return p; +} + +/* Print the numerator of the affine expression "aff" to "p", + * with the variable names taken from "space", + * separating out any (obvious) modulo expressions. + * + * In particular, look for modulo expressions in "aff", + * separating them out if found and simply printing out "aff" otherwise. + */ +static __isl_give isl_printer *print_aff_num(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff) +{ + isl_size n_div, mod; + + n_div = isl_aff_dim(aff, isl_dim_div); + if (n_div < 0) + return isl_printer_free(p); + mod = last_modulo(p, aff, n_div); + if (mod < 0) + return isl_printer_free(p); + if (mod < n_div) + return print_aff_num_mod(p, space, aff, mod); + else + return print_aff_num_base(p, space, aff); +} + +/* Print the (potentially rational) affine expression "aff" to "p", + * with the variable names taken from "space". + */ +static __isl_give isl_printer *print_aff_body(__isl_take isl_printer *p, + __isl_keep isl_space *space, __isl_keep isl_aff *aff) +{ if (isl_aff_is_nan(aff)) return isl_printer_print_str(p, "NaN"); - total = isl_local_space_dim(aff->ls, isl_dim_all); p = isl_printer_print_str(p, "("); - p = print_affine_of_len(aff->ls->dim, aff->ls->div, p, - aff->v->el + 1, 1 + total); + p = print_aff_num(p, space, aff); if (isl_int_is_one(aff->v->el[0])) p = isl_printer_print_str(p, ")"); else { @@ -2585,7 +2800,7 @@ p = isl_printer_print_str(p, " -> "); } p = isl_printer_print_str(p, "["); - p = print_aff_body(p, aff); + p = print_aff_body(p, aff->ls->dim, aff); p = isl_printer_print_str(p, "]"); return p; @@ -2651,9 +2866,6 @@ isl_printer_free(p); return NULL; } - -static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p, - __isl_keep isl_local_space *ls, isl_int *c); static __isl_give isl_printer *print_ls_name_c(__isl_take isl_printer *p, __isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos) @@ -2679,6 +2891,9 @@ __isl_keep isl_local_space *ls, isl_int c, unsigned pos) { enum isl_dim_type type; + + if (!p || !ls) + return isl_printer_free(p); if (pos == 0) return isl_printer_print_isl_int(p, c); @@ -2691,7 +2906,8 @@ p = isl_printer_print_isl_int(p, c); p = isl_printer_print_str(p, "*"); } - type = pos2type(ls->dim, &pos); + if (pos2type(ls->dim, &type, &pos) < 0) + return isl_printer_free(p); p = print_ls_name_c(p, ls, type, pos); return p; } @@ -2728,16 +2944,21 @@ static __isl_give isl_printer *print_ls_affine_c(__isl_take isl_printer *p, __isl_keep isl_local_space *ls, isl_int *c) { - unsigned len = 1 + isl_local_space_dim(ls, isl_dim_all); - return print_ls_partial_affine_c(p, ls, c, len); + isl_size total = isl_local_space_dim(ls, isl_dim_all); + + if (total < 0) + return isl_printer_free(p); + return print_ls_partial_affine_c(p, ls, c, 1 + total); } static __isl_give isl_printer *print_aff_c(__isl_take isl_printer *p, __isl_keep isl_aff *aff) { - unsigned total; + isl_size total; - total = isl_local_space_dim(aff->ls, isl_dim_all); + total = isl_aff_domain_dim(aff, isl_dim_all); + if (total < 0) + return isl_printer_free(p); if (!isl_int_is_one(aff->v->el[0])) p = isl_printer_print_str(p, "("); p = print_ls_partial_affine_c(p, aff->ls, aff->v->el + 1, 1 + total); @@ -2844,7 +3065,7 @@ data.p = p; if (isl_union_pw_aff_foreach_pw_aff(upa, &print_pw_aff_body_wrap, &data) < 0) - data.p = isl_printer_free(p); + data.p = isl_printer_free(data.p); p = data.p; p = isl_printer_print_str(p, s_close_set[0]); @@ -2890,16 +3111,26 @@ * * If the current dimension is an output dimension, then print * the corresponding expression. Otherwise, print the name of the dimension. + * Make sure to use the domain space for printing names as + * that is the space that will be used for printing constraints (if any). */ static __isl_give isl_printer *print_dim_ma(__isl_take isl_printer *p, struct isl_print_space_data *data, unsigned pos) { isl_multi_aff *ma = data->user; + isl_space *space; - if (data->type == isl_dim_out) - p = print_aff_body(p, ma->p[pos]); - else - p = print_name(data->space, p, data->type, pos, data->latex); + space = isl_multi_aff_get_domain_space(ma); + if (data->type == isl_dim_out) { + p = print_aff_body(p, space, ma->u.p[pos]); + } else { + enum isl_dim_type type = data->type; + + if (type == isl_dim_in) + type = isl_dim_set; + p = print_name(space, p, type, pos, data->latex); + } + isl_space_free(space); return p; } @@ -3003,18 +3234,18 @@ p = isl_printer_print_str(p, "("); p = print_set_c(p, space, pma->p[i].set); p = isl_printer_print_str(p, ") ? ("); - p = print_aff_c(p, pma->p[i].maff->p[0]); + p = print_aff_c(p, pma->p[i].maff->u.p[0]); p = isl_printer_print_str(p, ") : "); } isl_space_free(space); - return print_aff_c(p, pma->p[pma->n - 1].maff->p[0]); + return print_aff_c(p, pma->p[pma->n - 1].maff->u.p[0]); } static __isl_give isl_printer *print_pw_multi_aff_c(__isl_take isl_printer *p, __isl_keep isl_pw_multi_aff *pma) { - int n; + isl_size n; const char *name; if (!pma) @@ -3023,8 +3254,11 @@ isl_die(p->ctx, isl_error_unsupported, "cannot print empty isl_pw_multi_aff in C format", goto error); + n = isl_pw_multi_aff_dim(pma, isl_dim_out); + if (n < 0) + return isl_printer_free(p); name = isl_pw_multi_aff_get_tuple_name(pma, isl_dim_out); - if (!name && isl_pw_multi_aff_dim(pma, isl_dim_out) == 1) + if (!name && n == 1) return print_unnamed_pw_multi_aff_c(p, pma); if (!name) isl_die(p->ctx, isl_error_unsupported, @@ -3032,7 +3266,6 @@ goto error); p = isl_printer_print_str(p, name); - n = isl_pw_multi_aff_dim(pma, isl_dim_out); if (n != 0) isl_die(p->ctx, isl_error_unsupported, "not supported yet", goto error); @@ -3118,35 +3351,46 @@ * If the current dimension is an output dimension, then print * the corresponding piecewise affine expression. * Otherwise, print the name of the dimension. + * Make sure to use the same space in both cases. + * In particular, use the domain space for printing names as + * that is the space that is used for printing constraints. */ static __isl_give isl_printer *print_dim_mpa(__isl_take isl_printer *p, struct isl_print_space_data *data, unsigned pos) { int i; int need_parens; + isl_space *space; isl_multi_pw_aff *mpa = data->user; isl_pw_aff *pa; - if (data->type != isl_dim_out) - return print_name(data->space, p, data->type, pos, data->latex); + if (data->type != isl_dim_out) { + enum isl_dim_type type = data->type; + + if (type == isl_dim_in) + type = isl_dim_set; + space = isl_multi_pw_aff_get_domain_space(mpa); + p = print_name(space, p, type, pos, data->latex); + isl_space_free(space); + return p; + } - pa = mpa->p[pos]; + pa = mpa->u.p[pos]; if (pa->n == 0) return isl_printer_print_str(p, "(0 : false)"); need_parens = pa->n != 1 || !isl_set_plain_is_universe(pa->p[0].set); if (need_parens) p = isl_printer_print_str(p, "("); + space = isl_multi_pw_aff_get_domain_space(mpa); for (i = 0; i < pa->n; ++i) { - isl_space *space; if (i) p = isl_printer_print_str(p, "; "); - p = print_aff_body(p, pa->p[i].aff); - space = isl_aff_get_domain_space(pa->p[i].aff); + p = print_aff_body(p, space, pa->p[i].aff); p = print_disjuncts(pa->p[i].set, space, p, 0); - isl_space_free(space); } + isl_space_free(space); if (need_parens) p = isl_printer_print_str(p, ")"); @@ -3154,11 +3398,15 @@ } /* Print "mpa" to "p" in isl format. + * + * If "mpa" is zero-dimensional and has a non-trivial explicit domain, + * then it is printed after the tuple of affine expressions. */ static __isl_give isl_printer *print_multi_pw_aff_isl(__isl_take isl_printer *p, __isl_keep isl_multi_pw_aff *mpa) { struct isl_print_space_data data = { 0 }; + isl_bool has_domain; if (!mpa) return isl_printer_free(p); @@ -3168,6 +3416,16 @@ data.print_dim = &print_dim_mpa; data.user = mpa; p = isl_print_space(mpa->space, p, 0, &data); + has_domain = isl_multi_pw_aff_has_non_trivial_domain(mpa); + if (has_domain < 0) + return isl_printer_free(p); + if (has_domain) { + isl_space *space; + + space = isl_space_domain(isl_space_copy(mpa->space)); + p = print_disjuncts_set(mpa->u.dom, space, p, 0); + isl_space_free(space); + } p = isl_printer_print_str(p, " }"); return p; } @@ -3197,7 +3455,7 @@ isl_multi_val *mv = data->user; if (data->type == isl_dim_out) - return isl_printer_print_val(p, mv->p[pos]); + return isl_printer_print_val(p, mv->u.p[pos]); else return print_name(data->space, p, data->type, pos, data->latex); } @@ -3235,8 +3493,60 @@ return print_multi_val_isl(p, mv); isl_die(p->ctx, 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_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. @@ -3259,21 +3569,44 @@ } /* Print the isl_multi_union_pw_aff "mupa" to "p" in isl format. + * + * If "mupa" is zero-dimensional and has a non-trivial explicit domain, + * then it is printed after the tuple of affine expressions. + * In order to clarify that this domain belongs to the expression, + * the tuple along with the domain are placed inside parentheses. + * If "mupa" has any parameters, then the opening parenthesis + * appears after the parameter declarations. */ static __isl_give isl_printer *print_multi_union_pw_aff_isl( __isl_take isl_printer *p, __isl_keep isl_multi_union_pw_aff *mupa) { struct isl_print_space_data data = { 0 }; + isl_bool has_domain; isl_space *space; + + if (!mupa) + return isl_printer_free(p); + has_domain = isl_multi_union_pw_aff_has_non_trivial_domain(mupa); + if (has_domain < 0) + return isl_printer_free(p); space = isl_multi_union_pw_aff_get_space(mupa); p = print_param_tuple(p, space, &data); + if (has_domain) + p = isl_printer_print_str(p, "("); + data.print_dim = &print_union_pw_aff_dim; data.user = mupa; p = isl_print_space(space, p, 0, &data); isl_space_free(space); + + if (has_domain) { + p = isl_printer_print_str(p, " : "); + p = isl_printer_print_union_set_isl_body(p, mupa->u.dom); + p = isl_printer_print_str(p, ")"); + } return p; } diff --git a/gcc/isl/isl_point.c b/gcc/isl/isl_point.c index 2d5b306..8bd76ad 100644 --- a/gcc/isl/isl_point.c +++ a/gcc/isl/isl_point.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -17,55 +18,66 @@ return pnt ? isl_space_get_ctx(pnt->dim) : NULL; } +/* Return the space of "pnt". + */ +__isl_keep isl_space *isl_point_peek_space(__isl_keep isl_point *pnt) +{ + return pnt ? pnt->dim : NULL; +} + __isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt) { - return pnt ? isl_space_copy(pnt->dim) : NULL; + return isl_space_copy(isl_point_peek_space(pnt)); } -__isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim, +__isl_give isl_point *isl_point_alloc(__isl_take isl_space *space, __isl_take isl_vec *vec) { struct isl_point *pnt; + isl_size dim; - if (!dim || !vec) + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0 || !vec) goto error; - if (vec->size > 1 + isl_space_dim(dim, isl_dim_all)) { + if (vec->size > 1 + dim) { vec = isl_vec_cow(vec); if (!vec) goto error; - vec->size = 1 + isl_space_dim(dim, isl_dim_all); + vec->size = 1 + dim; } - pnt = isl_alloc_type(dim->ctx, struct isl_point); + pnt = isl_alloc_type(space->ctx, struct isl_point); if (!pnt) goto error; pnt->ref = 1; - pnt->dim = dim; + pnt->dim = space; pnt->vec = vec; return pnt; error: - isl_space_free(dim); + isl_space_free(space); isl_vec_free(vec); return NULL; } -__isl_give isl_point *isl_point_zero(__isl_take isl_space *dim) +__isl_give isl_point *isl_point_zero(__isl_take isl_space *space) { isl_vec *vec; + isl_size dim; - if (!dim) - return NULL; - vec = isl_vec_alloc(dim->ctx, 1 + isl_space_dim(dim, isl_dim_all)); + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + goto error; + vec = isl_vec_alloc(space->ctx, 1 + dim); if (!vec) goto error; isl_int_set_si(vec->el[0], 1); isl_seq_clr(vec->el + 1, vec->size - 1); - return isl_point_alloc(dim, vec); + return isl_point_alloc(space, vec); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -116,22 +128,160 @@ return NULL; } -__isl_give isl_point *isl_point_void(__isl_take isl_space *dim) +__isl_give isl_point *isl_point_void(__isl_take isl_space *space) { - if (!dim) + if (!space) return NULL; - return isl_point_alloc(dim, isl_vec_alloc(dim->ctx, 0)); + return isl_point_alloc(space, isl_vec_alloc(space->ctx, 0)); } isl_bool isl_point_is_void(__isl_keep isl_point *pnt) { if (!pnt) return isl_bool_error; + + return isl_bool_ok(pnt->vec->size == 0); +} + +/* Return the space of "pnt". + * This may be either a copy or the space itself + * if there is only one reference to "pnt". + * This allows the space to be modified inplace + * if both the point and its space have only a single reference. + * The caller is not allowed to modify "pnt" between this call and + * a subsequent call to isl_point_restore_space. + * The only exception is that isl_point_free can be called instead. + */ +__isl_give isl_space *isl_point_take_space(__isl_keep isl_point *pnt) +{ + isl_space *space; + + if (!pnt) + return NULL; + if (pnt->ref != 1) + return isl_point_get_space(pnt); + space = pnt->dim; + pnt->dim = NULL; + return space; +} + +/* Set the space of "pnt" to "space", where the space of "pnt" may be missing + * due to a preceding call to isl_point_take_space. + * However, in this case, "pnt" only has a single reference and + * then the call to isl_point_cow has no effect. + */ +__isl_give isl_point *isl_point_restore_space(__isl_take isl_point *pnt, + __isl_take isl_space *space) +{ + if (!pnt || !space) + goto error; + + if (pnt->dim == space) { + isl_space_free(space); + return pnt; + } + + pnt = isl_point_cow(pnt); + if (!pnt) + goto error; + isl_space_free(pnt->dim); + pnt->dim = space; + + return pnt; +error: + isl_point_free(pnt); + isl_space_free(space); + return NULL; +} + +/* Return the coordinate vector of "pnt". + */ +__isl_keep isl_vec *isl_point_peek_vec(__isl_keep isl_point *pnt) +{ + return pnt ? pnt->vec : NULL; +} + +/* Return a copy of the coordinate vector of "pnt". + */ +__isl_give isl_vec *isl_point_get_vec(__isl_keep isl_point *pnt) +{ + return isl_vec_copy(isl_point_peek_vec(pnt)); +} + +/* Return the coordinate vector of "pnt". + * This may be either a copy or the coordinate vector itself + * if there is only one reference to "pnt". + * This allows the coordinate vector to be modified inplace + * if both the point and its coordinate vector have only a single reference. + * The caller is not allowed to modify "pnt" between this call and + * a subsequent call to isl_point_restore_vec. + * The only exception is that isl_point_free can be called instead. + */ +__isl_give isl_vec *isl_point_take_vec(__isl_keep isl_point *pnt) +{ + isl_vec *vec; + + if (!pnt) + return NULL; + if (pnt->ref != 1) + return isl_point_get_vec(pnt); + vec = pnt->vec; + pnt->vec = NULL; + return vec; +} + +/* Set the coordinate vector of "pnt" to "vec", + * where the coordinate vector of "pnt" may be missing + * due to a preceding call to isl_point_take_vec. + * However, in this case, "pnt" only has a single reference and + * then the call to isl_point_cow has no effect. + */ +__isl_give isl_point *isl_point_restore_vec(__isl_take isl_point *pnt, + __isl_take isl_vec *vec) +{ + if (!pnt || !vec) + goto error; + + if (pnt->vec == vec) { + isl_vec_free(vec); + return pnt; + } + + pnt = isl_point_cow(pnt); + if (!pnt) + goto error; + isl_vec_free(pnt->vec); + pnt->vec = vec; + + return pnt; +error: + isl_point_free(pnt); + isl_vec_free(vec); + return NULL; +} + +/* Return the number of variables of the given type. + */ +static isl_size isl_point_dim(__isl_keep isl_point *pnt, enum isl_dim_type type) +{ + return isl_space_dim(isl_point_peek_space(pnt), type); +} - return pnt->vec->size == 0; +/* Return the position of the coordinates of the given type + * within the sequence of coordinates of "pnt". + */ +static isl_size isl_point_var_offset(__isl_keep isl_point *pnt, + enum isl_dim_type type) +{ + return pnt ? isl_space_offset(pnt->dim, type) : isl_size_error; } +#undef TYPE +#define TYPE isl_point +static +#include "check_type_range_templ.c" + /* Return the value of coordinate "pos" of type "type" of "pnt". */ __isl_give isl_val *isl_point_get_coordinate_val(__isl_keep isl_point *pnt, @@ -139,6 +289,7 @@ { isl_ctx *ctx; isl_val *v; + isl_size off; if (!pnt) return NULL; @@ -147,12 +298,13 @@ if (isl_point_is_void(pnt)) isl_die(ctx, isl_error_invalid, "void point does not have coordinates", return NULL); - if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) - isl_die(ctx, isl_error_invalid, - "position out of bounds", return NULL); + if (isl_point_check_range(pnt, type, pos, 1) < 0) + return NULL; - if (type == isl_dim_set) - pos += isl_space_dim(pnt->dim, isl_dim_param); + off = isl_point_var_offset(pnt, type); + if (off < 0) + return NULL; + pos += off; v = isl_val_rat_from_isl_int(ctx, pnt->vec->el[1 + pos], pnt->vec->el[0]); @@ -169,13 +321,13 @@ if (isl_point_is_void(pnt)) isl_die(isl_point_get_ctx(pnt), isl_error_invalid, "void point does not have coordinates", goto error); - if (pos < 0 || pos >= isl_space_dim(pnt->dim, type)) - isl_die(isl_point_get_ctx(pnt), isl_error_invalid, - "position out of bounds", goto error); + if (isl_point_check_range(pnt, type, pos, 1) < 0) + goto error; if (!isl_val_is_rat(v)) isl_die(isl_point_get_ctx(pnt), isl_error_invalid, "expecting rational value", goto error); + pos += isl_space_offset(isl_point_peek_space(pnt), type); if (isl_int_eq(pnt->vec->el[1 + pos], v->n) && isl_int_eq(pnt->vec->el[0], v->d)) { isl_val_free(v); @@ -214,6 +366,8 @@ __isl_give isl_point *isl_point_add_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val) { + isl_size off; + if (!pnt || isl_point_is_void(pnt)) return pnt; @@ -224,8 +378,10 @@ if (!pnt->vec) goto error; - if (type == isl_dim_set) - pos += isl_space_dim(pnt->dim, isl_dim_param); + off = isl_point_var_offset(pnt, type); + if (off < 0) + goto error; + pos += off; isl_int_add_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val); @@ -238,6 +394,8 @@ __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val) { + isl_size off; + if (!pnt || isl_point_is_void(pnt)) return pnt; @@ -248,8 +406,10 @@ if (!pnt->vec) goto error; - if (type == isl_dim_set) - pos += isl_space_dim(pnt->dim, isl_dim_param); + off = isl_point_var_offset(pnt, type); + if (off < 0) + goto error; + pos += off; isl_int_sub_ui(pnt->vec->el[1 + pos], pnt->vec->el[1 + pos], val); @@ -320,9 +480,8 @@ isl_bool isl_basic_map_contains_point(__isl_keep isl_basic_map *bmap, __isl_keep isl_point *point) { - int i; - struct isl_vec *vec; - unsigned dim; + isl_local *local; + isl_vec *vec; isl_bool contains; if (!bmap || !point) @@ -331,19 +490,11 @@ return isl_bool_error); if (bmap->n_div == 0) return isl_basic_map_contains(bmap, point->vec); - - dim = isl_basic_map_total_dim(bmap) - bmap->n_div; - vec = isl_vec_alloc(bmap->ctx, 1 + dim + bmap->n_div); - if (!vec) - return isl_bool_error; - isl_seq_cpy(vec->el, point->vec->el, point->vec->size); - for (i = 0; i < bmap->n_div; ++i) { - isl_seq_inner_product(bmap->div[i] + 1, vec->el, - 1 + dim + i, &vec->el[1+dim+i]); - isl_int_fdiv_q(vec->el[1+dim+i], vec->el[1+dim+i], - bmap->div[i][0]); - } + local = isl_local_alloc_from_mat(isl_basic_map_get_divs(bmap)); + vec = isl_point_get_vec(point); + vec = isl_local_extend_point_vec(local, vec); + isl_local_free(local); contains = isl_basic_map_contains(bmap, vec); @@ -431,7 +582,7 @@ __isl_take isl_point *pnt1, __isl_take isl_point *pnt2) { isl_basic_set *bset = NULL; - unsigned total; + isl_size total; int i; int k; isl_int t; @@ -462,7 +613,9 @@ return isl_basic_set_from_point(pnt1); } - total = isl_space_dim(pnt1->dim, isl_dim_all); + total = isl_point_dim(pnt1, isl_dim_all); + if (total < 0) + goto error; bset = isl_basic_set_alloc_space(isl_space_copy(pnt1->dim), 0, 0, 2 * total); for (i = 0; i < total; ++i) { @@ -527,6 +680,7 @@ { isl_point *pnt = data->user; + pos += isl_space_offset(data->space, data->type); p = isl_printer_print_isl_int(p, pnt->vec->el[1 + pos]); if (!isl_int_is_one(pnt->vec->el[0])) { p = isl_printer_print_str(p, "/"); @@ -541,7 +695,7 @@ { struct isl_print_space_data data = { 0 }; int i; - unsigned nparam; + isl_size nparam; if (!pnt) return p; @@ -550,7 +704,9 @@ return p; } - nparam = isl_space_dim(pnt->dim, isl_dim_param); + nparam = isl_point_dim(pnt, isl_dim_param); + if (nparam < 0) + return isl_printer_free(p); if (nparam > 0) { p = isl_printer_print_str(p, "["); for (i = 0; i < nparam; ++i) { diff --git a/gcc/isl/isl_point_private.h b/gcc/isl/isl_point_private.h index 305b81e..a1e8449 100644 --- a/gcc/isl/isl_point_private.h +++ a/gcc/isl/isl_point_private.h @@ -1,3 +1,6 @@ +#ifndef ISL_POINT_PRIVATE_H +#define ISL_POINT_PRIVATE_H + #include #include #include @@ -7,6 +10,18 @@ isl_space *dim; struct isl_vec *vec; }; + +__isl_give isl_point *isl_point_alloc(__isl_take isl_space *space, + __isl_take isl_vec *vec); -__isl_give isl_point *isl_point_alloc(__isl_take isl_space *dim, +__isl_keep isl_space *isl_point_peek_space(__isl_keep isl_point *pnt); +__isl_give isl_space *isl_point_take_space(__isl_keep isl_point *pnt); +__isl_give isl_point *isl_point_restore_space(__isl_take isl_point *pnt, + __isl_take isl_space *space); +__isl_keep isl_vec *isl_point_peek_vec(__isl_keep isl_point *pnt); +__isl_give isl_vec *isl_point_get_vec(__isl_keep isl_point *pnt); +__isl_give isl_vec *isl_point_take_vec(__isl_keep isl_point *pnt); +__isl_give isl_point *isl_point_restore_vec(__isl_take isl_point *pnt, __isl_take isl_vec *vec); + +#endif diff --git a/gcc/isl/isl_polynomial.c b/gcc/isl/isl_polynomial.c index c7c0f62..57e9ae2 100644 --- a/gcc/isl/isl_polynomial.c +++ a/gcc/isl/isl_polynomial.c @@ -9,7 +9,6 @@ */ #include -#define ISL_DIM_H #include #include #include @@ -29,6 +28,11 @@ #include #include +#undef EL_BASE +#define EL_BASE pw_qpolynomial + +#include + static unsigned pos(__isl_keep isl_space *dim, enum isl_dim_type type) { switch (type) { @@ -39,60 +43,62 @@ } } -int isl_upoly_is_cst(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_cst(__isl_keep isl_poly *poly) { - if (!up) - return -1; + if (!poly) + return isl_bool_error; - return up->var < 0; + return isl_bool_ok(poly->var < 0); } -__isl_keep struct isl_upoly_cst *isl_upoly_as_cst(__isl_keep struct isl_upoly *up) +__isl_keep isl_poly_cst *isl_poly_as_cst(__isl_keep isl_poly *poly) { - if (!up) + if (!poly) return NULL; - isl_assert(up->ctx, up->var < 0, return NULL); + isl_assert(poly->ctx, poly->var < 0, return NULL); - return (struct isl_upoly_cst *)up; + return (isl_poly_cst *) poly; } -__isl_keep struct isl_upoly_rec *isl_upoly_as_rec(__isl_keep struct isl_upoly *up) +__isl_keep isl_poly_rec *isl_poly_as_rec(__isl_keep isl_poly *poly) { - if (!up) + if (!poly) return NULL; - isl_assert(up->ctx, up->var >= 0, return NULL); + isl_assert(poly->ctx, poly->var >= 0, return NULL); - return (struct isl_upoly_rec *)up; + return (isl_poly_rec *) poly; } /* Compare two polynomials. * - * Return -1 if "up1" is "smaller" than "up2", 1 if "up1" is "greater" - * than "up2" and 0 if they are equal. + * Return -1 if "poly1" is "smaller" than "poly2", 1 if "poly1" is "greater" + * than "poly2" and 0 if they are equal. */ -static int isl_upoly_plain_cmp(__isl_keep struct isl_upoly *up1, - __isl_keep struct isl_upoly *up2) +static int isl_poly_plain_cmp(__isl_keep isl_poly *poly1, + __isl_keep isl_poly *poly2) { int i; - struct isl_upoly_rec *rec1, *rec2; + isl_bool is_cst1; + isl_poly_rec *rec1, *rec2; - if (up1 == up2) + if (poly1 == poly2) return 0; - if (!up1) + is_cst1 = isl_poly_is_cst(poly1); + if (is_cst1 < 0) return -1; - if (!up2) + if (!poly2) return 1; - if (up1->var != up2->var) - return up1->var - up2->var; - - if (isl_upoly_is_cst(up1)) { - struct isl_upoly_cst *cst1, *cst2; + if (poly1->var != poly2->var) + return poly1->var - poly2->var; + + if (is_cst1) { + isl_poly_cst *cst1, *cst2; int cmp; - cst1 = isl_upoly_as_cst(up1); - cst2 = isl_upoly_as_cst(up2); + cst1 = isl_poly_as_cst(poly1); + cst2 = isl_poly_as_cst(poly2); if (!cst1 || !cst2) return 0; cmp = isl_int_cmp(cst1->n, cst2->n); @@ -101,8 +107,8 @@ return isl_int_cmp(cst1->d, cst2->d); } - rec1 = isl_upoly_as_rec(up1); - rec2 = isl_upoly_as_rec(up2); + rec1 = isl_poly_as_rec(poly1); + rec2 = isl_poly_as_rec(poly2); if (!rec1 || !rec2) return 0; @@ -110,7 +116,7 @@ return rec1->n - rec2->n; for (i = 0; i < rec1->n; ++i) { - int cmp = isl_upoly_plain_cmp(rec1->p[i], rec2->p[i]); + int cmp = isl_poly_plain_cmp(rec1->p[i], rec2->p[i]); if (cmp != 0) return cmp; } @@ -118,30 +124,34 @@ return 0; } -isl_bool isl_upoly_is_equal(__isl_keep struct isl_upoly *up1, - __isl_keep struct isl_upoly *up2) +isl_bool isl_poly_is_equal(__isl_keep isl_poly *poly1, + __isl_keep isl_poly *poly2) { int i; - struct isl_upoly_rec *rec1, *rec2; - - if (!up1 || !up2) + isl_bool is_cst1; + isl_poly_rec *rec1, *rec2; + + is_cst1 = isl_poly_is_cst(poly1); + if (is_cst1 < 0 || !poly2) return isl_bool_error; - if (up1 == up2) + if (poly1 == poly2) return isl_bool_true; - if (up1->var != up2->var) + if (poly1->var != poly2->var) return isl_bool_false; - if (isl_upoly_is_cst(up1)) { - struct isl_upoly_cst *cst1, *cst2; - cst1 = isl_upoly_as_cst(up1); - cst2 = isl_upoly_as_cst(up2); + if (is_cst1) { + isl_poly_cst *cst1, *cst2; + int r; + cst1 = isl_poly_as_cst(poly1); + cst2 = isl_poly_as_cst(poly2); if (!cst1 || !cst2) return isl_bool_error; - return isl_int_eq(cst1->n, cst2->n) && - isl_int_eq(cst1->d, cst2->d); + r = isl_int_eq(cst1->n, cst2->n) && + isl_int_eq(cst1->d, cst2->d); + return isl_bool_ok(r); } - rec1 = isl_upoly_as_rec(up1); - rec2 = isl_upoly_as_rec(up2); + rec1 = isl_poly_as_rec(poly1); + rec2 = isl_poly_as_rec(poly2); if (!rec1 || !rec2) return isl_bool_error; @@ -149,7 +159,7 @@ return isl_bool_false; for (i = 0; i < rec1->n; ++i) { - isl_bool eq = isl_upoly_is_equal(rec1->p[i], rec2->p[i]); + isl_bool eq = isl_poly_is_equal(rec1->p[i], rec2->p[i]); if (eq < 0 || !eq) return eq; } @@ -157,130 +167,132 @@ return isl_bool_true; } -int isl_upoly_is_zero(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_zero(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_is_zero(cst->n) && isl_int_is_pos(cst->d); + return isl_bool_ok(isl_int_is_zero(cst->n) && isl_int_is_pos(cst->d)); } -int isl_upoly_sgn(__isl_keep struct isl_upoly *up) +int isl_poly_sgn(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return 0; - if (!isl_upoly_is_cst(up)) + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) return 0; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) return 0; return isl_int_sgn(cst->n); } -int isl_upoly_is_nan(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_nan(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_is_zero(cst->n) && isl_int_is_zero(cst->d); + return isl_bool_ok(isl_int_is_zero(cst->n) && isl_int_is_zero(cst->d)); } -int isl_upoly_is_infty(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_infty(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_is_pos(cst->n) && isl_int_is_zero(cst->d); + return isl_bool_ok(isl_int_is_pos(cst->n) && isl_int_is_zero(cst->d)); } -int isl_upoly_is_neginfty(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_neginfty(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_is_neg(cst->n) && isl_int_is_zero(cst->d); + return isl_bool_ok(isl_int_is_neg(cst->n) && isl_int_is_zero(cst->d)); } -int isl_upoly_is_one(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_one(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; + int r; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_eq(cst->n, cst->d) && isl_int_is_pos(cst->d); + r = isl_int_eq(cst->n, cst->d) && isl_int_is_pos(cst->d); + return isl_bool_ok(r); } -int isl_upoly_is_negone(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_negone(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) - return -1; - if (!isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) - return -1; + return isl_bool_error; - return isl_int_is_negone(cst->n) && isl_int_is_one(cst->d); + return isl_bool_ok(isl_int_is_negone(cst->n) && isl_int_is_one(cst->d)); } -__isl_give struct isl_upoly_cst *isl_upoly_cst_alloc(struct isl_ctx *ctx) +__isl_give isl_poly_cst *isl_poly_cst_alloc(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_alloc_type(ctx, struct isl_upoly_cst); + cst = isl_alloc_type(ctx, struct isl_poly_cst); if (!cst) return NULL; - cst->up.ref = 1; - cst->up.ctx = ctx; + cst->poly.ref = 1; + cst->poly.ctx = ctx; isl_ctx_ref(ctx); - cst->up.var = -1; + cst->poly.var = -1; isl_int_init(cst->n); isl_int_init(cst->d); @@ -288,108 +300,106 @@ return cst; } -__isl_give struct isl_upoly *isl_upoly_zero(struct isl_ctx *ctx) +__isl_give isl_poly *isl_poly_zero(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set_si(cst->n, 0); isl_int_set_si(cst->d, 1); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly *isl_upoly_one(struct isl_ctx *ctx) +__isl_give isl_poly *isl_poly_one(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set_si(cst->n, 1); isl_int_set_si(cst->d, 1); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly *isl_upoly_infty(struct isl_ctx *ctx) +__isl_give isl_poly *isl_poly_infty(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set_si(cst->n, 1); isl_int_set_si(cst->d, 0); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly *isl_upoly_neginfty(struct isl_ctx *ctx) +__isl_give isl_poly *isl_poly_neginfty(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set_si(cst->n, -1); isl_int_set_si(cst->d, 0); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly *isl_upoly_nan(struct isl_ctx *ctx) +__isl_give isl_poly *isl_poly_nan(isl_ctx *ctx) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set_si(cst->n, 0); isl_int_set_si(cst->d, 0); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly *isl_upoly_rat_cst(struct isl_ctx *ctx, - isl_int n, isl_int d) +__isl_give isl_poly *isl_poly_rat_cst(isl_ctx *ctx, isl_int n, isl_int d) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - cst = isl_upoly_cst_alloc(ctx); + cst = isl_poly_cst_alloc(ctx); if (!cst) return NULL; isl_int_set(cst->n, n); isl_int_set(cst->d, d); - return &cst->up; + return &cst->poly; } -__isl_give struct isl_upoly_rec *isl_upoly_alloc_rec(struct isl_ctx *ctx, - int var, int size) +__isl_give isl_poly_rec *isl_poly_alloc_rec(isl_ctx *ctx, int var, int size) { - struct isl_upoly_rec *rec; + isl_poly_rec *rec; isl_assert(ctx, var >= 0, return NULL); isl_assert(ctx, size >= 0, return NULL); - rec = isl_calloc(ctx, struct isl_upoly_rec, - sizeof(struct isl_upoly_rec) + - size * sizeof(struct isl_upoly *)); + rec = isl_calloc(ctx, struct isl_poly_rec, + sizeof(struct isl_poly_rec) + + size * sizeof(struct isl_poly *)); if (!rec) return NULL; - rec->up.ref = 1; - rec->up.ctx = ctx; + rec->poly.ref = 1; + rec->poly.ctx = ctx; isl_ctx_ref(ctx); - rec->up.var = var; + rec->poly.var = var; rec->n = 0; rec->size = size; @@ -429,14 +439,38 @@ isl_ctx *isl_qpolynomial_get_ctx(__isl_keep isl_qpolynomial *qp) { return qp ? qp->dim->ctx : NULL; +} + +/* Return the domain space of "qp". + */ +static __isl_keep isl_space *isl_qpolynomial_peek_domain_space( + __isl_keep isl_qpolynomial *qp) +{ + return qp ? qp->dim : NULL; } +/* Return a copy of the domain space of "qp". + */ __isl_give isl_space *isl_qpolynomial_get_domain_space( __isl_keep isl_qpolynomial *qp) { - return qp ? isl_space_copy(qp->dim) : NULL; + return isl_space_copy(isl_qpolynomial_peek_domain_space(qp)); } +/* Return a copy of the local space on which "qp" is defined. + */ +static __isl_give isl_local_space *isl_qpolynomial_get_domain_local_space( + __isl_keep isl_qpolynomial *qp) +{ + isl_space *space; + + if (!qp) + return NULL; + + space = isl_qpolynomial_get_domain_space(qp); + return isl_local_space_alloc_div(space, isl_mat_copy(qp->div)); +} + __isl_give isl_space *isl_qpolynomial_get_space(__isl_keep isl_qpolynomial *qp) { isl_space *space; @@ -450,32 +484,77 @@ /* Return the number of variables of the given type in the domain of "qp". */ -unsigned isl_qpolynomial_domain_dim(__isl_keep isl_qpolynomial *qp, +isl_size isl_qpolynomial_domain_dim(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type) { - if (!qp) - return 0; + isl_space *space; + isl_size dim; + + space = isl_qpolynomial_peek_domain_space(qp); + + if (!space) + return isl_size_error; if (type == isl_dim_div) return qp->div->n_row; - if (type == isl_dim_all) - return isl_space_dim(qp->dim, isl_dim_all) + - isl_qpolynomial_domain_dim(qp, isl_dim_div); - return isl_space_dim(qp->dim, type); + dim = isl_space_dim(space, type); + if (dim < 0) + return isl_size_error; + if (type == isl_dim_all) { + isl_size n_div; + + n_div = isl_qpolynomial_domain_dim(qp, isl_dim_div); + if (n_div < 0) + return isl_size_error; + dim += n_div; + } + return dim; +} + +/* Given the type of a dimension of an isl_qpolynomial, + * return the type of the corresponding dimension in its domain. + * This function is only called for "type" equal to isl_dim_in or + * isl_dim_param. + */ +static enum isl_dim_type domain_type(enum isl_dim_type type) +{ + return type == isl_dim_in ? isl_dim_set : type; } /* Externally, an isl_qpolynomial has a map space, but internally, the * ls field corresponds to the domain of that space. */ -unsigned isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp, +isl_size isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type) { if (!qp) - return 0; + return isl_size_error; if (type == isl_dim_out) return 1; - if (type == isl_dim_in) - type = isl_dim_set; + type = domain_type(type); return isl_qpolynomial_domain_dim(qp, type); +} + +/* Return the offset of the first variable of type "type" within + * the variables of the domain of "qp". + */ +static isl_size isl_qpolynomial_domain_var_offset( + __isl_keep isl_qpolynomial *qp, enum isl_dim_type type) +{ + isl_space *space; + + space = isl_qpolynomial_peek_domain_space(qp); + if (!space) + return isl_size_error; + + switch (type) { + case isl_dim_param: + case isl_dim_set: return isl_space_offset(space, type); + case isl_dim_div: return isl_space_dim(space, isl_dim_all); + case isl_dim_cst: + default: + isl_die(isl_qpolynomial_get_ctx(qp), isl_error_invalid, + "invalid dimension type", return isl_size_error); + } } /* Return the offset of the first coefficient of type "type" in @@ -484,16 +563,13 @@ unsigned isl_qpolynomial_domain_offset(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type) { - if (!qp) - return 0; switch (type) { case isl_dim_cst: return 0; case isl_dim_param: case isl_dim_set: - return 1 + isl_space_offset(qp->dim, type); case isl_dim_div: - return 1 + isl_space_dim(qp->dim, isl_dim_all); + return 1 + isl_qpolynomial_domain_var_offset(qp, type); default: return 0; } @@ -501,143 +577,145 @@ isl_bool isl_qpolynomial_is_zero(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_is_zero(qp->upoly) : isl_bool_error; + return qp ? isl_poly_is_zero(qp->poly) : isl_bool_error; } isl_bool isl_qpolynomial_is_one(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_is_one(qp->upoly) : isl_bool_error; + return qp ? isl_poly_is_one(qp->poly) : isl_bool_error; } isl_bool isl_qpolynomial_is_nan(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_is_nan(qp->upoly) : isl_bool_error; + return qp ? isl_poly_is_nan(qp->poly) : isl_bool_error; } isl_bool isl_qpolynomial_is_infty(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_is_infty(qp->upoly) : isl_bool_error; + return qp ? isl_poly_is_infty(qp->poly) : isl_bool_error; } isl_bool isl_qpolynomial_is_neginfty(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_is_neginfty(qp->upoly) : isl_bool_error; + return qp ? isl_poly_is_neginfty(qp->poly) : isl_bool_error; } int isl_qpolynomial_sgn(__isl_keep isl_qpolynomial *qp) { - return qp ? isl_upoly_sgn(qp->upoly) : 0; + return qp ? isl_poly_sgn(qp->poly) : 0; } -static void upoly_free_cst(__isl_take struct isl_upoly_cst *cst) +static void poly_free_cst(__isl_take isl_poly_cst *cst) { isl_int_clear(cst->n); isl_int_clear(cst->d); } -static void upoly_free_rec(__isl_take struct isl_upoly_rec *rec) +static void poly_free_rec(__isl_take isl_poly_rec *rec) { int i; for (i = 0; i < rec->n; ++i) - isl_upoly_free(rec->p[i]); + isl_poly_free(rec->p[i]); } -__isl_give struct isl_upoly *isl_upoly_copy(__isl_keep struct isl_upoly *up) +__isl_give isl_poly *isl_poly_copy(__isl_keep isl_poly *poly) { - if (!up) + if (!poly) return NULL; - up->ref++; - return up; + poly->ref++; + return poly; } -__isl_give struct isl_upoly *isl_upoly_dup_cst(__isl_keep struct isl_upoly *up) +__isl_give isl_poly *isl_poly_dup_cst(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; - struct isl_upoly_cst *dup; + isl_poly_cst *cst; + isl_poly_cst *dup; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) return NULL; - dup = isl_upoly_as_cst(isl_upoly_zero(up->ctx)); + dup = isl_poly_as_cst(isl_poly_zero(poly->ctx)); if (!dup) return NULL; isl_int_set(dup->n, cst->n); isl_int_set(dup->d, cst->d); - return &dup->up; + return &dup->poly; } -__isl_give struct isl_upoly *isl_upoly_dup_rec(__isl_keep struct isl_upoly *up) +__isl_give isl_poly *isl_poly_dup_rec(__isl_keep isl_poly *poly) { int i; - struct isl_upoly_rec *rec; - struct isl_upoly_rec *dup; + isl_poly_rec *rec; + isl_poly_rec *dup; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) return NULL; - dup = isl_upoly_alloc_rec(up->ctx, up->var, rec->n); + dup = isl_poly_alloc_rec(poly->ctx, poly->var, rec->n); if (!dup) return NULL; for (i = 0; i < rec->n; ++i) { - dup->p[i] = isl_upoly_copy(rec->p[i]); + dup->p[i] = isl_poly_copy(rec->p[i]); if (!dup->p[i]) goto error; dup->n++; } - return &dup->up; + return &dup->poly; error: - isl_upoly_free(&dup->up); + isl_poly_free(&dup->poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_dup(__isl_keep struct isl_upoly *up) +__isl_give isl_poly *isl_poly_dup(__isl_keep isl_poly *poly) { - if (!up) - return NULL; + isl_bool is_cst; - if (isl_upoly_is_cst(up)) - return isl_upoly_dup_cst(up); + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return NULL; + if (is_cst) + return isl_poly_dup_cst(poly); else - return isl_upoly_dup_rec(up); + return isl_poly_dup_rec(poly); } -__isl_give struct isl_upoly *isl_upoly_cow(__isl_take struct isl_upoly *up) +__isl_give isl_poly *isl_poly_cow(__isl_take isl_poly *poly) { - if (!up) + if (!poly) return NULL; - if (up->ref == 1) - return up; - up->ref--; - return isl_upoly_dup(up); + if (poly->ref == 1) + return poly; + poly->ref--; + return isl_poly_dup(poly); } -__isl_null struct isl_upoly *isl_upoly_free(__isl_take struct isl_upoly *up) +__isl_null isl_poly *isl_poly_free(__isl_take isl_poly *poly) { - if (!up) + if (!poly) return NULL; - if (--up->ref > 0) + if (--poly->ref > 0) return NULL; - if (up->var < 0) - upoly_free_cst((struct isl_upoly_cst *)up); + if (poly->var < 0) + poly_free_cst((isl_poly_cst *) poly); else - upoly_free_rec((struct isl_upoly_rec *)up); + poly_free_rec((isl_poly_rec *) poly); - isl_ctx_deref(up->ctx); - free(up); + isl_ctx_deref(poly->ctx); + free(poly); return NULL; } -static void isl_upoly_cst_reduce(__isl_keep struct isl_upoly_cst *cst) +static void isl_poly_cst_reduce(__isl_keep isl_poly_cst *cst) { isl_int gcd; @@ -650,18 +728,18 @@ isl_int_clear(gcd); } -__isl_give struct isl_upoly *isl_upoly_sum_cst(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2) +__isl_give isl_poly *isl_poly_sum_cst(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2) { - struct isl_upoly_cst *cst1; - struct isl_upoly_cst *cst2; + isl_poly_cst *cst1; + isl_poly_cst *cst2; - up1 = isl_upoly_cow(up1); - if (!up1 || !up2) + poly1 = isl_poly_cow(poly1); + if (!poly1 || !poly2) goto error; - cst1 = isl_upoly_as_cst(up1); - cst2 = isl_upoly_as_cst(up2); + cst1 = isl_poly_as_cst(poly1); + cst2 = isl_poly_as_cst(poly2); if (isl_int_eq(cst1->d, cst2->d)) isl_int_add(cst1->n, cst1->n, cst2->n); @@ -671,489 +749,554 @@ isl_int_mul(cst1->d, cst1->d, cst2->d); } - isl_upoly_cst_reduce(cst1); + isl_poly_cst_reduce(cst1); - isl_upoly_free(up2); - return up1; + isl_poly_free(poly2); + return poly1; error: - isl_upoly_free(up1); - isl_upoly_free(up2); + isl_poly_free(poly1); + isl_poly_free(poly2); return NULL; } -static __isl_give struct isl_upoly *replace_by_zero( - __isl_take struct isl_upoly *up) +static __isl_give isl_poly *replace_by_zero(__isl_take isl_poly *poly) { struct isl_ctx *ctx; - if (!up) + if (!poly) return NULL; - ctx = up->ctx; - isl_upoly_free(up); - return isl_upoly_zero(ctx); + ctx = poly->ctx; + isl_poly_free(poly); + return isl_poly_zero(ctx); } -static __isl_give struct isl_upoly *replace_by_constant_term( - __isl_take struct isl_upoly *up) +static __isl_give isl_poly *replace_by_constant_term(__isl_take isl_poly *poly) { - struct isl_upoly_rec *rec; - struct isl_upoly *cst; + isl_poly_rec *rec; + isl_poly *cst; - if (!up) + if (!poly) return NULL; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) goto error; - cst = isl_upoly_copy(rec->p[0]); - isl_upoly_free(up); + cst = isl_poly_copy(rec->p[0]); + isl_poly_free(poly); return cst; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_sum(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2) +__isl_give isl_poly *isl_poly_sum(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2) { int i; - struct isl_upoly_rec *rec1, *rec2; + isl_bool is_zero, is_nan, is_cst; + isl_poly_rec *rec1, *rec2; - if (!up1 || !up2) + if (!poly1 || !poly2) goto error; - if (isl_upoly_is_nan(up1)) { - isl_upoly_free(up2); - return up1; + is_nan = isl_poly_is_nan(poly1); + if (is_nan < 0) + goto error; + if (is_nan) { + isl_poly_free(poly2); + return poly1; } - if (isl_upoly_is_nan(up2)) { - isl_upoly_free(up1); - return up2; + is_nan = isl_poly_is_nan(poly2); + if (is_nan < 0) + goto error; + if (is_nan) { + isl_poly_free(poly1); + return poly2; } - if (isl_upoly_is_zero(up1)) { - isl_upoly_free(up1); - return up2; + is_zero = isl_poly_is_zero(poly1); + if (is_zero < 0) + goto error; + if (is_zero) { + isl_poly_free(poly1); + return poly2; } - if (isl_upoly_is_zero(up2)) { - isl_upoly_free(up2); - return up1; + is_zero = isl_poly_is_zero(poly2); + if (is_zero < 0) + goto error; + if (is_zero) { + isl_poly_free(poly2); + return poly1; } + + if (poly1->var < poly2->var) + return isl_poly_sum(poly2, poly1); - if (up1->var < up2->var) - return isl_upoly_sum(up2, up1); + if (poly2->var < poly1->var) { + isl_poly_rec *rec; + isl_bool is_infty; - if (up2->var < up1->var) { - struct isl_upoly_rec *rec; - if (isl_upoly_is_infty(up2) || isl_upoly_is_neginfty(up2)) { - isl_upoly_free(up1); - return up2; + is_infty = isl_poly_is_infty(poly2); + if (is_infty >= 0 && !is_infty) + is_infty = isl_poly_is_neginfty(poly2); + if (is_infty < 0) + goto error; + if (is_infty) { + isl_poly_free(poly1); + return poly2; } - up1 = isl_upoly_cow(up1); - rec = isl_upoly_as_rec(up1); + poly1 = isl_poly_cow(poly1); + rec = isl_poly_as_rec(poly1); if (!rec) goto error; - rec->p[0] = isl_upoly_sum(rec->p[0], up2); + rec->p[0] = isl_poly_sum(rec->p[0], poly2); if (rec->n == 1) - up1 = replace_by_constant_term(up1); - return up1; + poly1 = replace_by_constant_term(poly1); + return poly1; } - if (isl_upoly_is_cst(up1)) - return isl_upoly_sum_cst(up1, up2); + is_cst = isl_poly_is_cst(poly1); + if (is_cst < 0) + goto error; + if (is_cst) + return isl_poly_sum_cst(poly1, poly2); - rec1 = isl_upoly_as_rec(up1); - rec2 = isl_upoly_as_rec(up2); + rec1 = isl_poly_as_rec(poly1); + rec2 = isl_poly_as_rec(poly2); if (!rec1 || !rec2) goto error; if (rec1->n < rec2->n) - return isl_upoly_sum(up2, up1); + return isl_poly_sum(poly2, poly1); - up1 = isl_upoly_cow(up1); - rec1 = isl_upoly_as_rec(up1); + poly1 = isl_poly_cow(poly1); + rec1 = isl_poly_as_rec(poly1); if (!rec1) goto error; for (i = rec2->n - 1; i >= 0; --i) { - rec1->p[i] = isl_upoly_sum(rec1->p[i], - isl_upoly_copy(rec2->p[i])); + isl_bool is_zero; + + rec1->p[i] = isl_poly_sum(rec1->p[i], + isl_poly_copy(rec2->p[i])); if (!rec1->p[i]) goto error; - if (i == rec1->n - 1 && isl_upoly_is_zero(rec1->p[i])) { - isl_upoly_free(rec1->p[i]); + if (i != rec1->n - 1) + continue; + is_zero = isl_poly_is_zero(rec1->p[i]); + if (is_zero < 0) + goto error; + if (is_zero) { + isl_poly_free(rec1->p[i]); rec1->n--; } } if (rec1->n == 0) - up1 = replace_by_zero(up1); + poly1 = replace_by_zero(poly1); else if (rec1->n == 1) - up1 = replace_by_constant_term(up1); + poly1 = replace_by_constant_term(poly1); - isl_upoly_free(up2); + isl_poly_free(poly2); - return up1; + return poly1; error: - isl_upoly_free(up1); - isl_upoly_free(up2); + isl_poly_free(poly1); + isl_poly_free(poly2); return NULL; } -__isl_give struct isl_upoly *isl_upoly_cst_add_isl_int( - __isl_take struct isl_upoly *up, isl_int v) +__isl_give isl_poly *isl_poly_cst_add_isl_int(__isl_take isl_poly *poly, + isl_int v) { - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - up = isl_upoly_cow(up); - if (!up) + poly = isl_poly_cow(poly); + if (!poly) return NULL; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); isl_int_addmul(cst->n, cst->d, v); - return up; + return poly; } -__isl_give struct isl_upoly *isl_upoly_add_isl_int( - __isl_take struct isl_upoly *up, isl_int v) +__isl_give isl_poly *isl_poly_add_isl_int(__isl_take isl_poly *poly, isl_int v) { - struct isl_upoly_rec *rec; - - if (!up) - return NULL; + isl_bool is_cst; + isl_poly_rec *rec; - if (isl_upoly_is_cst(up)) - return isl_upoly_cst_add_isl_int(up, v); - - up = isl_upoly_cow(up); - rec = isl_upoly_as_rec(up); + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return isl_poly_cst_add_isl_int(poly, v); + + poly = isl_poly_cow(poly); + rec = isl_poly_as_rec(poly); if (!rec) goto error; - rec->p[0] = isl_upoly_add_isl_int(rec->p[0], v); + rec->p[0] = isl_poly_add_isl_int(rec->p[0], v); if (!rec->p[0]) goto error; - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_cst_mul_isl_int( - __isl_take struct isl_upoly *up, isl_int v) +__isl_give isl_poly *isl_poly_cst_mul_isl_int(__isl_take isl_poly *poly, + isl_int v) { - struct isl_upoly_cst *cst; + isl_bool is_zero; + isl_poly_cst *cst; - if (isl_upoly_is_zero(up)) - return up; + is_zero = isl_poly_is_zero(poly); + if (is_zero < 0) + return isl_poly_free(poly); + if (is_zero) + return poly; - up = isl_upoly_cow(up); - if (!up) + poly = isl_poly_cow(poly); + if (!poly) return NULL; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); isl_int_mul(cst->n, cst->n, v); - return up; + return poly; } -__isl_give struct isl_upoly *isl_upoly_mul_isl_int( - __isl_take struct isl_upoly *up, isl_int v) +__isl_give isl_poly *isl_poly_mul_isl_int(__isl_take isl_poly *poly, isl_int v) { int i; - struct isl_upoly_rec *rec; - - if (!up) - return NULL; + isl_bool is_cst; + isl_poly_rec *rec; - if (isl_upoly_is_cst(up)) - return isl_upoly_cst_mul_isl_int(up, v); - - up = isl_upoly_cow(up); - rec = isl_upoly_as_rec(up); + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return isl_poly_cst_mul_isl_int(poly, v); + + poly = isl_poly_cow(poly); + rec = isl_poly_as_rec(poly); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - rec->p[i] = isl_upoly_mul_isl_int(rec->p[i], v); + rec->p[i] = isl_poly_mul_isl_int(rec->p[i], v); if (!rec->p[i]) goto error; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } -/* Multiply the constant polynomial "up" by "v". +/* Multiply the constant polynomial "poly" by "v". */ -static __isl_give struct isl_upoly *isl_upoly_cst_scale_val( - __isl_take struct isl_upoly *up, __isl_keep isl_val *v) -{ - struct isl_upoly_cst *cst; - - if (isl_upoly_is_zero(up)) - return up; - - up = isl_upoly_cow(up); - if (!up) +static __isl_give isl_poly *isl_poly_cst_scale_val(__isl_take isl_poly *poly, + __isl_keep isl_val *v) +{ + isl_bool is_zero; + isl_poly_cst *cst; + + is_zero = isl_poly_is_zero(poly); + if (is_zero < 0) + return isl_poly_free(poly); + if (is_zero) + return poly; + + poly = isl_poly_cow(poly); + if (!poly) return NULL; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); isl_int_mul(cst->n, cst->n, v->n); isl_int_mul(cst->d, cst->d, v->d); - isl_upoly_cst_reduce(cst); + isl_poly_cst_reduce(cst); - return up; + return poly; } -/* Multiply the polynomial "up" by "v". +/* Multiply the polynomial "poly" by "v". */ -static __isl_give struct isl_upoly *isl_upoly_scale_val( - __isl_take struct isl_upoly *up, __isl_keep isl_val *v) +static __isl_give isl_poly *isl_poly_scale_val(__isl_take isl_poly *poly, + __isl_keep isl_val *v) { int i; - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; - if (!up) - return NULL; - - if (isl_upoly_is_cst(up)) - return isl_upoly_cst_scale_val(up, v); - - up = isl_upoly_cow(up); - rec = isl_upoly_as_rec(up); + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return isl_poly_cst_scale_val(poly, v); + + poly = isl_poly_cow(poly); + rec = isl_poly_as_rec(poly); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - rec->p[i] = isl_upoly_scale_val(rec->p[i], v); + rec->p[i] = isl_poly_scale_val(rec->p[i], v); if (!rec->p[i]) goto error; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_mul_cst(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2) +__isl_give isl_poly *isl_poly_mul_cst(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2) { - struct isl_upoly_cst *cst1; - struct isl_upoly_cst *cst2; + isl_poly_cst *cst1; + isl_poly_cst *cst2; - up1 = isl_upoly_cow(up1); - if (!up1 || !up2) + poly1 = isl_poly_cow(poly1); + if (!poly1 || !poly2) goto error; - cst1 = isl_upoly_as_cst(up1); - cst2 = isl_upoly_as_cst(up2); + cst1 = isl_poly_as_cst(poly1); + cst2 = isl_poly_as_cst(poly2); isl_int_mul(cst1->n, cst1->n, cst2->n); isl_int_mul(cst1->d, cst1->d, cst2->d); - isl_upoly_cst_reduce(cst1); + isl_poly_cst_reduce(cst1); - isl_upoly_free(up2); - return up1; + isl_poly_free(poly2); + return poly1; error: - isl_upoly_free(up1); - isl_upoly_free(up2); + isl_poly_free(poly1); + isl_poly_free(poly2); return NULL; } -__isl_give struct isl_upoly *isl_upoly_mul_rec(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2) +__isl_give isl_poly *isl_poly_mul_rec(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2) { - struct isl_upoly_rec *rec1; - struct isl_upoly_rec *rec2; - struct isl_upoly_rec *res = NULL; + isl_poly_rec *rec1; + isl_poly_rec *rec2; + isl_poly_rec *res = NULL; int i, j; int size; - rec1 = isl_upoly_as_rec(up1); - rec2 = isl_upoly_as_rec(up2); + rec1 = isl_poly_as_rec(poly1); + rec2 = isl_poly_as_rec(poly2); if (!rec1 || !rec2) goto error; size = rec1->n + rec2->n - 1; - res = isl_upoly_alloc_rec(up1->ctx, up1->var, size); + res = isl_poly_alloc_rec(poly1->ctx, poly1->var, size); if (!res) goto error; for (i = 0; i < rec1->n; ++i) { - res->p[i] = isl_upoly_mul(isl_upoly_copy(rec2->p[0]), - isl_upoly_copy(rec1->p[i])); + res->p[i] = isl_poly_mul(isl_poly_copy(rec2->p[0]), + isl_poly_copy(rec1->p[i])); if (!res->p[i]) goto error; res->n++; } for (; i < size; ++i) { - res->p[i] = isl_upoly_zero(up1->ctx); + res->p[i] = isl_poly_zero(poly1->ctx); if (!res->p[i]) goto error; res->n++; } for (i = 0; i < rec1->n; ++i) { for (j = 1; j < rec2->n; ++j) { - struct isl_upoly *up; - up = isl_upoly_mul(isl_upoly_copy(rec2->p[j]), - isl_upoly_copy(rec1->p[i])); - res->p[i + j] = isl_upoly_sum(res->p[i + j], up); + isl_poly *poly; + poly = isl_poly_mul(isl_poly_copy(rec2->p[j]), + isl_poly_copy(rec1->p[i])); + res->p[i + j] = isl_poly_sum(res->p[i + j], poly); if (!res->p[i + j]) goto error; } } - isl_upoly_free(up1); - isl_upoly_free(up2); + isl_poly_free(poly1); + isl_poly_free(poly2); - return &res->up; + return &res->poly; error: - isl_upoly_free(up1); - isl_upoly_free(up2); - isl_upoly_free(&res->up); + isl_poly_free(poly1); + isl_poly_free(poly2); + isl_poly_free(&res->poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_mul(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2) +__isl_give isl_poly *isl_poly_mul(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2) { - if (!up1 || !up2) + isl_bool is_zero, is_nan, is_one, is_cst; + + if (!poly1 || !poly2) goto error; - if (isl_upoly_is_nan(up1)) { - isl_upoly_free(up2); - return up1; + is_nan = isl_poly_is_nan(poly1); + if (is_nan < 0) + goto error; + if (is_nan) { + isl_poly_free(poly2); + return poly1; } - if (isl_upoly_is_nan(up2)) { - isl_upoly_free(up1); - return up2; + is_nan = isl_poly_is_nan(poly2); + if (is_nan < 0) + goto error; + if (is_nan) { + isl_poly_free(poly1); + return poly2; } - if (isl_upoly_is_zero(up1)) { - isl_upoly_free(up2); - return up1; + is_zero = isl_poly_is_zero(poly1); + if (is_zero < 0) + goto error; + if (is_zero) { + isl_poly_free(poly2); + return poly1; } - if (isl_upoly_is_zero(up2)) { - isl_upoly_free(up1); - return up2; + is_zero = isl_poly_is_zero(poly2); + if (is_zero < 0) + goto error; + if (is_zero) { + isl_poly_free(poly1); + return poly2; } - if (isl_upoly_is_one(up1)) { - isl_upoly_free(up1); - return up2; + is_one = isl_poly_is_one(poly1); + if (is_one < 0) + goto error; + if (is_one) { + isl_poly_free(poly1); + return poly2; } - if (isl_upoly_is_one(up2)) { - isl_upoly_free(up2); - return up1; + is_one = isl_poly_is_one(poly2); + if (is_one < 0) + goto error; + if (is_one) { + isl_poly_free(poly2); + return poly1; } - if (up1->var < up2->var) - return isl_upoly_mul(up2, up1); + if (poly1->var < poly2->var) + return isl_poly_mul(poly2, poly1); - if (up2->var < up1->var) { + if (poly2->var < poly1->var) { int i; - struct isl_upoly_rec *rec; - if (isl_upoly_is_infty(up2) || isl_upoly_is_neginfty(up2)) { - isl_ctx *ctx = up1->ctx; - isl_upoly_free(up1); - isl_upoly_free(up2); - return isl_upoly_nan(ctx); + isl_poly_rec *rec; + isl_bool is_infty; + + is_infty = isl_poly_is_infty(poly2); + if (is_infty >= 0 && !is_infty) + is_infty = isl_poly_is_neginfty(poly2); + if (is_infty < 0) + goto error; + if (is_infty) { + isl_ctx *ctx = poly1->ctx; + isl_poly_free(poly1); + isl_poly_free(poly2); + return isl_poly_nan(ctx); } - up1 = isl_upoly_cow(up1); - rec = isl_upoly_as_rec(up1); + poly1 = isl_poly_cow(poly1); + rec = isl_poly_as_rec(poly1); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - rec->p[i] = isl_upoly_mul(rec->p[i], - isl_upoly_copy(up2)); + rec->p[i] = isl_poly_mul(rec->p[i], + isl_poly_copy(poly2)); if (!rec->p[i]) goto error; } - isl_upoly_free(up2); - return up1; + isl_poly_free(poly2); + return poly1; } - if (isl_upoly_is_cst(up1)) - return isl_upoly_mul_cst(up1, up2); + is_cst = isl_poly_is_cst(poly1); + if (is_cst < 0) + goto error; + if (is_cst) + return isl_poly_mul_cst(poly1, poly2); - return isl_upoly_mul_rec(up1, up2); + return isl_poly_mul_rec(poly1, poly2); error: - isl_upoly_free(up1); - isl_upoly_free(up2); + isl_poly_free(poly1); + isl_poly_free(poly2); return NULL; } -__isl_give struct isl_upoly *isl_upoly_pow(__isl_take struct isl_upoly *up, - unsigned power) +__isl_give isl_poly *isl_poly_pow(__isl_take isl_poly *poly, unsigned power) { - struct isl_upoly *res; + isl_poly *res; - if (!up) + if (!poly) return NULL; if (power == 1) - return up; + return poly; if (power % 2) - res = isl_upoly_copy(up); + res = isl_poly_copy(poly); else - res = isl_upoly_one(up->ctx); + res = isl_poly_one(poly->ctx); while (power >>= 1) { - up = isl_upoly_mul(up, isl_upoly_copy(up)); + poly = isl_poly_mul(poly, isl_poly_copy(poly)); if (power % 2) - res = isl_upoly_mul(res, isl_upoly_copy(up)); + res = isl_poly_mul(res, isl_poly_copy(poly)); } - isl_upoly_free(up); + isl_poly_free(poly); return res; } -__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *dim, - unsigned n_div, __isl_take struct isl_upoly *up) +__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *space, + unsigned n_div, __isl_take isl_poly *poly) { struct isl_qpolynomial *qp = NULL; - unsigned total; + isl_size total; - if (!dim || !up) + total = isl_space_dim(space, isl_dim_all); + if (total < 0 || !poly) goto error; - if (!isl_space_is_set(dim)) - isl_die(isl_space_get_ctx(dim), isl_error_invalid, + if (!isl_space_is_set(space)) + isl_die(isl_space_get_ctx(space), isl_error_invalid, "domain of polynomial should be a set", goto error); - total = isl_space_dim(dim, isl_dim_all); - - qp = isl_calloc_type(dim->ctx, struct isl_qpolynomial); + qp = isl_calloc_type(space->ctx, struct isl_qpolynomial); if (!qp) goto error; qp->ref = 1; - qp->div = isl_mat_alloc(dim->ctx, n_div, 1 + 1 + total + n_div); + qp->div = isl_mat_alloc(space->ctx, n_div, 1 + 1 + total + n_div); if (!qp->div) goto error; - qp->dim = dim; - qp->upoly = up; + qp->dim = space; + qp->poly = poly; return qp; error: - isl_space_free(dim); - isl_upoly_free(up); + isl_space_free(space); + isl_poly_free(poly); isl_qpolynomial_free(qp); return NULL; } @@ -1175,7 +1318,7 @@ return NULL; dup = isl_qpolynomial_alloc(isl_space_copy(qp->dim), qp->div->n_row, - isl_upoly_copy(qp->upoly)); + isl_poly_copy(qp->poly)); if (!dup) return NULL; isl_mat_free(dup->div); @@ -1211,69 +1354,72 @@ isl_space_free(qp->dim); isl_mat_free(qp->div); - isl_upoly_free(qp->upoly); + isl_poly_free(qp->poly); free(qp); return NULL; } -__isl_give struct isl_upoly *isl_upoly_var_pow(isl_ctx *ctx, int pos, int power) +__isl_give isl_poly *isl_poly_var_pow(isl_ctx *ctx, int pos, int power) { int i; - struct isl_upoly_rec *rec; - struct isl_upoly_cst *cst; + isl_poly_rec *rec; + isl_poly_cst *cst; - rec = isl_upoly_alloc_rec(ctx, pos, 1 + power); + rec = isl_poly_alloc_rec(ctx, pos, 1 + power); if (!rec) return NULL; for (i = 0; i < 1 + power; ++i) { - rec->p[i] = isl_upoly_zero(ctx); + rec->p[i] = isl_poly_zero(ctx); if (!rec->p[i]) goto error; rec->n++; } - cst = isl_upoly_as_cst(rec->p[power]); + cst = isl_poly_as_cst(rec->p[power]); isl_int_set_si(cst->n, 1); - return &rec->up; + return &rec->poly; error: - isl_upoly_free(&rec->up); + isl_poly_free(&rec->poly); return NULL; } /* r array maps original positions to new positions. */ -static __isl_give struct isl_upoly *reorder(__isl_take struct isl_upoly *up, - int *r) +static __isl_give isl_poly *reorder(__isl_take isl_poly *poly, int *r) { int i; - struct isl_upoly_rec *rec; - struct isl_upoly *base; - struct isl_upoly *res; - - if (isl_upoly_is_cst(up)) - return up; - - rec = isl_upoly_as_rec(up); + isl_bool is_cst; + isl_poly_rec *rec; + isl_poly *base; + isl_poly *res; + + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return poly; + + rec = isl_poly_as_rec(poly); if (!rec) goto error; - isl_assert(up->ctx, rec->n >= 1, goto error); + isl_assert(poly->ctx, rec->n >= 1, goto error); - base = isl_upoly_var_pow(up->ctx, r[up->var], 1); - res = reorder(isl_upoly_copy(rec->p[rec->n - 1]), r); + base = isl_poly_var_pow(poly->ctx, r[poly->var], 1); + res = reorder(isl_poly_copy(rec->p[rec->n - 1]), r); for (i = rec->n - 2; i >= 0; --i) { - res = isl_upoly_mul(res, isl_upoly_copy(base)); - res = isl_upoly_sum(res, reorder(isl_upoly_copy(rec->p[i]), r)); + res = isl_poly_mul(res, isl_poly_copy(base)); + res = isl_poly_sum(res, reorder(isl_poly_copy(rec->p[i]), r)); } - isl_upoly_free(base); - isl_upoly_free(up); + isl_poly_free(base); + isl_poly_free(poly); return res; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } @@ -1340,14 +1486,16 @@ struct isl_div_sort_info *array = NULL; int *pos = NULL, *at = NULL; int *reordering = NULL; - unsigned div_pos; + isl_size div_pos; if (!qp) return NULL; if (qp->div->n_row <= 1) return qp; - div_pos = isl_space_dim(qp->dim, isl_dim_all); + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) + return isl_qpolynomial_free(qp); array = isl_alloc_array(qp->div->ctx, struct isl_div_sort_info, qp->div->n_row); @@ -1396,9 +1544,9 @@ reordering[div_pos + array[i].row] = div_pos + i - skip; } - qp->upoly = reorder(qp->upoly, reordering); + qp->poly = reorder(qp->poly, reordering); - if (!qp->upoly || !qp->div) + if (!qp->poly || !qp->div) goto error; free(at); @@ -1416,28 +1564,32 @@ return NULL; } -static __isl_give struct isl_upoly *expand(__isl_take struct isl_upoly *up, - int *exp, int first) +static __isl_give isl_poly *expand(__isl_take isl_poly *poly, int *exp, + int first) { int i; - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; - if (isl_upoly_is_cst(up)) - return up; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return poly; - if (up->var < first) - return up; + if (poly->var < first) + return poly; - if (exp[up->var - first] == up->var - first) - return up; + if (exp[poly->var - first] == poly->var - first) + return poly; - up = isl_upoly_cow(up); - if (!up) + poly = isl_poly_cow(poly); + if (!poly) goto error; - up->var = exp[up->var - first] + first; + poly->var = exp[poly->var - first] + first; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) goto error; @@ -1447,9 +1599,9 @@ goto error; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } @@ -1488,10 +1640,10 @@ isl_mat_free(qp2->div); qp2->div = isl_mat_copy(div); - qp1->upoly = expand(qp1->upoly, exp1, div->n_col - div->n_row - 2); - qp2->upoly = expand(qp2->upoly, exp2, div->n_col - div->n_row - 2); + qp1->poly = expand(qp1->poly, exp1, div->n_col - div->n_row - 2); + qp2->poly = expand(qp2->poly, exp2, div->n_col - div->n_row - 2); - if (!qp1->upoly || !qp2->upoly) + if (!qp1->poly || !qp2->poly) goto error; isl_mat_free(div); @@ -1528,8 +1680,8 @@ if (!compatible) return with_merged_divs(isl_qpolynomial_add, qp1, qp2); - qp1->upoly = isl_upoly_sum(qp1->upoly, isl_upoly_copy(qp2->upoly)); - if (!qp1->upoly) + qp1->poly = isl_poly_sum(qp1->poly, isl_poly_copy(qp2->poly)); + if (!qp1->poly) goto error; isl_qpolynomial_free(qp2); @@ -1567,8 +1719,8 @@ if (!qp) return NULL; - qp->upoly = isl_upoly_add_isl_int(qp->upoly, v); - if (!qp->upoly) + qp->poly = isl_poly_add_isl_int(qp->poly, v); + if (!qp->poly) goto error; return qp; @@ -1603,8 +1755,8 @@ if (!qp) return NULL; - qp->upoly = isl_upoly_mul_isl_int(qp->upoly, v); - if (!qp->upoly) + qp->poly = isl_poly_mul_isl_int(qp->poly, v); + if (!qp->poly) goto error; return qp; @@ -1649,8 +1801,8 @@ if (!qp) goto error; - qp->upoly = isl_upoly_scale_val(qp->upoly, v); - if (!qp->upoly) + qp->poly = isl_poly_scale_val(qp->poly, v); + if (!qp->poly) qp = isl_qpolynomial_free(qp); isl_val_free(v); @@ -1703,8 +1855,8 @@ if (!compatible) return with_merged_divs(isl_qpolynomial_mul, qp1, qp2); - qp1->upoly = isl_upoly_mul(qp1->upoly, isl_upoly_copy(qp2->upoly)); - if (!qp1->upoly) + qp1->poly = isl_poly_mul(qp1->poly, isl_poly_copy(qp2->poly)); + if (!qp1->poly) goto error; isl_qpolynomial_free(qp2); @@ -1724,8 +1876,8 @@ if (!qp) return NULL; - qp->upoly = isl_upoly_pow(qp->upoly, power); - if (!qp->upoly) + qp->poly = isl_poly_pow(qp->poly, power); + if (!qp->poly) goto error; return qp; @@ -1756,111 +1908,112 @@ } __isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain( - __isl_take isl_space *dim) + __isl_take isl_space *domain) { - if (!dim) + if (!domain) return NULL; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_zero(dim->ctx)); + return isl_qpolynomial_alloc(domain, 0, isl_poly_zero(domain->ctx)); } __isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain( - __isl_take isl_space *dim) + __isl_take isl_space *domain) { - if (!dim) + if (!domain) return NULL; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_one(dim->ctx)); + return isl_qpolynomial_alloc(domain, 0, isl_poly_one(domain->ctx)); } __isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain( - __isl_take isl_space *dim) + __isl_take isl_space *domain) { - if (!dim) + if (!domain) return NULL; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_infty(dim->ctx)); + return isl_qpolynomial_alloc(domain, 0, isl_poly_infty(domain->ctx)); } __isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain( - __isl_take isl_space *dim) + __isl_take isl_space *domain) { - if (!dim) + if (!domain) return NULL; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_neginfty(dim->ctx)); + return isl_qpolynomial_alloc(domain, 0, isl_poly_neginfty(domain->ctx)); } __isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain( - __isl_take isl_space *dim) + __isl_take isl_space *domain) { - if (!dim) + if (!domain) return NULL; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_nan(dim->ctx)); + return isl_qpolynomial_alloc(domain, 0, isl_poly_nan(domain->ctx)); } __isl_give isl_qpolynomial *isl_qpolynomial_cst_on_domain( - __isl_take isl_space *dim, + __isl_take isl_space *domain, isl_int v) { struct isl_qpolynomial *qp; - struct isl_upoly_cst *cst; - - if (!dim) - return NULL; + isl_poly_cst *cst; - qp = isl_qpolynomial_alloc(dim, 0, isl_upoly_zero(dim->ctx)); + qp = isl_qpolynomial_zero_on_domain(domain); if (!qp) return NULL; - cst = isl_upoly_as_cst(qp->upoly); + cst = isl_poly_as_cst(qp->poly); isl_int_set(cst->n, v); return qp; } -int isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp, +isl_bool isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp, isl_int *n, isl_int *d) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; if (!qp) - return -1; + return isl_bool_error; - if (!isl_upoly_is_cst(qp->upoly)) - return 0; + is_cst = isl_poly_is_cst(qp->poly); + if (is_cst < 0 || !is_cst) + return is_cst; - cst = isl_upoly_as_cst(qp->upoly); + cst = isl_poly_as_cst(qp->poly); if (!cst) - return -1; + return isl_bool_error; if (n) isl_int_set(*n, cst->n); if (d) isl_int_set(*d, cst->d); - return 1; + return isl_bool_true; } -/* Return the constant term of "up". +/* Return the constant term of "poly". */ -static __isl_give isl_val *isl_upoly_get_constant_val( - __isl_keep struct isl_upoly *up) +static __isl_give isl_val *isl_poly_get_constant_val(__isl_keep isl_poly *poly) { - struct isl_upoly_cst *cst; + isl_bool is_cst; + isl_poly_cst *cst; - if (!up) + if (!poly) return NULL; - while (!isl_upoly_is_cst(up)) { - struct isl_upoly_rec *rec; + while ((is_cst = isl_poly_is_cst(poly)) == isl_bool_false) { + isl_poly_rec *rec; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) return NULL; - up = rec->p[0]; + poly = rec->p[0]; } + if (is_cst < 0) + return NULL; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) return NULL; - return isl_val_rat_from_isl_int(cst->up.ctx, cst->n, cst->d); + return isl_val_rat_from_isl_int(cst->poly.ctx, cst->n, cst->d); } /* Return the constant term of "qp". @@ -1871,51 +2024,49 @@ if (!qp) return NULL; - return isl_upoly_get_constant_val(qp->upoly); + return isl_poly_get_constant_val(qp->poly); } -int isl_upoly_is_affine(__isl_keep struct isl_upoly *up) +isl_bool isl_poly_is_affine(__isl_keep isl_poly *poly) { - int is_cst; - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; - if (!up) - return -1; + if (!poly) + return isl_bool_error; - if (up->var < 0) - return 1; + if (poly->var < 0) + return isl_bool_true; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) - return -1; + return isl_bool_error; if (rec->n > 2) - return 0; + return isl_bool_false; - isl_assert(up->ctx, rec->n > 1, return -1); + isl_assert(poly->ctx, rec->n > 1, return isl_bool_error); - is_cst = isl_upoly_is_cst(rec->p[1]); - if (is_cst < 0) - return -1; - if (!is_cst) - return 0; + is_cst = isl_poly_is_cst(rec->p[1]); + if (is_cst < 0 || !is_cst) + return is_cst; - return isl_upoly_is_affine(rec->p[0]); + return isl_poly_is_affine(rec->p[0]); } -int isl_qpolynomial_is_affine(__isl_keep isl_qpolynomial *qp) +isl_bool isl_qpolynomial_is_affine(__isl_keep isl_qpolynomial *qp) { if (!qp) - return -1; + return isl_bool_error; if (qp->div->n_row > 0) - return 0; + return isl_bool_false; - return isl_upoly_is_affine(qp->upoly); + return isl_poly_is_affine(qp->poly); } static void update_coeff(__isl_keep isl_vec *aff, - __isl_keep struct isl_upoly_cst *cst, int pos) + __isl_keep isl_poly_cst *cst, int pos) { isl_int gcd; isl_int f; @@ -1934,56 +2085,55 @@ isl_int_clear(f); } -int isl_upoly_update_affine(__isl_keep struct isl_upoly *up, - __isl_keep isl_vec *aff) +int isl_poly_update_affine(__isl_keep isl_poly *poly, __isl_keep isl_vec *aff) { - struct isl_upoly_cst *cst; - struct isl_upoly_rec *rec; + isl_poly_cst *cst; + isl_poly_rec *rec; - if (!up || !aff) + if (!poly || !aff) return -1; - if (up->var < 0) { - struct isl_upoly_cst *cst; + if (poly->var < 0) { + isl_poly_cst *cst; - cst = isl_upoly_as_cst(up); + cst = isl_poly_as_cst(poly); if (!cst) return -1; update_coeff(aff, cst, 0); return 0; } - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) return -1; - isl_assert(up->ctx, rec->n == 2, return -1); + isl_assert(poly->ctx, rec->n == 2, return -1); - cst = isl_upoly_as_cst(rec->p[1]); + cst = isl_poly_as_cst(rec->p[1]); if (!cst) return -1; - update_coeff(aff, cst, 1 + up->var); + update_coeff(aff, cst, 1 + poly->var); - return isl_upoly_update_affine(rec->p[0], aff); + return isl_poly_update_affine(rec->p[0], aff); } __isl_give isl_vec *isl_qpolynomial_extract_affine( __isl_keep isl_qpolynomial *qp) { isl_vec *aff; - unsigned d; + isl_size d; - if (!qp) + d = isl_qpolynomial_domain_dim(qp, isl_dim_all); + if (d < 0) return NULL; - d = isl_space_dim(qp->dim, isl_dim_all); - aff = isl_vec_alloc(qp->div->ctx, 2 + d + qp->div->n_row); + aff = isl_vec_alloc(qp->div->ctx, 2 + d); if (!aff) return NULL; - isl_seq_clr(aff->el + 1, 1 + d + qp->div->n_row); + isl_seq_clr(aff->el + 1, 1 + d); isl_int_set_si(aff->el[0], 1); - if (isl_upoly_update_affine(qp->upoly, aff) < 0) + if (isl_poly_update_affine(qp->poly, aff) < 0) goto error; return aff; @@ -2017,7 +2167,7 @@ if (cmp != 0) return cmp; - return isl_upoly_plain_cmp(qp1->upoly, qp2->upoly); + return isl_poly_plain_cmp(qp1->poly, qp2->poly); } /* Is "qp1" obviously equal to "qp2"? @@ -2043,137 +2193,149 @@ if (equal < 0 || !equal) return equal; - return isl_upoly_is_equal(qp1->upoly, qp2->upoly); + return isl_poly_is_equal(qp1->poly, qp2->poly); } -static void upoly_update_den(__isl_keep struct isl_upoly *up, isl_int *d) +static isl_stat poly_update_den(__isl_keep isl_poly *poly, isl_int *d) { int i; - struct isl_upoly_rec *rec; - - if (isl_upoly_is_cst(up)) { - struct isl_upoly_cst *cst; - cst = isl_upoly_as_cst(up); + isl_bool is_cst; + isl_poly_rec *rec; + + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_stat_error; + if (is_cst) { + isl_poly_cst *cst; + cst = isl_poly_as_cst(poly); if (!cst) - return; + return isl_stat_error; isl_int_lcm(*d, *d, cst->d); - return; + return isl_stat_ok; } - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) - return; + return isl_stat_error; for (i = 0; i < rec->n; ++i) - upoly_update_den(rec->p[i], d); + poly_update_den(rec->p[i], d); + + return isl_stat_ok; } -void isl_qpolynomial_get_den(__isl_keep isl_qpolynomial *qp, isl_int *d) +__isl_give isl_val *isl_qpolynomial_get_den(__isl_keep isl_qpolynomial *qp) { - isl_int_set_si(*d, 1); + isl_val *d; + if (!qp) - return; - upoly_update_den(qp->upoly, d); + return NULL; + d = isl_val_one(isl_qpolynomial_get_ctx(qp)); + if (!d) + return NULL; + if (poly_update_den(qp->poly, &d->n) < 0) + return isl_val_free(d); + return d; } __isl_give isl_qpolynomial *isl_qpolynomial_var_pow_on_domain( - __isl_take isl_space *dim, int pos, int power) + __isl_take isl_space *domain, int pos, int power) { struct isl_ctx *ctx; - if (!dim) + if (!domain) return NULL; - ctx = dim->ctx; + ctx = domain->ctx; - return isl_qpolynomial_alloc(dim, 0, isl_upoly_var_pow(ctx, pos, power)); + return isl_qpolynomial_alloc(domain, 0, + isl_poly_var_pow(ctx, pos, power)); } -__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain(__isl_take isl_space *dim, - enum isl_dim_type type, unsigned pos) +__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain( + __isl_take isl_space *domain, enum isl_dim_type type, unsigned pos) { - if (!dim) - return NULL; - - isl_assert(dim->ctx, isl_space_dim(dim, isl_dim_in) == 0, goto error); - isl_assert(dim->ctx, pos < isl_space_dim(dim, type), goto error); + if (isl_space_check_is_set(domain ) < 0) + goto error; + if (isl_space_check_range(domain, type, pos, 1) < 0) + goto error; - if (type == isl_dim_set) - pos += isl_space_dim(dim, isl_dim_param); + pos += isl_space_offset(domain, type); - return isl_qpolynomial_var_pow_on_domain(dim, pos, 1); + return isl_qpolynomial_var_pow_on_domain(domain, pos, 1); error: - isl_space_free(dim); + isl_space_free(domain); return NULL; } -__isl_give struct isl_upoly *isl_upoly_subs(__isl_take struct isl_upoly *up, - unsigned first, unsigned n, __isl_keep struct isl_upoly **subs) +__isl_give isl_poly *isl_poly_subs(__isl_take isl_poly *poly, + unsigned first, unsigned n, __isl_keep isl_poly **subs) { int i; - struct isl_upoly_rec *rec; - struct isl_upoly *base, *res; - - if (!up) - return NULL; - - if (isl_upoly_is_cst(up)) - return up; + isl_bool is_cst; + isl_poly_rec *rec; + isl_poly *base, *res; + + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst) + return poly; - if (up->var < first) - return up; + if (poly->var < first) + return poly; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) goto error; - isl_assert(up->ctx, rec->n >= 1, goto error); + isl_assert(poly->ctx, rec->n >= 1, goto error); - if (up->var >= first + n) - base = isl_upoly_var_pow(up->ctx, up->var, 1); + if (poly->var >= first + n) + base = isl_poly_var_pow(poly->ctx, poly->var, 1); else - base = isl_upoly_copy(subs[up->var - first]); + base = isl_poly_copy(subs[poly->var - first]); - res = isl_upoly_subs(isl_upoly_copy(rec->p[rec->n - 1]), first, n, subs); + res = isl_poly_subs(isl_poly_copy(rec->p[rec->n - 1]), first, n, subs); for (i = rec->n - 2; i >= 0; --i) { - struct isl_upoly *t; - t = isl_upoly_subs(isl_upoly_copy(rec->p[i]), first, n, subs); - res = isl_upoly_mul(res, isl_upoly_copy(base)); - res = isl_upoly_sum(res, t); + isl_poly *t; + t = isl_poly_subs(isl_poly_copy(rec->p[i]), first, n, subs); + res = isl_poly_mul(res, isl_poly_copy(base)); + res = isl_poly_sum(res, t); } - isl_upoly_free(base); - isl_upoly_free(up); + isl_poly_free(base); + isl_poly_free(poly); return res; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } -__isl_give struct isl_upoly *isl_upoly_from_affine(isl_ctx *ctx, isl_int *f, +__isl_give isl_poly *isl_poly_from_affine(isl_ctx *ctx, isl_int *f, isl_int denom, unsigned len) { int i; - struct isl_upoly *up; + isl_poly *poly; isl_assert(ctx, len >= 1, return NULL); - up = isl_upoly_rat_cst(ctx, f[0], denom); + poly = isl_poly_rat_cst(ctx, f[0], denom); for (i = 0; i < len - 1; ++i) { - struct isl_upoly *t; - struct isl_upoly *c; + isl_poly *t; + isl_poly *c; if (isl_int_is_zero(f[1 + i])) continue; - c = isl_upoly_rat_cst(ctx, f[1 + i], denom); - t = isl_upoly_var_pow(ctx, i, 1); - t = isl_upoly_mul(c, t); - up = isl_upoly_sum(up, t); + c = isl_poly_rat_cst(ctx, f[1 + i], denom); + t = isl_poly_var_pow(ctx, i, 1); + t = isl_poly_mul(c, t); + poly = isl_poly_sum(poly, t); } - return up; + return poly; } /* Remove common factor of non-constant terms and denominator. @@ -2202,12 +2364,12 @@ * of any other integer divisions. */ static __isl_give isl_qpolynomial *substitute_div( - __isl_take isl_qpolynomial *qp, - int div, __isl_take struct isl_upoly *s) + __isl_take isl_qpolynomial *qp, int div, __isl_take isl_poly *s) { int i; - int total; + isl_size div_pos; int *reordering; + isl_ctx *ctx; if (!qp || !s) goto error; @@ -2216,31 +2378,34 @@ if (!qp) goto error; - total = isl_space_dim(qp->dim, isl_dim_all); - qp->upoly = isl_upoly_subs(qp->upoly, total + div, 1, &s); - if (!qp->upoly) + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) goto error; + qp->poly = isl_poly_subs(qp->poly, div_pos + div, 1, &s); + if (!qp->poly) + goto error; - reordering = isl_alloc_array(qp->dim->ctx, int, total + qp->div->n_row); + ctx = isl_qpolynomial_get_ctx(qp); + reordering = isl_alloc_array(ctx, int, div_pos + qp->div->n_row); if (!reordering) goto error; - for (i = 0; i < total + div; ++i) + for (i = 0; i < div_pos + div; ++i) reordering[i] = i; - for (i = total + div + 1; i < total + qp->div->n_row; ++i) + for (i = div_pos + div + 1; i < div_pos + qp->div->n_row; ++i) reordering[i] = i - 1; qp->div = isl_mat_drop_rows(qp->div, div, 1); - qp->div = isl_mat_drop_cols(qp->div, 2 + total + div, 1); - qp->upoly = reorder(qp->upoly, reordering); + qp->div = isl_mat_drop_cols(qp->div, 2 + div_pos + div, 1); + qp->poly = reorder(qp->poly, reordering); free(reordering); - if (!qp->upoly || !qp->div) + if (!qp->poly || !qp->div) goto error; - isl_upoly_free(s); + isl_poly_free(s); return qp; error: isl_qpolynomial_free(qp); - isl_upoly_free(s); + isl_poly_free(s); return NULL; } @@ -2251,27 +2416,27 @@ __isl_take isl_qpolynomial *qp) { int i, j; - int total; - struct isl_upoly *s; - - if (!qp) - return NULL; + isl_size div_pos; + isl_poly *s; + + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) + return isl_qpolynomial_free(qp); - total = isl_space_dim(qp->dim, isl_dim_all); for (i = 0; qp && i < qp->div->n_row; ++i) { if (!isl_int_is_one(qp->div->row[i][0])) continue; for (j = i + 1; j < qp->div->n_row; ++j) { - if (isl_int_is_zero(qp->div->row[j][2 + total + i])) + if (isl_int_is_zero(qp->div->row[j][2 + div_pos + i])) continue; isl_seq_combine(qp->div->row[j] + 1, qp->div->ctx->one, qp->div->row[j] + 1, - qp->div->row[j][2 + total + i], - qp->div->row[i] + 1, 1 + total + i); - isl_int_set_si(qp->div->row[j][2 + total + i], 0); + qp->div->row[j][2 + div_pos + i], + qp->div->row[i] + 1, 1 + div_pos + i); + isl_int_set_si(qp->div->row[j][2 + div_pos + i], 0); normalize_div(qp, j); } - s = isl_upoly_from_affine(qp->dim->ctx, qp->div->row[i] + 1, + s = isl_poly_from_affine(qp->dim->ctx, qp->div->row[i] + 1, qp->div->row[i][0], qp->div->n_col - 1); qp = substitute_div(qp, i, s); --i; @@ -2381,15 +2546,15 @@ int i; isl_ctx *ctx; isl_mat *mat; - struct isl_upoly **s; - unsigned o_div, n_div, total; - - if (!qp) - return NULL; + isl_poly **s; + unsigned o_div; + isl_size n_div, total, new_n_div; total = isl_qpolynomial_domain_dim(qp, isl_dim_all); n_div = isl_qpolynomial_domain_dim(qp, isl_dim_div); o_div = isl_qpolynomial_domain_offset(qp, isl_dim_div); + if (total < 0 || n_div < 0) + return isl_qpolynomial_free(qp); ctx = isl_qpolynomial_get_ctx(qp); mat = isl_mat_zero(ctx, n_div, 1 + total); @@ -2407,24 +2572,27 @@ if (!mat) goto error; - s = isl_alloc_array(ctx, struct isl_upoly *, n_div); + s = isl_alloc_array(ctx, struct isl_poly *, n_div); if (n_div && !s) goto error; for (i = 0; i < n_div; ++i) - s[i] = isl_upoly_from_affine(ctx, mat->row[i], ctx->one, + s[i] = isl_poly_from_affine(ctx, mat->row[i], ctx->one, 1 + total); - qp->upoly = isl_upoly_subs(qp->upoly, o_div - 1, n_div, s); + qp->poly = isl_poly_subs(qp->poly, o_div - 1, n_div, s); for (i = 0; i < n_div; ++i) - isl_upoly_free(s[i]); + isl_poly_free(s[i]); free(s); - if (!qp->upoly) + if (!qp->poly) goto error; isl_mat_free(mat); qp = substitute_non_divs(qp); qp = sort_divs(qp); - if (qp && isl_qpolynomial_domain_dim(qp, isl_dim_div) < n_div) + new_n_div = isl_qpolynomial_domain_dim(qp, isl_dim_div); + if (new_n_div < 0) + return isl_qpolynomial_free(qp); + if (new_n_div < n_div) return reduce_divs(qp); return qp; @@ -2435,19 +2603,16 @@ } __isl_give isl_qpolynomial *isl_qpolynomial_rat_cst_on_domain( - __isl_take isl_space *dim, const isl_int n, const isl_int d) + __isl_take isl_space *domain, const isl_int n, const isl_int d) { struct isl_qpolynomial *qp; - struct isl_upoly_cst *cst; + isl_poly_cst *cst; - if (!dim) - return NULL; - - qp = isl_qpolynomial_alloc(dim, 0, isl_upoly_zero(dim->ctx)); + qp = isl_qpolynomial_zero_on_domain(domain); if (!qp) return NULL; - cst = isl_upoly_as_cst(qp->upoly); + cst = isl_poly_as_cst(qp->poly); isl_int_set(cst->n, n); isl_int_set(cst->d, d); @@ -2460,58 +2625,57 @@ __isl_take isl_space *domain, __isl_take isl_val *val) { isl_qpolynomial *qp; - struct isl_upoly_cst *cst; - - if (!domain || !val) - goto error; + isl_poly_cst *cst; - qp = isl_qpolynomial_alloc(isl_space_copy(domain), 0, - isl_upoly_zero(domain->ctx)); - if (!qp) + qp = isl_qpolynomial_zero_on_domain(domain); + if (!qp || !val) goto error; - cst = isl_upoly_as_cst(qp->upoly); + cst = isl_poly_as_cst(qp->poly); isl_int_set(cst->n, val->n); isl_int_set(cst->d, val->d); - isl_space_free(domain); isl_val_free(val); return qp; error: - isl_space_free(domain); isl_val_free(val); + isl_qpolynomial_free(qp); return NULL; } -static int up_set_active(__isl_keep struct isl_upoly *up, int *active, int d) +static isl_stat poly_set_active(__isl_keep isl_poly *poly, int *active, int d) { - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; int i; - - if (!up) - return -1; - if (isl_upoly_is_cst(up)) - return 0; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_stat_error; + if (is_cst) + return isl_stat_ok; - if (up->var < d) - active[up->var] = 1; + if (poly->var < d) + active[poly->var] = 1; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); for (i = 0; i < rec->n; ++i) - if (up_set_active(rec->p[i], active, d) < 0) - return -1; + if (poly_set_active(rec->p[i], active, d) < 0) + return isl_stat_error; - return 0; + return isl_stat_ok; } -static int set_active(__isl_keep isl_qpolynomial *qp, int *active) +static isl_stat set_active(__isl_keep isl_qpolynomial *qp, int *active) { int i, j; - int d = isl_space_dim(qp->dim, isl_dim_all); + isl_size d; + isl_space *space; - if (!qp || !active) - return -1; + space = isl_qpolynomial_peek_domain_space(qp); + d = isl_space_dim(space, isl_dim_all); + if (d < 0 || !active) + return isl_stat_error; for (i = 0; i < d; ++i) for (j = 0; j < qp->div->n_row; ++j) { @@ -2521,34 +2685,46 @@ break; } - return up_set_active(qp->upoly, active, d); + return poly_set_active(qp->poly, active, d); } +#undef TYPE +#define TYPE isl_qpolynomial +static +#include "check_type_range_templ.c" + isl_bool isl_qpolynomial_involves_dims(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type, unsigned first, unsigned n) { int i; int *active = NULL; isl_bool involves = isl_bool_false; + isl_size offset; + isl_size d; + isl_space *space; if (!qp) return isl_bool_error; if (n == 0) return isl_bool_false; - isl_assert(qp->dim->ctx, - first + n <= isl_qpolynomial_dim(qp, type), - return isl_bool_error); + if (isl_qpolynomial_check_range(qp, type, first, n) < 0) + return isl_bool_error; isl_assert(qp->dim->ctx, type == isl_dim_param || type == isl_dim_in, return isl_bool_error); - active = isl_calloc_array(qp->dim->ctx, int, - isl_space_dim(qp->dim, isl_dim_all)); + space = isl_qpolynomial_peek_domain_space(qp); + d = isl_space_dim(space, isl_dim_all); + if (d < 0) + return isl_bool_error; + active = isl_calloc_array(qp->dim->ctx, int, d); if (set_active(qp, active) < 0) goto error; - if (type == isl_dim_in) - first += isl_space_dim(qp->dim, isl_dim_param); + offset = isl_qpolynomial_domain_var_offset(qp, domain_type(type)); + if (offset < 0) + goto error; + first += offset; for (i = 0; i < n; ++i) if (active[first + i]) { involves = isl_bool_true; @@ -2570,7 +2746,7 @@ __isl_take isl_qpolynomial *qp) { int i, j; - int d; + isl_size div_pos; int len; int skip; int *active = NULL; @@ -2584,25 +2760,27 @@ if (qp->div->n_row == 0) return qp; - d = isl_space_dim(qp->dim, isl_dim_all); + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) + return isl_qpolynomial_free(qp); len = qp->div->n_col - 2; ctx = isl_qpolynomial_get_ctx(qp); active = isl_calloc_array(ctx, int, len); if (!active) goto error; - if (up_set_active(qp->upoly, active, len) < 0) + if (poly_set_active(qp->poly, active, len) < 0) goto error; for (i = qp->div->n_row - 1; i >= 0; --i) { - if (!active[d + i]) { + if (!active[div_pos + i]) { redundant = 1; continue; } for (j = 0; j < i; ++j) { - if (isl_int_is_zero(qp->div->row[i][2 + d + j])) + if (isl_int_is_zero(qp->div->row[i][2 + div_pos + j])) continue; - active[d + j] = 1; + active[div_pos + j] = 1; break; } } @@ -2616,24 +2794,24 @@ if (!reordering) goto error; - for (i = 0; i < d; ++i) + for (i = 0; i < div_pos; ++i) reordering[i] = i; skip = 0; n_div = qp->div->n_row; for (i = 0; i < n_div; ++i) { - if (!active[d + i]) { + if (!active[div_pos + i]) { qp->div = isl_mat_drop_rows(qp->div, i - skip, 1); qp->div = isl_mat_drop_cols(qp->div, - 2 + d + i - skip, 1); + 2 + div_pos + i - skip, 1); skip++; } - reordering[d + i] = d + i - skip; + reordering[div_pos + i] = div_pos + i - skip; } - qp->upoly = reorder(qp->upoly, reordering); + qp->poly = reorder(qp->poly, reordering); - if (!qp->upoly || !qp->div) + if (!qp->poly || !qp->div) goto error; free(active); @@ -2647,37 +2825,37 @@ return NULL; } -__isl_give struct isl_upoly *isl_upoly_drop(__isl_take struct isl_upoly *up, +__isl_give isl_poly *isl_poly_drop(__isl_take isl_poly *poly, unsigned first, unsigned n) { int i; - struct isl_upoly_rec *rec; + isl_poly_rec *rec; - if (!up) + if (!poly) return NULL; - if (n == 0 || up->var < 0 || up->var < first) - return up; - if (up->var < first + n) { - up = replace_by_constant_term(up); - return isl_upoly_drop(up, first, n); + if (n == 0 || poly->var < 0 || poly->var < first) + return poly; + if (poly->var < first + n) { + poly = replace_by_constant_term(poly); + return isl_poly_drop(poly, first, n); } - up = isl_upoly_cow(up); - if (!up) + poly = isl_poly_cow(poly); + if (!poly) return NULL; - up->var -= n; - rec = isl_upoly_as_rec(up); + poly->var -= n; + rec = isl_poly_as_rec(poly); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - rec->p[i] = isl_upoly_drop(rec->p[i], first, n); + rec->p[i] = isl_poly_drop(rec->p[i], first, n); if (!rec->p[i]) goto error; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } @@ -2692,8 +2870,7 @@ isl_die(isl_qpolynomial_get_ctx(qp), isl_error_invalid, "cannot set name of output/set dimension", return isl_qpolynomial_free(qp)); - if (type == isl_dim_in) - type = isl_dim_set; + type = domain_type(type); qp->dim = isl_space_set_dim_name(qp->dim, type, pos, s); if (!qp->dim) goto error; @@ -2707,14 +2884,17 @@ __isl_take isl_qpolynomial *qp, enum isl_dim_type type, unsigned first, unsigned n) { + isl_size offset; + if (!qp) return NULL; if (type == isl_dim_out) isl_die(qp->dim->ctx, isl_error_invalid, "cannot drop output/set dimension", goto error); - if (type == isl_dim_in) - type = isl_dim_set; + if (isl_qpolynomial_check_range(qp, type, first, n) < 0) + return isl_qpolynomial_free(qp); + type = domain_type(type); if (n == 0 && !isl_space_is_named_or_nested(qp->dim, type)) return qp; @@ -2722,8 +2902,6 @@ if (!qp) return NULL; - isl_assert(qp->dim->ctx, first + n <= isl_space_dim(qp->dim, type), - goto error); isl_assert(qp->dim->ctx, type == isl_dim_param || type == isl_dim_set, goto error); @@ -2731,15 +2909,17 @@ if (!qp->dim) goto error; - if (type == isl_dim_set) - first += isl_space_dim(qp->dim, isl_dim_param); + offset = isl_qpolynomial_domain_var_offset(qp, type); + if (offset < 0) + goto error; + first += offset; qp->div = isl_mat_drop_cols(qp->div, 2 + first, n); if (!qp->div) goto error; - qp->upoly = isl_upoly_drop(qp->upoly, first, n); - if (!qp->upoly) + qp->poly = isl_poly_drop(qp->poly, first, n); + if (!qp->poly) goto error; return qp; @@ -2755,10 +2935,12 @@ __isl_take isl_qpolynomial *qp) { isl_space *space; - unsigned n; - int involves; + isl_size n; + isl_bool involves; n = isl_qpolynomial_dim(qp, isl_dim_in); + if (n < 0) + return isl_qpolynomial_free(qp); involves = isl_qpolynomial_involves_dims(qp, isl_dim_in, 0, n); if (involves < 0) return isl_qpolynomial_free(qp); @@ -2780,7 +2962,7 @@ isl_int denom; unsigned total; unsigned n_div; - struct isl_upoly *up; + isl_poly *poly; if (!eq) goto error; @@ -2796,7 +2978,7 @@ if (!qp->div) goto error; - total = 1 + isl_space_dim(eq->dim, isl_dim_all); + total = isl_basic_set_offset(eq, isl_dim_div); n_div = eq->n_div; isl_int_init(denom); for (i = 0; i < eq->n_eq; ++i) { @@ -2817,14 +2999,14 @@ isl_int_abs(denom, eq->eq[i][j]); isl_int_set_si(eq->eq[i][j], 0); - up = isl_upoly_from_affine(qp->dim->ctx, + poly = isl_poly_from_affine(qp->dim->ctx, eq->eq[i], denom, total); - qp->upoly = isl_upoly_subs(qp->upoly, j - 1, 1, &up); - isl_upoly_free(up); + qp->poly = isl_poly_subs(qp->poly, j - 1, 1, &poly); + isl_poly_free(poly); } isl_int_clear(denom); - if (!qp->upoly) + if (!qp->poly) goto error; isl_basic_set_free(eq); @@ -2852,32 +3034,6 @@ error: isl_basic_set_free(eq); isl_qpolynomial_free(qp); - return NULL; -} - -static __isl_give isl_basic_set *add_div_constraints( - __isl_take isl_basic_set *bset, __isl_take isl_mat *div) -{ - int i; - unsigned total; - - if (!bset || !div) - goto error; - - bset = isl_basic_set_extend_constraints(bset, 0, 2 * div->n_row); - if (!bset) - goto error; - total = isl_basic_set_total_dim(bset); - for (i = 0; i < div->n_row; ++i) - if (isl_basic_set_add_div_constraints_var(bset, - total - div->n_row + i, div->row[i]) < 0) - goto error; - - isl_mat_free(div); - return bset; -error: - isl_mat_free(div); - isl_basic_set_free(bset); return NULL; } @@ -2889,26 +3045,14 @@ __isl_give isl_qpolynomial *isl_qpolynomial_gist( __isl_take isl_qpolynomial *qp, __isl_take isl_set *context) { + isl_local_space *ls; isl_basic_set *aff; - if (!qp) - goto error; - if (qp->div->n_row > 0) { - isl_basic_set *bset; - context = isl_set_add_dims(context, isl_dim_set, - qp->div->n_row); - bset = isl_basic_set_universe(isl_set_get_space(context)); - bset = add_div_constraints(bset, isl_mat_copy(qp->div)); - context = isl_set_intersect(context, - isl_set_from_basic_set(bset)); - } + ls = isl_qpolynomial_get_domain_local_space(qp); + context = isl_local_space_lift_set(ls, context); aff = isl_set_affine_hull(context); return isl_qpolynomial_substitute_equalities_lifted(qp, aff); -error: - isl_qpolynomial_free(qp); - isl_set_free(context); - return NULL; } __isl_give isl_qpolynomial *isl_qpolynomial_gist_params( @@ -2920,29 +3064,23 @@ return isl_qpolynomial_gist(qp, dom_context); } -__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial( - __isl_take isl_qpolynomial *qp) +/* Return a zero isl_qpolynomial in the given space. + * + * This is a helper function for isl_pw_*_as_* that ensures a uniform + * interface over all piecewise types. + */ +static __isl_give isl_qpolynomial *isl_qpolynomial_zero_in_space( + __isl_take isl_space *space) { - isl_set *dom; - - if (!qp) - return NULL; - if (isl_qpolynomial_is_zero(qp)) { - isl_space *dim = isl_qpolynomial_get_space(qp); - isl_qpolynomial_free(qp); - return isl_pw_qpolynomial_zero(dim); - } - - dom = isl_set_universe(isl_qpolynomial_get_domain_space(qp)); - return isl_pw_qpolynomial_alloc(dom, qp); + return isl_qpolynomial_zero_on_domain(isl_space_domain(space)); } #define isl_qpolynomial_involves_nan isl_qpolynomial_is_nan #undef PW #define PW isl_pw_qpolynomial -#undef EL -#define EL isl_qpolynomial +#undef BASE +#define BASE qpolynomial #undef EL_IS_ZERO #define EL_IS_ZERO is_zero #undef ZERO @@ -2957,13 +3095,10 @@ #define NO_PULLBACK #include +#include -#undef UNION -#define UNION isl_union_pw_qpolynomial -#undef PART -#define PART isl_pw_qpolynomial -#undef PARTS -#define PARTS pw_qpolynomial +#undef BASE +#define BASE pw_qpolynomial #include #include @@ -3055,46 +3190,49 @@ return NULL; } -__isl_give isl_val *isl_upoly_eval(__isl_take struct isl_upoly *up, +__isl_give isl_val *isl_poly_eval(__isl_take isl_poly *poly, __isl_take isl_vec *vec) { int i; - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; isl_val *res; isl_val *base; - if (isl_upoly_is_cst(up)) { + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + goto error; + if (is_cst) { isl_vec_free(vec); - res = isl_upoly_get_constant_val(up); - isl_upoly_free(up); + res = isl_poly_get_constant_val(poly); + isl_poly_free(poly); return res; } - rec = isl_upoly_as_rec(up); - if (!rec) + rec = isl_poly_as_rec(poly); + if (!rec || !vec) goto error; - isl_assert(up->ctx, rec->n >= 1, goto error); + isl_assert(poly->ctx, rec->n >= 1, goto error); - base = isl_val_rat_from_isl_int(up->ctx, - vec->el[1 + up->var], vec->el[0]); + base = isl_val_rat_from_isl_int(poly->ctx, + vec->el[1 + poly->var], vec->el[0]); - res = isl_upoly_eval(isl_upoly_copy(rec->p[rec->n - 1]), + res = isl_poly_eval(isl_poly_copy(rec->p[rec->n - 1]), isl_vec_copy(vec)); for (i = rec->n - 2; i >= 0; --i) { res = isl_val_mul(res, isl_val_copy(base)); - res = isl_val_add(res, - isl_upoly_eval(isl_upoly_copy(rec->p[i]), + res = isl_val_add(res, isl_poly_eval(isl_poly_copy(rec->p[i]), isl_vec_copy(vec))); } isl_val_free(base); - isl_upoly_free(up); + isl_poly_free(poly); isl_vec_free(vec); return res; error: - isl_upoly_free(up); + isl_poly_free(poly); isl_vec_free(vec); return NULL; } @@ -3128,26 +3266,10 @@ goto error; if (is_void) return eval_void(qp, pnt); - - if (qp->div->n_row == 0) - ext = isl_vec_copy(pnt->vec); - else { - int i; - unsigned dim = isl_space_dim(qp->dim, isl_dim_all); - ext = isl_vec_alloc(qp->dim->ctx, 1 + dim + qp->div->n_row); - if (!ext) - goto error; - isl_seq_cpy(ext->el, pnt->vec->el, pnt->vec->size); - for (i = 0; i < qp->div->n_row; ++i) { - isl_seq_inner_product(qp->div->row[i] + 1, ext->el, - 1 + dim + i, &ext->el[1+dim+i]); - isl_int_fdiv_q(ext->el[1+dim+i], ext->el[1+dim+i], - qp->div->row[i][0]); - } - } + ext = isl_local_extend_point_vec(qp->div, isl_vec_copy(pnt->vec)); - v = isl_upoly_eval(isl_upoly_copy(qp->upoly), ext); + v = isl_poly_eval(isl_poly_copy(qp->poly), ext); isl_qpolynomial_free(qp); isl_point_free(pnt); @@ -3159,8 +3281,7 @@ return NULL; } -int isl_upoly_cmp(__isl_keep struct isl_upoly_cst *cst1, - __isl_keep struct isl_upoly_cst *cst2) +int isl_poly_cmp(__isl_keep isl_poly_cst *cst1, __isl_keep isl_poly_cst *cst2) { int cmp; isl_int t; @@ -3186,17 +3307,15 @@ isl_die(qp->div->ctx, isl_error_invalid, "cannot insert output/set dimensions", goto error); - if (type == isl_dim_in) - type = isl_dim_set; + if (isl_qpolynomial_check_range(qp, type, first, 0) < 0) + return isl_qpolynomial_free(qp); + type = domain_type(type); if (n == 0 && !isl_space_is_named_or_nested(qp->dim, type)) return qp; qp = isl_qpolynomial_cow(qp); if (!qp) return NULL; - - isl_assert(qp->div->ctx, first <= isl_space_dim(qp->dim, type), - goto error); g_pos = pos(qp->dim, type) + first; @@ -3212,9 +3331,9 @@ goto error; for (i = 0; i < total - g_pos; ++i) exp[i] = i + n; - qp->upoly = expand(qp->upoly, exp, g_pos); + qp->poly = expand(qp->poly, exp, g_pos); free(exp); - if (!qp->upoly) + if (!qp->poly) goto error; } @@ -3231,9 +3350,11 @@ __isl_give isl_qpolynomial *isl_qpolynomial_add_dims( __isl_take isl_qpolynomial *qp, enum isl_dim_type type, unsigned n) { - unsigned pos; + isl_size pos; pos = isl_qpolynomial_dim(qp, type); + if (pos < 0) + return isl_qpolynomial_free(qp); return isl_qpolynomial_insert_dims(qp, type, pos, n); } @@ -3242,9 +3363,11 @@ __isl_take isl_pw_qpolynomial *pwqp, enum isl_dim_type type, unsigned n) { - unsigned pos; + isl_size pos; pos = isl_pw_qpolynomial_dim(pwqp, type); + if (pos < 0) + return isl_pw_qpolynomial_free(pwqp); return isl_pw_qpolynomial_insert_dims(pwqp, type, pos, n); } @@ -3298,6 +3421,8 @@ isl_die(qp->dim->ctx, isl_error_invalid, "cannot move output/set dimension", goto error); + if (isl_qpolynomial_check_range(qp, src_type, src_pos, n) < 0) + return isl_qpolynomial_free(qp); if (dst_type == isl_dim_in) dst_type = isl_dim_set; if (src_type == isl_dim_in) @@ -3311,9 +3436,6 @@ qp = isl_qpolynomial_cow(qp); if (!qp) return NULL; - - isl_assert(qp->dim->ctx, src_pos + n <= isl_space_dim(qp->dim, src_type), - goto error); g_dst_pos = pos(qp->dim, dst_type) + dst_pos; g_src_pos = pos(qp->dim, src_type) + src_pos; @@ -3332,9 +3454,9 @@ if (!reordering) goto error; - qp->upoly = reorder(qp->upoly, reordering); + qp->poly = reorder(qp->poly, reordering); free(reordering); - if (!qp->upoly) + if (!qp->poly) goto error; qp->dim = isl_space_move_dims(qp->dim, dst_type, dst_pos, src_type, src_pos, n); @@ -3347,36 +3469,37 @@ return NULL; } -__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_space *dim, - isl_int *f, isl_int denom) +__isl_give isl_qpolynomial *isl_qpolynomial_from_affine( + __isl_take isl_space *space, isl_int *f, isl_int denom) { - struct isl_upoly *up; + isl_size d; + isl_poly *poly; - dim = isl_space_domain(dim); - if (!dim) + space = isl_space_domain(space); + if (!space) return NULL; - up = isl_upoly_from_affine(dim->ctx, f, denom, - 1 + isl_space_dim(dim, isl_dim_all)); + d = isl_space_dim(space, isl_dim_all); + poly = d < 0 ? NULL : isl_poly_from_affine(space->ctx, f, denom, 1 + d); - return isl_qpolynomial_alloc(dim, 0, up); + return isl_qpolynomial_alloc(space, 0, poly); } __isl_give isl_qpolynomial *isl_qpolynomial_from_aff(__isl_take isl_aff *aff) { isl_ctx *ctx; - struct isl_upoly *up; + isl_poly *poly; isl_qpolynomial *qp; if (!aff) return NULL; ctx = isl_aff_get_ctx(aff); - up = isl_upoly_from_affine(ctx, aff->v->el + 1, aff->v->el[0], + poly = isl_poly_from_affine(ctx, aff->v->el + 1, aff->v->el[0], aff->v->size - 1); qp = isl_qpolynomial_alloc(isl_aff_get_domain_space(aff), - aff->ls->div->n_row, up); + aff->ls->div->n_row, poly); if (!qp) goto error; @@ -3439,7 +3562,7 @@ __isl_keep isl_qpolynomial **subs) { int i; - struct isl_upoly **ups; + isl_poly **polys; if (n == 0) return qp; @@ -3452,15 +3575,13 @@ isl_die(qp->dim->ctx, isl_error_invalid, "cannot substitute output/set dimension", goto error); - if (type == isl_dim_in) - type = isl_dim_set; + if (isl_qpolynomial_check_range(qp, type, first, n) < 0) + return isl_qpolynomial_free(qp); + type = domain_type(type); for (i = 0; i < n; ++i) if (!subs[i]) goto error; - - isl_assert(qp->dim->ctx, first + n <= isl_space_dim(qp->dim, type), - goto error); for (i = 0; i < n; ++i) isl_assert(qp->dim->ctx, isl_space_is_equal(qp->dim, subs[i]->dim), @@ -3472,17 +3593,17 @@ first += pos(qp->dim, type); - ups = isl_alloc_array(qp->dim->ctx, struct isl_upoly *, n); - if (!ups) + polys = isl_alloc_array(qp->dim->ctx, struct isl_poly *, n); + if (!polys) goto error; for (i = 0; i < n; ++i) - ups[i] = subs[i]->upoly; + polys[i] = subs[i]->poly; - qp->upoly = isl_upoly_subs(qp->upoly, first, n, ups); + qp->poly = isl_poly_subs(qp->poly, first, n, polys); - free(ups); + free(polys); - if (!qp->upoly) + if (!qp->poly) goto error; return qp; @@ -3501,8 +3622,8 @@ isl_stat (*fn)(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, void *user), void *user) { - isl_space *dim; - isl_mat *div; + isl_space *space; + isl_local_space *ls; isl_qpolynomial *poly; if (!qp || !bset) @@ -3511,43 +3632,50 @@ return fn(isl_basic_set_copy(bset), isl_qpolynomial_copy(qp), user); - div = isl_mat_copy(qp->div); - dim = isl_space_copy(qp->dim); - dim = isl_space_add_dims(dim, isl_dim_set, qp->div->n_row); - poly = isl_qpolynomial_alloc(dim, 0, isl_upoly_copy(qp->upoly)); + space = isl_space_copy(qp->dim); + space = isl_space_add_dims(space, isl_dim_set, qp->div->n_row); + poly = isl_qpolynomial_alloc(space, 0, isl_poly_copy(qp->poly)); bset = isl_basic_set_copy(bset); - bset = isl_basic_set_add_dims(bset, isl_dim_set, qp->div->n_row); - bset = add_div_constraints(bset, div); + ls = isl_qpolynomial_get_domain_local_space(qp); + bset = isl_local_space_lift_basic_set(ls, bset); return fn(bset, poly, user); } /* Return total degree in variables first (inclusive) up to last (exclusive). */ -int isl_upoly_degree(__isl_keep struct isl_upoly *up, int first, int last) +int isl_poly_degree(__isl_keep isl_poly *poly, int first, int last) { int deg = -1; int i; - struct isl_upoly_rec *rec; - - if (!up) + isl_bool is_zero, is_cst; + isl_poly_rec *rec; + + is_zero = isl_poly_is_zero(poly); + if (is_zero < 0) return -2; - if (isl_upoly_is_zero(up)) + if (is_zero) return -1; - if (isl_upoly_is_cst(up) || up->var < first) + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return -2; + if (is_cst || poly->var < first) return 0; - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) return -2; for (i = 0; i < rec->n; ++i) { int d; - if (isl_upoly_is_zero(rec->p[i])) + is_zero = isl_poly_is_zero(rec->p[i]); + if (is_zero < 0) + return -2; + if (is_zero) continue; - d = isl_upoly_degree(rec->p[i], first, last); - if (up->var < last) + d = isl_poly_degree(rec->p[i], first, last); + if (poly->var < last) d += i; if (d > deg) deg = d; @@ -3561,61 +3689,64 @@ int isl_qpolynomial_degree(__isl_keep isl_qpolynomial *poly) { unsigned ovar; - unsigned nvar; + isl_size nvar; if (!poly) return -2; ovar = isl_space_offset(poly->dim, isl_dim_set); nvar = isl_space_dim(poly->dim, isl_dim_set); - return isl_upoly_degree(poly->upoly, ovar, ovar + nvar); + if (nvar < 0) + return -2; + return isl_poly_degree(poly->poly, ovar, ovar + nvar); } -__isl_give struct isl_upoly *isl_upoly_coeff(__isl_keep struct isl_upoly *up, +__isl_give isl_poly *isl_poly_coeff(__isl_keep isl_poly *poly, unsigned pos, int deg) { int i; - struct isl_upoly_rec *rec; + isl_bool is_cst; + isl_poly_rec *rec; - if (!up) + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) return NULL; - - if (isl_upoly_is_cst(up) || up->var < pos) { + if (is_cst || poly->var < pos) { if (deg == 0) - return isl_upoly_copy(up); + return isl_poly_copy(poly); else - return isl_upoly_zero(up->ctx); + return isl_poly_zero(poly->ctx); } - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) return NULL; - if (up->var == pos) { + if (poly->var == pos) { if (deg < rec->n) - return isl_upoly_copy(rec->p[deg]); + return isl_poly_copy(rec->p[deg]); else - return isl_upoly_zero(up->ctx); + return isl_poly_zero(poly->ctx); } - up = isl_upoly_copy(up); - up = isl_upoly_cow(up); - rec = isl_upoly_as_rec(up); + poly = isl_poly_copy(poly); + poly = isl_poly_cow(poly); + rec = isl_poly_as_rec(poly); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - struct isl_upoly *t; - t = isl_upoly_coeff(rec->p[i], pos, deg); + isl_poly *t; + t = isl_poly_coeff(rec->p[i], pos, deg); if (!t) goto error; - isl_upoly_free(rec->p[i]); + isl_poly_free(rec->p[i]); rec->p[i] = t; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } @@ -3626,7 +3757,7 @@ enum isl_dim_type type, unsigned t_pos, int deg) { unsigned g_pos; - struct isl_upoly *up; + isl_poly *poly; isl_qpolynomial *c; if (!qp) @@ -3636,16 +3767,15 @@ isl_die(qp->div->ctx, isl_error_invalid, "output/set dimension does not have a coefficient", return NULL); - if (type == isl_dim_in) - type = isl_dim_set; - - isl_assert(qp->div->ctx, t_pos < isl_space_dim(qp->dim, type), - return NULL); + if (isl_qpolynomial_check_range(qp, type, t_pos, 1) < 0) + return NULL; + type = domain_type(type); g_pos = pos(qp->dim, type) + t_pos; - up = isl_upoly_coeff(qp->upoly, g_pos, deg); + poly = isl_poly_coeff(qp->poly, g_pos, deg); - c = isl_qpolynomial_alloc(isl_space_copy(qp->dim), qp->div->n_row, up); + c = isl_qpolynomial_alloc(isl_space_copy(qp->dim), + qp->div->n_row, poly); if (!c) return NULL; isl_mat_free(c->div); @@ -3662,49 +3792,56 @@ * last (exclusive) by inserting powers of variable first. * Variable first is assumed not to appear in the input. */ -__isl_give struct isl_upoly *isl_upoly_homogenize( - __isl_take struct isl_upoly *up, int deg, int target, - int first, int last) +__isl_give isl_poly *isl_poly_homogenize(__isl_take isl_poly *poly, int deg, + int target, int first, int last) { int i; - struct isl_upoly_rec *rec; - - if (!up) - return NULL; - if (isl_upoly_is_zero(up)) - return up; + isl_bool is_zero, is_cst; + isl_poly_rec *rec; + + is_zero = isl_poly_is_zero(poly); + if (is_zero < 0) + return isl_poly_free(poly); + if (is_zero) + return poly; if (deg == target) - return up; - if (isl_upoly_is_cst(up) || up->var < first) { - struct isl_upoly *hom; - - hom = isl_upoly_var_pow(up->ctx, first, target - deg); + return poly; + is_cst = isl_poly_is_cst(poly); + if (is_cst < 0) + return isl_poly_free(poly); + if (is_cst || poly->var < first) { + isl_poly *hom; + + hom = isl_poly_var_pow(poly->ctx, first, target - deg); if (!hom) goto error; - rec = isl_upoly_as_rec(hom); - rec->p[target - deg] = isl_upoly_mul(rec->p[target - deg], up); + rec = isl_poly_as_rec(hom); + rec->p[target - deg] = isl_poly_mul(rec->p[target - deg], poly); return hom; } - up = isl_upoly_cow(up); - rec = isl_upoly_as_rec(up); + poly = isl_poly_cow(poly); + rec = isl_poly_as_rec(poly); if (!rec) goto error; for (i = 0; i < rec->n; ++i) { - if (isl_upoly_is_zero(rec->p[i])) + is_zero = isl_poly_is_zero(rec->p[i]); + if (is_zero < 0) + return isl_poly_free(poly); + if (is_zero) continue; - rec->p[i] = isl_upoly_homogenize(rec->p[i], - up->var < last ? deg + i : i, target, + rec->p[i] = isl_poly_homogenize(rec->p[i], + poly->var < last ? deg + i : i, target, first, last); if (!rec->p[i]) goto error; } - return up; + return poly; error: - isl_upoly_free(up); + isl_poly_free(poly); return NULL; } @@ -3715,7 +3852,7 @@ __isl_take isl_qpolynomial *poly) { unsigned ovar; - unsigned nvar; + isl_size nvar; int deg = isl_qpolynomial_degree(poly); if (deg < -1) @@ -3728,9 +3865,10 @@ ovar = isl_space_offset(poly->dim, isl_dim_set); nvar = isl_space_dim(poly->dim, isl_dim_set); - poly->upoly = isl_upoly_homogenize(poly->upoly, 0, deg, - ovar, ovar + nvar); - if (!poly->upoly) + if (nvar < 0) + return isl_qpolynomial_free(poly); + poly->poly = isl_poly_homogenize(poly->poly, 0, deg, ovar, ovar + nvar); + if (!poly->poly) goto error; return poly; @@ -3739,31 +3877,33 @@ return NULL; } -__isl_give isl_term *isl_term_alloc(__isl_take isl_space *dim, +__isl_give isl_term *isl_term_alloc(__isl_take isl_space *space, __isl_take isl_mat *div) { isl_term *term; + isl_size d; int n; - if (!dim || !div) + d = isl_space_dim(space, isl_dim_all); + if (d < 0 || !div) goto error; - n = isl_space_dim(dim, isl_dim_all) + div->n_row; + n = d + div->n_row; - term = isl_calloc(dim->ctx, struct isl_term, + term = isl_calloc(space->ctx, struct isl_term, sizeof(struct isl_term) + (n - 1) * sizeof(int)); if (!term) goto error; term->ref = 1; - term->dim = dim; + term->dim = space; term->div = div; isl_int_init(term->n); isl_int_init(term->d); return term; error: - isl_space_free(dim); + isl_space_free(space); isl_mat_free(div); return NULL; } @@ -3781,13 +3921,12 @@ { int i; isl_term *dup; - unsigned total; + isl_size total; - if (!term) + total = isl_term_dim(term, isl_dim_all); + if (total < 0) return NULL; - total = isl_space_dim(term->dim, isl_dim_all) + term->div->n_row; - dup = isl_term_alloc(isl_space_copy(term->dim), isl_mat_copy(term->div)); if (!dup) return NULL; @@ -3812,34 +3951,69 @@ return isl_term_dup(term); } -void isl_term_free(__isl_take isl_term *term) +__isl_null isl_term *isl_term_free(__isl_take isl_term *term) { if (!term) - return; + return NULL; if (--term->ref > 0) - return; + return NULL; isl_space_free(term->dim); isl_mat_free(term->div); isl_int_clear(term->n); isl_int_clear(term->d); free(term); + + return NULL; } -unsigned isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type) +isl_size isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type) { + isl_size dim; + if (!term) - return 0; + return isl_size_error; switch (type) { case isl_dim_param: case isl_dim_in: case isl_dim_out: return isl_space_dim(term->dim, type); case isl_dim_div: return term->div->n_row; - case isl_dim_all: return isl_space_dim(term->dim, isl_dim_all) + - term->div->n_row; - default: return 0; + case isl_dim_all: dim = isl_space_dim(term->dim, isl_dim_all); + if (dim < 0) + return isl_size_error; + return dim + term->div->n_row; + default: return isl_size_error; + } +} + +/* Return the space of "term". + */ +static __isl_keep isl_space *isl_term_peek_space(__isl_keep isl_term *term) +{ + return term ? term->dim : NULL; +} + +/* Return the offset of the first variable of type "type" within + * the variables of "term". + */ +static isl_size isl_term_offset(__isl_keep isl_term *term, + enum isl_dim_type type) +{ + isl_space *space; + + space = isl_term_peek_space(term); + if (!space) + return isl_size_error; + + switch (type) { + case isl_dim_param: + case isl_dim_set: return isl_space_offset(space, type); + case isl_dim_div: return isl_space_dim(space, isl_dim_all); + default: + isl_die(isl_term_get_ctx(term), isl_error_invalid, + "invalid dimension type", return isl_size_error); } } @@ -3866,20 +4040,23 @@ term->n, term->d); } -int isl_term_get_exp(__isl_keep isl_term *term, +#undef TYPE +#define TYPE isl_term +static +#include "check_type_range_templ.c" + +isl_size isl_term_get_exp(__isl_keep isl_term *term, enum isl_dim_type type, unsigned pos) { - if (!term) - return -1; - - isl_assert(term->dim->ctx, pos < isl_term_dim(term, type), return -1); + isl_size offset; - if (type >= isl_dim_set) - pos += isl_space_dim(term->dim, isl_dim_param); - if (type >= isl_dim_div) - pos += isl_space_dim(term->dim, isl_dim_set); + if (isl_term_check_range(term, type, pos, 1) < 0) + return isl_size_error; + offset = isl_term_offset(term, type); + if (offset < 0) + return isl_size_error; - return term->pow[pos]; + return term->pow[offset + pos]; } __isl_give isl_aff *isl_term_get_div(__isl_keep isl_term *term, unsigned pos) @@ -3887,11 +4064,8 @@ isl_local_space *ls; isl_aff *aff; - if (!term) + if (isl_term_check_range(term, isl_dim_div, pos, 1) < 0) return NULL; - - isl_assert(term->dim->ctx, pos < isl_term_dim(term, isl_dim_div), - return NULL); ls = isl_local_space_alloc_div(isl_space_copy(term->dim), isl_mat_copy(term->div)); @@ -3906,26 +4080,37 @@ return aff; } -__isl_give isl_term *isl_upoly_foreach_term(__isl_keep struct isl_upoly *up, +__isl_give isl_term *isl_poly_foreach_term(__isl_keep isl_poly *poly, isl_stat (*fn)(__isl_take isl_term *term, void *user), __isl_take isl_term *term, void *user) { int i; - struct isl_upoly_rec *rec; + isl_bool is_zero, is_bad, is_cst; + isl_poly_rec *rec; - if (!up || !term) + is_zero = isl_poly_is_zero(poly); + if (is_zero < 0 || !term) goto error; - if (isl_upoly_is_zero(up)) + if (is_zero) return term; - isl_assert(up->ctx, !isl_upoly_is_nan(up), goto error); - isl_assert(up->ctx, !isl_upoly_is_infty(up), goto error); - isl_assert(up->ctx, !isl_upoly_is_neginfty(up), goto error); - - if (isl_upoly_is_cst(up)) { - struct isl_upoly_cst *cst; - cst = isl_upoly_as_cst(up); + is_cst = isl_poly_is_cst(poly); + is_bad = isl_poly_is_nan(poly); + if (is_bad >= 0 && !is_bad) + is_bad = isl_poly_is_infty(poly); + if (is_bad >= 0 && !is_bad) + is_bad = isl_poly_is_neginfty(poly); + if (is_cst < 0 || is_bad < 0) + return isl_term_free(term); + if (is_bad) + isl_die(isl_term_get_ctx(term), isl_error_invalid, + "cannot handle NaN/infty polynomial", + return isl_term_free(term)); + + if (is_cst) { + isl_poly_cst *cst; + cst = isl_poly_as_cst(poly); if (!cst) goto error; term = isl_term_cow(term); @@ -3938,7 +4123,7 @@ return term; } - rec = isl_upoly_as_rec(up); + rec = isl_poly_as_rec(poly); if (!rec) goto error; @@ -3946,12 +4131,15 @@ term = isl_term_cow(term); if (!term) goto error; - term->pow[up->var] = i; - term = isl_upoly_foreach_term(rec->p[i], fn, term, user); + term->pow[poly->var] = i; + term = isl_poly_foreach_term(rec->p[i], fn, term, user); if (!term) goto error; } - term->pow[up->var] = 0; + term = isl_term_cow(term); + if (!term) + return NULL; + term->pow[poly->var] = 0; return term; error: @@ -3971,7 +4159,7 @@ if (!term) return isl_stat_error; - term = isl_upoly_foreach_term(qp->upoly, fn, term, user); + term = isl_poly_foreach_term(qp->poly, fn, term, user); isl_term_free(term); @@ -3980,24 +4168,27 @@ __isl_give isl_qpolynomial *isl_qpolynomial_from_term(__isl_take isl_term *term) { - struct isl_upoly *up; + isl_poly *poly; isl_qpolynomial *qp; - int i, n; - + int i; + isl_size n; + + n = isl_term_dim(term, isl_dim_all); + if (n < 0) + term = isl_term_free(term); if (!term) return NULL; - n = isl_space_dim(term->dim, isl_dim_all) + term->div->n_row; - - up = isl_upoly_rat_cst(term->dim->ctx, term->n, term->d); + poly = isl_poly_rat_cst(term->dim->ctx, term->n, term->d); for (i = 0; i < n; ++i) { if (!term->pow[i]) continue; - up = isl_upoly_mul(up, - isl_upoly_var_pow(term->dim->ctx, i, term->pow[i])); + poly = isl_poly_mul(poly, + isl_poly_var_pow(term->dim->ctx, i, term->pow[i])); } - qp = isl_qpolynomial_alloc(isl_space_copy(term->dim), term->div->n_row, up); + qp = isl_qpolynomial_alloc(isl_space_copy(term->dim), + term->div->n_row, poly); if (!qp) goto error; isl_mat_free(qp->div); @@ -4014,17 +4205,17 @@ } __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp, - __isl_take isl_space *dim) + __isl_take isl_space *space) { int i; int extra; - unsigned total; + isl_size total, d_set, d_qp; - if (!qp || !dim) + if (!qp || !space) goto error; - if (isl_space_is_equal(qp->dim, dim)) { - isl_space_free(dim); + if (isl_space_is_equal(qp->dim, space)) { + isl_space_free(space); return qp; } @@ -4032,9 +4223,12 @@ if (!qp) goto error; - extra = isl_space_dim(dim, isl_dim_set) - - isl_space_dim(qp->dim, isl_dim_set); + d_set = isl_space_dim(space, isl_dim_set); + d_qp = isl_qpolynomial_domain_dim(qp, isl_dim_set); + extra = d_set - d_qp; total = isl_space_dim(qp->dim, isl_dim_all); + if (d_set < 0 || d_qp < 0 || total < 0) + goto error; if (qp->div->n_row) { int *exp; @@ -4043,9 +4237,9 @@ goto error; for (i = 0; i < qp->div->n_row; ++i) exp[i] = extra + i; - qp->upoly = expand(qp->upoly, exp, total); + qp->poly = expand(qp->poly, exp, total); free(exp); - if (!qp->upoly) + if (!qp->poly) goto error; } qp->div = isl_mat_insert_cols(qp->div, 2 + total, extra); @@ -4055,11 +4249,11 @@ isl_seq_clr(qp->div->row[i] + 2 + total, extra); isl_space_free(qp->dim); - qp->dim = dim; + qp->dim = space; return qp; error: - isl_space_free(dim); + isl_space_free(space); isl_qpolynomial_free(qp); return NULL; } @@ -4072,14 +4266,14 @@ { int *active = NULL; int i; - int d; - unsigned nparam; - unsigned nvar; + isl_size d; + isl_size nparam; + isl_size nvar; - if (!set || !qp) + d = isl_set_dim(set, isl_dim_all); + if (d < 0 || !qp) goto error; - d = isl_space_dim(set->dim, isl_dim_all); active = isl_calloc_array(set->ctx, int, d); if (set_active(qp, active) < 0) goto error; @@ -4093,8 +4287,10 @@ return set; } - nparam = isl_space_dim(set->dim, isl_dim_param); - nvar = isl_space_dim(set->dim, isl_dim_set); + nparam = isl_set_dim(set, isl_dim_param); + nvar = isl_set_dim(set, isl_dim_set); + if (nparam < 0 || nvar < 0) + goto error; for (i = 0; i < nparam; ++i) { if (active[i]) continue; @@ -4146,11 +4342,15 @@ __isl_take isl_qpolynomial *qp, __isl_take isl_set *set, int max) { struct isl_opt_data data = { NULL, 1, NULL, max }; + isl_bool is_cst; if (!set || !qp) goto error; - if (isl_upoly_is_cst(qp->upoly)) { + is_cst = isl_poly_is_cst(qp->poly); + if (is_cst < 0) + goto error; + if (is_cst) { isl_set_free(set); data.opt = isl_qpolynomial_get_constant_val(qp); isl_qpolynomial_free(qp); @@ -4182,7 +4382,7 @@ int i; int n_sub; isl_ctx *ctx; - struct isl_upoly **subs; + isl_poly **subs; isl_mat *mat, *diag; qp = isl_qpolynomial_cow(qp); @@ -4195,22 +4395,22 @@ n_sub = morph->inv->n_row - 1; if (morph->inv->n_row != morph->inv->n_col) n_sub += qp->div->n_row; - subs = isl_calloc_array(ctx, struct isl_upoly *, n_sub); + subs = isl_calloc_array(ctx, struct isl_poly *, n_sub); if (n_sub && !subs) goto error; for (i = 0; 1 + i < morph->inv->n_row; ++i) - subs[i] = isl_upoly_from_affine(ctx, morph->inv->row[1 + i], + subs[i] = isl_poly_from_affine(ctx, morph->inv->row[1 + i], morph->inv->row[0][0], morph->inv->n_col); if (morph->inv->n_row != morph->inv->n_col) for (i = 0; i < qp->div->n_row; ++i) subs[morph->inv->n_row - 1 + i] = - isl_upoly_var_pow(ctx, morph->inv->n_col - 1 + i, 1); + isl_poly_var_pow(ctx, morph->inv->n_col - 1 + i, 1); - qp->upoly = isl_upoly_subs(qp->upoly, 0, n_sub, subs); + qp->poly = isl_poly_subs(qp->poly, 0, n_sub, subs); for (i = 0; i < n_sub; ++i) - isl_upoly_free(subs[i]); + isl_poly_free(subs[i]); free(subs); diag = isl_mat_diag(ctx, 1, morph->inv->row[0][0]); @@ -4221,7 +4421,7 @@ isl_space_free(qp->dim); qp->dim = isl_space_copy(morph->ran->dim); - if (!qp->upoly || !qp->div || !qp->dim) + if (!qp->poly || !qp->div || !qp->dim) goto error; isl_morph_free(morph); @@ -4239,41 +4439,6 @@ { return isl_union_pw_qpolynomial_match_bin_op(upwqp1, upwqp2, &isl_pw_qpolynomial_mul); -} - -/* Reorder the columns of the given div definitions according to the - * given reordering. - */ -static __isl_give isl_mat *reorder_divs(__isl_take isl_mat *div, - __isl_take isl_reordering *r) -{ - int i, j; - isl_mat *mat; - int extra; - - if (!div || !r) - goto error; - - extra = isl_space_dim(r->dim, isl_dim_all) + div->n_row - r->len; - mat = isl_mat_alloc(div->ctx, div->n_row, div->n_col + extra); - if (!mat) - goto error; - - for (i = 0; i < div->n_row; ++i) { - isl_seq_cpy(mat->row[i], div->row[i], 2); - isl_seq_clr(mat->row[i] + 2, mat->n_col - 2); - for (j = 0; j < r->len; ++j) - isl_int_set(mat->row[i][2 + r->pos[j]], - div->row[i][2 + j]); - } - - isl_reordering_free(r); - isl_mat_free(div); - return mat; -error: - isl_reordering_free(r); - isl_mat_free(div); - return NULL; } /* Reorder the dimension of "qp" according to the given reordering. @@ -4281,6 +4446,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_realign_domain( __isl_take isl_qpolynomial *qp, __isl_take isl_reordering *r) { + isl_space *space; + qp = isl_qpolynomial_cow(qp); if (!qp) goto error; @@ -4289,15 +4456,16 @@ if (!r) goto error; - qp->div = reorder_divs(qp->div, isl_reordering_copy(r)); + qp->div = isl_local_reorder(qp->div, isl_reordering_copy(r)); if (!qp->div) goto error; - qp->upoly = reorder(qp->upoly, r->pos); - if (!qp->upoly) + qp->poly = reorder(qp->poly, r->pos); + if (!qp->poly) goto error; - qp = isl_qpolynomial_reset_domain_space(qp, isl_space_copy(r->dim)); + space = isl_reordering_get_space(r); + qp = isl_qpolynomial_reset_domain_space(qp, space); isl_reordering_free(r); return qp; @@ -4321,10 +4489,6 @@ if (!equal_params) { isl_reordering *exp; - model = isl_space_drop_dims(model, isl_dim_in, - 0, isl_space_dim(model, isl_dim_in)); - model = isl_space_drop_dims(model, isl_dim_out, - 0, isl_space_dim(model, isl_dim_out)); exp = isl_parameter_alignment_reordering(qp->dim, model); exp = isl_reordering_extend_space(exp, isl_qpolynomial_get_domain_space(qp)); @@ -4354,18 +4518,18 @@ * f - m v >= 0 * -f + m v + (m - 1) >= 0 */ -static __isl_give isl_set *set_div_slice(__isl_take isl_space *dim, +static __isl_give isl_set *set_div_slice(__isl_take isl_space *space, __isl_keep isl_qpolynomial *qp, int div, isl_int v) { - int total; + isl_size total; isl_basic_set *bset = NULL; int k; - if (!dim || !qp) + total = isl_space_dim(space, isl_dim_all); + if (total < 0 || !qp) goto error; - total = isl_space_dim(dim, isl_dim_all); - bset = isl_basic_set_alloc_space(isl_space_copy(dim), 0, 0, 2); + bset = isl_basic_set_alloc_space(isl_space_copy(space), 0, 0, 2); k = isl_basic_set_alloc_inequality(bset); if (k < 0) @@ -4381,11 +4545,11 @@ isl_int_add(bset->ineq[k][0], bset->ineq[k][0], qp->div->row[div][0]); isl_int_sub_ui(bset->ineq[k][0], bset->ineq[k][0], 1); - isl_space_free(dim); + isl_space_free(space); return isl_set_from_basic_set(bset); error: isl_basic_set_free(bset); - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -4401,34 +4565,33 @@ struct isl_split_periods_data *data) { int i; - int total; + isl_size div_pos; isl_set *slice; - struct isl_upoly *cst; + isl_poly *cst; slice = set_div_slice(isl_set_get_space(set), qp, div, v); set = isl_set_intersect(set, slice); - if (!qp) + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) goto error; - - total = isl_space_dim(qp->dim, isl_dim_all); for (i = div + 1; i < qp->div->n_row; ++i) { - if (isl_int_is_zero(qp->div->row[i][2 + total + div])) + if (isl_int_is_zero(qp->div->row[i][2 + div_pos + div])) continue; isl_int_addmul(qp->div->row[i][1], - qp->div->row[i][2 + total + div], v); - isl_int_set_si(qp->div->row[i][2 + total + div], 0); + qp->div->row[i][2 + div_pos + div], v); + isl_int_set_si(qp->div->row[i][2 + div_pos + div], 0); } - cst = isl_upoly_rat_cst(qp->dim->ctx, v, qp->dim->ctx->one); + cst = isl_poly_rat_cst(qp->dim->ctx, v, qp->dim->ctx->one); qp = substitute_div(qp, div, cst); return split_periods(set, qp, data); error: isl_set_free(set); isl_qpolynomial_free(qp); - return -1; + return isl_stat_error; } /* Split the domain "set" such that integer division "div" @@ -4468,7 +4631,7 @@ isl_pw_qpolynomial *pwqp; struct isl_split_periods_data *data; isl_int min, max; - int total; + isl_size div_pos; isl_stat r = isl_stat_ok; data = (struct isl_split_periods_data *)user; @@ -4481,14 +4644,17 @@ data->res = isl_pw_qpolynomial_add_disjoint(data->res, pwqp); return isl_stat_ok; } + + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) + goto error; isl_int_init(min); isl_int_init(max); - total = isl_space_dim(qp->dim, isl_dim_all); for (i = 0; i < qp->div->n_row; ++i) { enum isl_lp_result lp_res; - if (isl_seq_first_non_zero(qp->div->row[i] + 2 + total, + if (isl_seq_first_non_zero(qp->div->row[i] + 2 + div_pos, qp->div->n_row) != -1) continue; @@ -4606,8 +4772,8 @@ isl_factorizer *f; isl_qpolynomial *qp; isl_pw_qpolynomial *pwqp; - unsigned nparam; - unsigned nvar; + isl_size nparam; + isl_size nvar; f = isl_basic_set_factorizer(bset); if (!f) @@ -4619,6 +4785,8 @@ nparam = isl_basic_set_dim(bset, isl_dim_param); nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nparam < 0 || nvar < 0) + bset = isl_basic_set_free(bset); space = isl_basic_set_get_space(bset); space = isl_space_params(space); @@ -4669,6 +4837,7 @@ __isl_give isl_pw_qpolynomial *(*fn)(__isl_take isl_basic_set *bset)) { isl_bool bounded; + isl_size dim; isl_morph *morph; isl_pw_qpolynomial *pwqp; @@ -4678,7 +4847,10 @@ if (isl_basic_set_plain_is_empty(bset)) return constant_on_domain(bset, 0); - if (isl_basic_set_dim(bset, isl_dim_set) == 0) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + goto error; + if (dim == 0) return constant_on_domain(bset, 1); bounded = isl_basic_set_is_bounded(bset); @@ -4715,7 +4887,7 @@ __isl_take isl_qpolynomial *qp, int down) { int i; - struct isl_upoly *s; + isl_poly *s; if (!qp) return NULL; @@ -4733,7 +4905,7 @@ isl_int_add_ui(qp->div->row[i][1], qp->div->row[i][1], 1); } - s = isl_upoly_from_affine(qp->dim->ctx, qp->div->row[i] + 1, + s = isl_poly_from_affine(qp->dim->ctx, qp->div->row[i] + 1, qp->div->row[i][0], qp->div->n_col - 1); qp = substitute_div(qp, i, s); if (!qp) @@ -4792,18 +4964,18 @@ int *signs) { int i, j; - int total; + isl_size div_pos; isl_vec *v = NULL; - struct isl_upoly *s; + isl_poly *s; qp = isl_qpolynomial_cow(qp); - if (!qp) - return NULL; + div_pos = isl_qpolynomial_domain_var_offset(qp, isl_dim_div); + if (div_pos < 0) + return isl_qpolynomial_free(qp); qp->div = isl_mat_cow(qp->div); if (!qp->div) goto error; - total = isl_space_dim(qp->dim, isl_dim_all); v = isl_vec_alloc(qp->div->ctx, qp->div->n_col - 1); for (i = 0; i < qp->div->n_row; ++i) { @@ -4816,7 +4988,7 @@ isl_int_sub_ui(v->el[0], v->el[0], 1); isl_int_submul(row[1], row[0], v->el[0]); } - for (j = 0; j < total; ++j) { + for (j = 0; j < div_pos; ++j) { if (isl_int_sgn(row[2 + j]) * signs[j] >= 0) continue; if (signs[j] < 0) @@ -4826,26 +4998,27 @@ isl_int_submul(row[2 + j], row[0], v->el[1 + j]); } for (j = 0; j < i; ++j) { - if (isl_int_sgn(row[2 + total + j]) >= 0) + if (isl_int_sgn(row[2 + div_pos + j]) >= 0) continue; - isl_int_fdiv_q(v->el[1 + total + j], - row[2 + total + j], row[0]); - isl_int_submul(row[2 + total + j], - row[0], v->el[1 + total + j]); + isl_int_fdiv_q(v->el[1 + div_pos + j], + row[2 + div_pos + j], row[0]); + isl_int_submul(row[2 + div_pos + j], + row[0], v->el[1 + div_pos + j]); } for (j = i + 1; j < qp->div->n_row; ++j) { - if (isl_int_is_zero(qp->div->row[j][2 + total + i])) + if (isl_int_is_zero(qp->div->row[j][2 + div_pos + i])) continue; isl_seq_combine(qp->div->row[j] + 1, qp->div->ctx->one, qp->div->row[j] + 1, - qp->div->row[j][2 + total + i], v->el, v->size); + qp->div->row[j][2 + div_pos + i], v->el, + v->size); } - isl_int_set_si(v->el[1 + total + i], 1); - s = isl_upoly_from_affine(qp->dim->ctx, v->el, + isl_int_set_si(v->el[1 + div_pos + i], 1); + s = isl_poly_from_affine(qp->dim->ctx, v->el, qp->div->ctx->one, v->size); - qp->upoly = isl_upoly_subs(qp->upoly, total + i, 1, &s); - isl_upoly_free(s); - if (!qp->upoly) + qp->poly = isl_poly_subs(qp->poly, div_pos + i, 1, &s); + isl_poly_free(s); + if (!qp->poly) goto error; } @@ -4968,12 +5141,16 @@ isl_space *dim; isl_vec *aff = NULL; isl_basic_map *bmap = NULL; + isl_bool is_affine; unsigned pos; unsigned n_div; if (!qp) return NULL; - if (!isl_upoly_is_affine(qp->upoly)) + is_affine = isl_poly_is_affine(qp->poly); + if (is_affine < 0) + goto error; + if (!is_affine) isl_die(qp->dim->ctx, isl_error_invalid, "input quasi-polynomial not affine", goto error); aff = isl_qpolynomial_extract_affine(qp); @@ -4990,8 +5167,7 @@ goto error; isl_seq_cpy(bmap->div[k], qp->div->row[i], qp->div->n_col); isl_int_set_si(bmap->div[k][qp->div->n_col], 0); - if (isl_basic_map_add_div_constraints(bmap, k) < 0) - goto error; + bmap = isl_basic_map_add_div_constraints(bmap, k); } k = isl_basic_map_alloc_equality(bmap); if (k < 0) diff --git a/gcc/isl/isl_polynomial_private.h b/gcc/isl/isl_polynomial_private.h index 94f5883..be5d9e9 100644 --- a/gcc/isl/isl_polynomial_private.h +++ a/gcc/isl/isl_polynomial_private.h @@ -6,26 +6,29 @@ #include #include -struct isl_upoly { +struct isl_poly { int ref; struct isl_ctx *ctx; int var; }; +typedef struct isl_poly isl_poly; -struct isl_upoly_cst { - struct isl_upoly up; +struct isl_poly_cst { + struct isl_poly poly; isl_int n; isl_int d; }; +typedef struct isl_poly_cst isl_poly_cst; -struct isl_upoly_rec { - struct isl_upoly up; +struct isl_poly_rec { + struct isl_poly poly; int n; size_t size; - struct isl_upoly *p[]; + isl_poly *p[]; }; +typedef struct isl_poly_rec isl_poly_rec; /* dim represents the domain space. */ @@ -34,7 +37,7 @@ isl_space *dim; struct isl_mat *div; - struct isl_upoly *upoly; + isl_poly *poly; }; struct isl_term { @@ -65,6 +68,16 @@ struct isl_pw_qpolynomial_piece p[1]; }; +#undef PW +#define PW isl_pw_qpolynomial + +#include + +#undef EL +#define EL isl_pw_qpolynomial + +#include + /* dim represents the domain space. */ struct isl_qpolynomial_fold { @@ -95,31 +108,41 @@ size_t size; struct isl_pw_qpolynomial_fold_piece p[1]; }; + +#undef PW +#define PW isl_pw_qpolynomial_fold + +#include + +#undef EL +#define EL isl_pw_qpolynomial_fold + +#include void isl_term_get_num(__isl_keep isl_term *term, isl_int *n); -__isl_give struct isl_upoly *isl_upoly_zero(struct isl_ctx *ctx); -__isl_give struct isl_upoly *isl_upoly_copy(__isl_keep struct isl_upoly *up); -__isl_give struct isl_upoly *isl_upoly_cow(__isl_take struct isl_upoly *up); -__isl_give struct isl_upoly *isl_upoly_dup(__isl_keep struct isl_upoly *up); -__isl_null struct isl_upoly *isl_upoly_free(__isl_take struct isl_upoly *up); -__isl_give struct isl_upoly *isl_upoly_mul(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2); - -int isl_upoly_is_cst(__isl_keep struct isl_upoly *up); -int isl_upoly_is_zero(__isl_keep struct isl_upoly *up); -int isl_upoly_is_one(__isl_keep struct isl_upoly *up); -int isl_upoly_is_negone(__isl_keep struct isl_upoly *up); -__isl_keep struct isl_upoly_cst *isl_upoly_as_cst(__isl_keep struct isl_upoly *up); -__isl_keep struct isl_upoly_rec *isl_upoly_as_rec(__isl_keep struct isl_upoly *up); - -__isl_give struct isl_upoly *isl_upoly_sum(__isl_take struct isl_upoly *up1, - __isl_take struct isl_upoly *up2); -__isl_give struct isl_upoly *isl_upoly_mul_isl_int( - __isl_take struct isl_upoly *up, isl_int v); - -__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *dim, - unsigned n_div, __isl_take struct isl_upoly *up); +__isl_give isl_poly *isl_poly_zero(struct isl_ctx *ctx); +__isl_give isl_poly *isl_poly_copy(__isl_keep isl_poly *poly); +__isl_give isl_poly *isl_poly_cow(__isl_take isl_poly *poly); +__isl_give isl_poly *isl_poly_dup(__isl_keep isl_poly *poly); +__isl_null isl_poly *isl_poly_free(__isl_take isl_poly *poly); +__isl_give struct isl_poly *isl_poly_mul(__isl_take struct isl_poly *poly1, + __isl_take struct isl_poly *poly2); + +isl_bool isl_poly_is_cst(__isl_keep isl_poly *poly); +isl_bool isl_poly_is_zero(__isl_keep isl_poly *poly); +isl_bool isl_poly_is_one(__isl_keep isl_poly *poly); +isl_bool isl_poly_is_negone(__isl_keep isl_poly *poly); +__isl_keep isl_poly_cst *isl_poly_as_cst(__isl_keep isl_poly *poly); +__isl_keep isl_poly_rec *isl_poly_as_rec(__isl_keep isl_poly *poly); + +__isl_give isl_poly *isl_poly_sum(__isl_take isl_poly *poly1, + __isl_take isl_poly *poly2); +__isl_give struct isl_poly *isl_poly_mul_isl_int( + __isl_take isl_poly *poly, isl_int v); + +__isl_give isl_qpolynomial *isl_qpolynomial_alloc(__isl_take isl_space *space, + unsigned n_div, __isl_take isl_poly *poly); __isl_give isl_qpolynomial *isl_qpolynomial_cow(__isl_take isl_qpolynomial *qp); __isl_give isl_qpolynomial *isl_qpolynomial_dup(__isl_keep isl_qpolynomial *qp); @@ -130,8 +153,8 @@ __isl_give isl_qpolynomial *isl_qpolynomial_var_pow_on_domain(__isl_take isl_space *dim, int pos, int power); isl_bool isl_qpolynomial_is_one(__isl_keep isl_qpolynomial *qp); -int isl_qpolynomial_is_affine(__isl_keep isl_qpolynomial *qp); -int isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp, +isl_bool isl_qpolynomial_is_affine(__isl_keep isl_qpolynomial *qp); +isl_bool isl_qpolynomial_is_cst(__isl_keep isl_qpolynomial *qp, isl_int *n, isl_int *d); unsigned isl_qpolynomial_domain_offset(__isl_keep isl_qpolynomial *qp, @@ -152,8 +175,8 @@ __isl_give isl_vec *isl_qpolynomial_extract_affine( __isl_keep isl_qpolynomial *qp); -__isl_give isl_qpolynomial *isl_qpolynomial_from_affine(__isl_take isl_space *dim, - isl_int *f, isl_int denom); +__isl_give isl_qpolynomial *isl_qpolynomial_from_affine( + __isl_take isl_space *space, isl_int *f, isl_int denom); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_cow( __isl_take isl_pw_qpolynomial *pwqp); @@ -195,7 +218,8 @@ __isl_give isl_val *isl_qpolynomial_fold_opt_on_domain( __isl_take isl_qpolynomial_fold *fold, __isl_take isl_set *set, int max); -int isl_pw_qpolynomial_fold_covers(__isl_keep isl_pw_qpolynomial_fold *pwf1, +isl_bool isl_pw_qpolynomial_fold_covers( + __isl_keep isl_pw_qpolynomial_fold *pwf1, __isl_keep isl_pw_qpolynomial_fold *pwf2); __isl_give isl_qpolynomial *isl_qpolynomial_morph_domain( @@ -208,7 +232,7 @@ __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_morph *morph); __isl_give isl_qpolynomial *isl_qpolynomial_lift(__isl_take isl_qpolynomial *qp, - __isl_take isl_space *dim); + __isl_take isl_space *space); __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_lift( __isl_take isl_qpolynomial_fold *fold, __isl_take isl_space *dim); @@ -243,7 +267,7 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_reset_domain_space( __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_space *dim); -void isl_qpolynomial_get_den(__isl_keep isl_qpolynomial *qp, isl_int *d); +__isl_give isl_val *isl_qpolynomial_get_den(__isl_keep isl_qpolynomial *qp); __isl_give isl_qpolynomial *isl_qpolynomial_add_isl_int( __isl_take isl_qpolynomial *qp, isl_int v); __isl_give isl_qpolynomial *isl_qpolynomial_mul_isl_int( diff --git a/gcc/isl/isl_printer.c b/gcc/isl/isl_printer.c index 05860da..f58a8a7 100644 --- a/gcc/isl/isl_printer.c +++ a/gcc/isl/isl_printer.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include static __isl_give isl_printer *file_start_line(__isl_take isl_printer *p) @@ -91,6 +93,7 @@ goto error; for (i = 0; i < indent; ++i) p->buf[p->buf_n++] = ' '; + p->buf[p->buf_n] = '\0'; return p; error: isl_printer_free(p); diff --git a/gcc/isl/isl_pw_macro.h b/gcc/isl/isl_pw_macro.h index f445df6..4f74978 100644 --- a/gcc/isl/isl_pw_macro.h +++ a/gcc/isl/isl_pw_macro.h @@ -1,3 +1,7 @@ +#define xCAT(A,B) A ## B +#define CAT(A,B) xCAT(A,B) +#undef EL +#define EL CAT(isl_,BASE) #define xFN(TYPE,NAME) TYPE ## _ ## NAME #define FN(TYPE,NAME) xFN(TYPE,NAME) #define xS(TYPE,NAME) struct TYPE ## _ ## NAME diff --git a/gcc/isl/isl_pw_templ.c b/gcc/isl/isl_pw_templ.c index 6b6b5ad..9a8e1a7 100644 --- a/gcc/isl/isl_pw_templ.c +++ a/gcc/isl/isl_pw_templ.c @@ -11,25 +11,24 @@ * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France */ +#include #include #include #include #include -#ifdef HAS_TYPE -__isl_give PW *FN(PW,alloc_size)(__isl_take isl_space *dim, - enum isl_fold type, int n) -#else -__isl_give PW *FN(PW,alloc_size)(__isl_take isl_space *dim, int n) -#endif +#include "opt_type.h" + +__isl_give PW *FN(PW,alloc_size)(__isl_take isl_space *space + OPT_TYPE_PARAM, int n) { isl_ctx *ctx; struct PW *pw; - if (!dim) + if (!space) return NULL; - ctx = isl_space_get_ctx(dim); + ctx = isl_space_get_ctx(space); isl_assert(ctx, n >= 0, goto error); pw = isl_alloc(ctx, struct PW, sizeof(struct PW) + (n - 1) * sizeof(S(PW,piece))); @@ -37,29 +36,20 @@ goto error; pw->ref = 1; -#ifdef HAS_TYPE - pw->type = type; -#endif + OPT_SET_TYPE(pw->, type); pw->size = n; pw->n = 0; - pw->dim = dim; + pw->dim = space; return pw; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } -#ifdef HAS_TYPE -__isl_give PW *FN(PW,ZERO)(__isl_take isl_space *dim, enum isl_fold type) +__isl_give PW *FN(PW,ZERO)(__isl_take isl_space *space OPT_TYPE_PARAM) { - return FN(PW,alloc_size)(dim, type, 0); + return FN(PW,alloc_size)(space OPT_TYPE_ARG(NO_LOC), 0); } -#else -__isl_give PW *FN(PW,ZERO)(__isl_take isl_space *dim) -{ - return FN(PW,alloc_size)(dim, 0); -} -#endif __isl_give PW *FN(PW,add_piece)(__isl_take PW *pw, __isl_take isl_set *set, __isl_take EL *el) @@ -77,11 +67,9 @@ } ctx = isl_set_get_ctx(set); -#ifdef HAS_TYPE - if (pw->type != el->type) + if (!OPT_EQUAL_TYPES(pw->, el->)) isl_die(ctx, isl_error_invalid, "fold types don't match", goto error); -#endif el_dim = FN(EL,get_space(el)); isl_assert(ctx, isl_space_is_equal(pw->dim, el_dim), goto error); isl_assert(ctx, pw->n < pw->size, goto error); @@ -135,23 +123,15 @@ return isl_stat_ok; } -#ifdef HAS_TYPE -__isl_give PW *FN(PW,alloc)(enum isl_fold type, +__isl_give PW *FN(PW,alloc)(OPT_TYPE_PARAM_FIRST __isl_take isl_set *set, __isl_take EL *el) -#else -__isl_give PW *FN(PW,alloc)(__isl_take isl_set *set, __isl_take EL *el) -#endif { PW *pw; if (FN(PW,check_compatible_domain)(el, set) < 0) goto error; -#ifdef HAS_TYPE - pw = FN(PW,alloc_size)(FN(EL,get_space)(el), type, 1); -#else - pw = FN(PW,alloc_size)(FN(EL,get_space)(el), 1); -#endif + pw = FN(PW,alloc_size)(FN(EL,get_space)(el) OPT_TYPE_ARG(NO_LOC), 1); return FN(PW,add_piece)(pw, set, el); error: @@ -168,11 +148,8 @@ if (!pw) return NULL; -#ifdef HAS_TYPE - dup = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->type, pw->n); -#else - dup = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->n); -#endif + dup = FN(PW,alloc_size)(isl_space_copy(pw->dim) + OPT_TYPE_ARG(pw->), pw->n); if (!dup) return NULL; @@ -218,9 +195,68 @@ } isl_space_free(pw->dim); free(pw); + + return NULL; +} + +/* Create a piecewise expression with the given base expression on a universe + * domain. + */ +static __isl_give PW *FN(FN(FN(PW,from),BASE),type_base)(__isl_take EL *el + OPT_TYPE_PARAM) +{ + isl_set *dom = isl_set_universe(FN(EL,get_domain_space)(el)); + return FN(PW,alloc)(OPT_TYPE_ARG_FIRST(NO_LOC) dom, el); +} + +/* Create a piecewise expression with the given base expression on a universe + * domain. + * + * If the default value of this piecewise type is zero and + * if "el" is effectively zero, then create an empty piecewise expression + * instead. + */ +static __isl_give PW *FN(FN(FN(PW,from),BASE),type)(__isl_take EL *el + OPT_TYPE_PARAM) +{ + isl_bool is_zero; + isl_space *space; + if (!DEFAULT_IS_ZERO) + return FN(FN(FN(PW,from),BASE),type_base)(el + OPT_TYPE_ARG(NO_LOC)); + is_zero = FN(EL,EL_IS_ZERO)(el); + if (is_zero < 0) + goto error; + if (!is_zero) + return FN(FN(FN(PW,from),BASE),type_base)(el + OPT_TYPE_ARG(NO_LOC)); + space = FN(EL,get_space)(el); + FN(EL,free)(el); + return FN(PW,ZERO)(space OPT_TYPE_ARG(NO_LOC)); +error: + FN(EL,free)(el); return NULL; +} + +#ifdef HAS_TYPE +/* Create a piecewise expression with the given base expression on a universe + * domain. + * + * Pass along the type as an extra argument for improved uniformity + * with piecewise types that do not have a fold type. + */ +__isl_give PW *FN(FN(PW,from),BASE)(__isl_take EL *el) +{ + enum isl_fold type = FN(EL,get_type)(el); + return FN(FN(FN(PW,from),BASE),type)(el, type); +} +#else +__isl_give PW *FN(FN(PW,from),BASE)(__isl_take EL *el) +{ + return FN(FN(FN(PW,from),BASE),type)(el); } +#endif const char *FN(PW,get_dim_name)(__isl_keep PW *pw, enum isl_dim_type type, unsigned pos) @@ -265,7 +301,7 @@ if (!pw) return isl_bool_error; - return pw->n == 0; + return isl_bool_ok(pw->n == 0); } #ifndef NO_REALIGN @@ -289,7 +325,7 @@ goto error; } - pw = FN(PW,reset_domain_space)(pw, isl_space_copy(exp->dim)); + pw = FN(PW,reset_domain_space)(pw, isl_reordering_get_space(exp)); isl_reordering_free(exp); return pw; @@ -297,6 +333,14 @@ isl_reordering_free(exp); FN(PW,free)(pw); return NULL; +} + +/* Check that "pw" has only named parameters, reporting an error + * if it does not. + */ +isl_stat FN(PW,check_named_params)(__isl_keep PW *pw) +{ + return isl_space_check_named_params(FN(PW,peek_space)(pw)); } /* Align the parameters of "pw" to those of "model". @@ -313,19 +357,14 @@ if (!isl_space_has_named_params(model)) isl_die(ctx, isl_error_invalid, "model has unnamed parameters", goto error); - if (!isl_space_has_named_params(pw->dim)) - isl_die(ctx, isl_error_invalid, - "input has unnamed parameters", goto error); + if (FN(PW,check_named_params)(pw) < 0) + goto error; equal_params = isl_space_has_equal_params(pw->dim, model); if (equal_params < 0) goto error; if (!equal_params) { isl_reordering *exp; - model = isl_space_drop_dims(model, isl_dim_in, - 0, isl_space_dim(model, isl_dim_in)); - model = isl_space_drop_dims(model, isl_dim_out, - 0, isl_space_dim(model, isl_dim_out)); exp = isl_parameter_alignment_reordering(pw->dim, model); exp = isl_reordering_extend_space(exp, FN(PW,get_domain_space)(pw)); @@ -344,7 +383,6 @@ __isl_take PW *pw2, __isl_give PW *(*fn)(__isl_take PW *pw1, __isl_take PW *pw2)) { - isl_ctx *ctx; isl_bool equal_params; if (!pw1 || !pw2) @@ -354,11 +392,9 @@ goto error; if (equal_params) return fn(pw1, pw2); - ctx = FN(PW,get_ctx)(pw1); - if (!isl_space_has_named_params(pw1->dim) || - !isl_space_has_named_params(pw2->dim)) - isl_die(ctx, isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (FN(PW,check_named_params)(pw1) < 0 || + FN(PW,check_named_params)(pw2) < 0) + goto error; pw1 = FN(PW,align_params)(pw1, FN(PW,get_space)(pw2)); pw2 = FN(PW,align_params)(pw2, FN(PW,get_space)(pw1)); return fn(pw1, pw2); @@ -383,8 +419,9 @@ if (aligned) return fn(pw, set); ctx = FN(PW,get_ctx)(pw); - if (!isl_space_has_named_params(pw->dim) || - !isl_space_has_named_params(set->dim)) + if (FN(PW,check_named_params)(pw) < 0) + goto error; + if (!isl_space_has_named_params(set->dim)) isl_die(ctx, isl_error_invalid, "unaligned unnamed parameters", goto error); pw = FN(PW,align_params)(pw, isl_set_get_space(set)); @@ -409,11 +446,9 @@ goto error; ctx = isl_space_get_ctx(pw1->dim); -#ifdef HAS_TYPE - if (pw1->type != pw2->type) + if (!OPT_EQUAL_TYPES(pw1->, pw2->)) isl_die(ctx, isl_error_invalid, "fold types don't match", goto error); -#endif isl_assert(ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error); if (FN(PW,IS_ZERO)(pw1)) { @@ -427,11 +462,8 @@ } n = (pw1->n + 1) * (pw2->n + 1); -#ifdef HAS_TYPE - res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), pw1->type, n); -#else - res = FN(PW,alloc_size)(isl_space_copy(pw1->dim), n); -#endif + res = FN(PW,alloc_size)(isl_space_copy(pw1->dim) + OPT_TYPE_ARG(pw1->), n); for (i = 0; i < pw1->n; ++i) { set = isl_set_copy(pw1->p[i].set); @@ -508,11 +540,7 @@ res->size = n; return res; } -#ifdef HAS_TYPE - res = FN(PW,alloc_size)(isl_space_copy(pw->dim), pw->type, n); -#else - res = FN(PW,alloc_size)(isl_space_copy(pw->dim), n); -#endif + res = FN(PW,alloc_size)(isl_space_copy(pw->dim) OPT_TYPE_ARG(pw->), n); if (!res) return FN(PW,free)(pw); for (i = 0; i < pw->n; ++i) @@ -535,11 +563,9 @@ return FN(PW,add_disjoint_aligned)(pw2, pw1); ctx = isl_space_get_ctx(pw1->dim); -#ifdef HAS_TYPE - if (pw1->type != pw2->type) + if (!OPT_EQUAL_TYPES(pw1->, pw2->)) isl_die(ctx, isl_error_invalid, "fold types don't match", goto error); -#endif isl_assert(ctx, isl_space_is_equal(pw1->dim, pw2->dim), goto error); if (FN(PW,IS_ZERO)(pw1)) { @@ -597,11 +623,7 @@ goto error; n = pw1->n * pw2->n; -#ifdef HAS_TYPE - res = FN(PW,alloc_size)(isl_space_copy(space), pw1->type, n); -#else - res = FN(PW,alloc_size)(isl_space_copy(space), n); -#endif + res = FN(PW,alloc_size)(isl_space_copy(space) OPT_TYPE_ARG(pw1->), n); for (i = 0; i < pw1->n; ++i) { for (j = 0; j < pw2->n; ++j) { @@ -696,66 +718,6 @@ __isl_give PW *FN(PW,sub)(__isl_take PW *pw1, __isl_take PW *pw2) { return FN(PW,add)(pw1, FN(PW,neg)(pw2)); -} -#endif - -#ifndef NO_EVAL -/* Evaluate "pw" in the void point "pnt". - * In particular, return the value NaN. - */ -static __isl_give isl_val *FN(PW,eval_void)(__isl_take PW *pw, - __isl_take isl_point *pnt) -{ - isl_ctx *ctx; - - ctx = isl_point_get_ctx(pnt); - FN(PW,free)(pw); - isl_point_free(pnt); - return isl_val_nan(ctx); -} - -__isl_give isl_val *FN(PW,eval)(__isl_take PW *pw, __isl_take isl_point *pnt) -{ - int i; - isl_bool is_void; - int found = 0; - isl_ctx *ctx; - isl_space *pnt_dim = NULL; - isl_val *v; - - if (!pw || !pnt) - goto error; - ctx = isl_point_get_ctx(pnt); - pnt_dim = isl_point_get_space(pnt); - isl_assert(ctx, isl_space_is_domain_internal(pnt_dim, pw->dim), - goto error); - is_void = isl_point_is_void(pnt); - if (is_void < 0) - goto error; - if (is_void) - return FN(PW,eval_void)(pw, pnt); - - for (i = 0; i < pw->n; ++i) { - found = isl_set_contains_point(pw->p[i].set, pnt); - if (found < 0) - goto error; - if (found) - break; - } - if (found) - v = FN(EL,eval)(FN(EL,copy)(pw->p[i].FIELD), - isl_point_copy(pnt)); - else - v = isl_val_zero(ctx); - FN(PW,free)(pw); - isl_space_free(pnt_dim); - isl_point_free(pnt); - return v; -error: - FN(PW,free)(pw); - isl_space_free(pnt_dim); - isl_point_free(pnt); - return NULL; } #endif @@ -870,7 +832,8 @@ /* Restrict the domain of "pw" by combining each cell * with "set" through a call to "fn", where "fn" may be - * isl_set_intersect, isl_set_intersect_params or isl_set_subtract. + * isl_set_intersect, isl_set_intersect_params, isl_set_intersect_factor_domain, + * isl_set_intersect_factor_range or isl_set_subtract. */ static __isl_give PW *FN(PW,restrict_domain_aligned)(__isl_take PW *pw, __isl_take isl_set *set, @@ -932,8 +895,50 @@ { return FN(PW,align_params_pw_set_and)(pw, context, &FN(PW,intersect_params_aligned)); +} + +/* Given a piecewise expression "pw" with domain in a space [A -> B] and + * a set in the space A, intersect the domain with the set, + * assuming the parameters have been aligned. + */ +static __isl_give PW *FN(PW,intersect_domain_wrapped_domain_aligned)( + __isl_take PW *pw, __isl_take isl_set *set) +{ + return FN(PW,restrict_domain_aligned)(pw, set, + &isl_set_intersect_factor_domain); +} + +/* Given a piecewise expression "pw" with domain in a space [A -> B] and + * a set in the space A, intersect the domain with the set. + */ +__isl_give PW *FN(PW,intersect_domain_wrapped_domain)(__isl_take PW *pw, + __isl_take isl_set *set) +{ + return FN(PW,align_params_pw_set_and)(pw, set, + &FN(PW,intersect_domain_wrapped_domain_aligned)); +} + +/* Given a piecewise expression "pw" with domain in a space [A -> B] and + * a set in the space B, intersect the domain with the set, + * assuming the parameters have been aligned. + */ +static __isl_give PW *FN(PW,intersect_domain_wrapped_range_aligned)( + __isl_take PW *pw, __isl_take isl_set *set) +{ + return FN(PW,restrict_domain_aligned)(pw, set, + &isl_set_intersect_factor_range); } +/* Given a piecewise expression "pw" with domain in a space [A -> B] and + * a set in the space B, intersect the domain with the set. + */ +__isl_give PW *FN(PW,intersect_domain_wrapped_range)(__isl_take PW *pw, + __isl_take isl_set *set) +{ + return FN(PW,align_params_pw_set_and)(pw, set, + &FN(PW,intersect_domain_wrapped_range_aligned)); +} + /* Subtract "domain' from the domain of "pw", assuming their * parameters have been aligned. */ @@ -1200,7 +1205,6 @@ return pw ? isl_space_get_ctx(pw->dim) : NULL; } -#ifndef NO_INVOLVES_DIMS isl_bool FN(PW,involves_dims)(__isl_keep PW *pw, enum isl_dim_type type, unsigned first, unsigned n) { @@ -1226,7 +1230,6 @@ } return isl_bool_false; } -#endif __isl_give PW *FN(PW,set_dim_name)(__isl_take PW *pw, enum isl_dim_type type, unsigned pos, const char *s) @@ -1260,7 +1263,6 @@ return NULL; } -#ifndef NO_DROP_DIMS __isl_give PW *FN(PW,drop_dims)(__isl_take PW *pw, enum isl_dim_type type, unsigned first, unsigned n) { @@ -1342,16 +1344,43 @@ __isl_give PW *FN(PW,project_domain_on_params)(__isl_take PW *pw) { isl_space *space; - unsigned n; + isl_size n; n = FN(PW,dim)(pw, isl_dim_in); + if (n < 0) + return FN(PW,free)(pw); pw = FN(PW,project_out)(pw, isl_dim_in, 0, n); space = FN(PW,get_domain_space)(pw); space = isl_space_params(space); pw = FN(PW,reset_domain_space)(pw, space); return pw; } -#endif + +/* Drop all parameters not referenced by "pw". + */ +__isl_give PW *FN(PW,drop_unused_params)(__isl_take PW *pw) +{ + isl_size n; + int i; + + if (FN(PW,check_named_params)(pw) < 0) + return FN(PW,free)(pw); + + n = FN(PW,dim)(pw, isl_dim_param); + if (n < 0) + return FN(PW,free)(pw); + for (i = n - 1; i >= 0; i--) { + isl_bool involves; + + involves = FN(PW,involves_dims)(pw, isl_dim_param, i, 1); + if (involves < 0) + return FN(PW,free)(pw); + if (!involves) + pw = FN(PW,drop_dims)(pw, isl_dim_param, i, 1); + } + + return pw; +} #ifndef NO_INSERT_DIMS __isl_give PW *FN(PW,insert_dims)(__isl_take PW *pw, enum isl_dim_type type, @@ -1437,9 +1466,9 @@ return FN(PW,free)(pw); } -unsigned FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type) +isl_size FN(PW,dim)(__isl_keep PW *pw, enum isl_dim_type type) { - return pw ? isl_space_dim(pw->dim, type) : 0; + return isl_space_dim(FN(PW,peek_space)(pw), type); } __isl_give PW *FN(PW,split_dims)(__isl_take PW *pw, @@ -1529,6 +1558,145 @@ __isl_give isl_space *FN(PW,get_space)(__isl_keep PW *pw) { return isl_space_copy(FN(PW,peek_space)(pw)); +} + +/* Return the space of "pw". + * This may be either a copy or the space itself + * if there is only one reference to "pw". + * This allows the space to be modified inplace + * if both the piecewise expression and its space have only a single reference. + * The caller is not allowed to modify "pw" between this call and + * a subsequent call to isl_pw_*_restore_*. + * The only exception is that isl_pw_*_free can be called instead. + */ +__isl_give isl_space *FN(PW,take_space)(__isl_keep PW *pw) +{ + isl_space *space; + + if (!pw) + return NULL; + if (pw->ref != 1) + return FN(PW,get_space)(pw); + space = pw->dim; + pw->dim = NULL; + return space; +} + +/* Set the space of "pw" to "space", where the space of "pw" may be missing + * due to a preceding call to isl_pw_*_take_space. + * However, in this case, "pw" only has a single reference and + * then the call to isl_pw_*_cow has no effect. + */ +__isl_give PW *FN(PW,restore_space)(__isl_take PW *pw, + __isl_take isl_space *space) +{ + if (!pw || !space) + goto error; + + if (pw->dim == space) { + isl_space_free(space); + return pw; + } + + pw = FN(PW,cow)(pw); + if (!pw) + goto error; + isl_space_free(pw->dim); + pw->dim = space; + + return pw; +error: + FN(PW,free)(pw); + isl_space_free(space); + return NULL; +} + +/* Check that "pos" is a valid position for a cell in "pw". + */ +static isl_stat FN(PW,check_pos)(__isl_keep PW *pw, int pos) +{ + if (!pw) + return isl_stat_error; + if (pos < 0 || pos >= pw->n) + isl_die(FN(PW,get_ctx)(pw), isl_error_internal, + "position out of bounds", return isl_stat_error); + return isl_stat_ok; +} + +/* Return the cell at position "pos" in "pw". + */ +static __isl_keep isl_set *FN(PW,peek_domain_at)(__isl_keep PW *pw, int pos) +{ + if (FN(PW,check_pos)(pw, pos) < 0) + return NULL; + return pw->p[pos].set; +} + +/* Return a copy of the base expression associated to + * the cell at position "pos" in "pw". + */ +__isl_give EL *FN(PW,get_base_at)(__isl_keep PW *pw, int pos) +{ + if (FN(PW,check_pos)(pw, pos) < 0) + return NULL; + return FN(EL,copy)(pw->p[pos].FIELD); +} + +/* Return the base expression associated to + * the cell at position "pos" in "pw". + * This may be either a copy or the base expression itself + * if there is only one reference to "pw". + * This allows the base expression to be modified inplace + * if both the piecewise expression and this base expression + * have only a single reference. + * The caller is not allowed to modify "pw" between this call and + * a subsequent call to isl_pw_*_restore_*. + * The only exception is that isl_pw_*_free can be called instead. + */ +__isl_give EL *FN(PW,take_base_at)(__isl_keep PW *pw, int pos) +{ + EL *el; + + if (!pw) + return NULL; + if (pw->ref != 1) + return FN(PW,get_base_at)(pw, pos); + if (FN(PW,check_pos)(pw, pos) < 0) + return NULL; + el = pw->p[pos].FIELD; + pw->p[pos].FIELD = NULL; + return el; +} + +/* Set the base expression associated to + * the cell at position "pos" in "pw" to "el", + * where this base expression may be missing + * due to a preceding call to isl_pw_*_take_base_at. + * However, in this case, "pw" only has a single reference and + * then the call to isl_pw_*_cow has no effect. + */ +__isl_give PW *FN(PW,restore_base_at)(__isl_take PW *pw, int pos, + __isl_take EL *el) +{ + if (FN(PW,check_pos)(pw, pos) < 0 || !el) + goto error; + + if (pw->p[pos].FIELD == el) { + FN(EL,free)(el); + return pw; + } + + pw = FN(PW,cow)(pw); + if (!pw) + goto error; + FN(EL,free)(pw->p[pos].FIELD); + pw->p[pos].FIELD = el; + + return pw; +error: + FN(PW,free)(pw); + FN(EL,free)(el); + return NULL; } __isl_give isl_space *FN(PW,get_domain_space)(__isl_keep PW *pw) @@ -1546,6 +1714,37 @@ if (!pw) return -1; return isl_space_find_dim_by_name(pw->dim, type, name); +} + +/* Return the position of the dimension of the given type and identifier + * in "pw". + * Return -1 if no such dimension can be found. + */ +static int FN(PW,find_dim_by_id)(__isl_keep PW *pw, + enum isl_dim_type type, __isl_keep isl_id *id) +{ + isl_space *space; + + space = FN(PW,peek_space)(pw); + return isl_space_find_dim_by_id(space, type, id); +} + +/* Does the piecewise expression "pw" depend in any way + * on the parameter with identifier "id"? + */ +isl_bool FN(PW,involves_param_id)(__isl_keep PW *pw, __isl_keep isl_id *id) +{ + int pos; + + if (!pw || !id) + return isl_bool_error; + if (pw->n == 0) + return isl_bool_false; + + pos = FN(PW,find_dim_by_id)(pw, isl_dim_param, id); + if (pos < 0) + return isl_bool_false; + return FN(PW,involves_dims)(pw, isl_dim_param, pos, 1); } #ifndef NO_RESET_DIM @@ -1720,9 +1919,9 @@ } #endif -int FN(PW,n_piece)(__isl_keep PW *pw) +isl_size FN(PW,n_piece)(__isl_keep PW *pw) { - return pw ? pw->n : 0; + return pw ? pw->n : isl_size_error; } isl_stat FN(PW,foreach_piece)(__isl_keep PW *pw, @@ -1740,6 +1939,100 @@ return isl_stat_error; return isl_stat_ok; +} + +/* Is "pw" defined over a single universe domain? + * + * If the default value of this piecewise type is zero, + * then a "pw" with a zero number of cells is also accepted + * as it represents the default zero value. + */ +isl_bool FN(FN(PW,isa),BASE)(__isl_keep PW *pw) +{ + isl_size n; + + n = FN(PW,n_piece)(pw); + if (n < 0) + return isl_bool_error; + if (DEFAULT_IS_ZERO && n == 0) + return isl_bool_true; + if (n != 1) + return isl_bool_false; + return isl_set_plain_is_universe(FN(PW,peek_domain_at)(pw, 0)); +} + +/* Return a zero base expression in the same space (and of the same type) + * as "pw". + */ +static __isl_give EL *FN(EL,zero_like_type)(__isl_take PW *pw OPT_TYPE_PARAM) +{ + isl_space *space; + + space = FN(PW,get_space)(pw); + FN(PW,free)(pw); + return FN(EL,zero_in_space)(space OPT_TYPE_ARG(NO_LOC)); +} + +#ifndef HAS_TYPE +/* Return a zero base expression in the same space as "pw". + */ +static __isl_give EL *FN(EL,zero_like)(__isl_take PW *pw) +{ + return FN(EL,zero_like_type)(pw); +} +#else +/* Return a zero base expression in the same space and of the same type + * as "pw". + * + * Pass along the type as an explicit argument for uniform handling + * in isl_*_zero_like_type. + */ +static __isl_give EL *FN(EL,zero_like)(__isl_take PW *pw) +{ + enum isl_fold type; + + type = FN(PW,get_type)(pw); + if (type < 0) + goto error; + return FN(EL,zero_like_type)(pw, type); +error: + FN(PW,free)(pw); + return NULL; +} +#endif + +/* Given that "pw" is defined over a single universe domain, + * return the base expression associated to this domain. + * + * If the number of cells is zero, then "pw" is of a piecewise type + * with a default zero value and effectively represents zero. + * In this case, create a zero base expression in the same space + * (and with the same type). + * Otherwise, simply extract the associated base expression. + */ +__isl_give EL *FN(FN(PW,as),BASE)(__isl_take PW *pw) +{ + isl_bool is_total; + isl_size n; + EL *el; + + is_total = FN(FN(PW,isa),BASE)(pw); + if (is_total < 0) + goto error; + if (!is_total) + isl_die(FN(PW,get_ctx)(pw), isl_error_invalid, + "expecting single total function", goto error); + n = FN(PW,n_piece)(pw); + if (n < 0) + goto error; + if (n == 0) + return FN(EL,zero_like)(pw); + el = FN(PW,take_base_at)(pw, 0); + FN(PW,free)(pw); + return el; +error: + FN(PW,free)(pw); + return NULL; } #ifndef NO_LIFT @@ -1865,6 +2158,27 @@ } #endif +#ifdef HAS_TYPE +/* Negate the type of "pw". + */ +static __isl_give PW *FN(PW,negate_type)(__isl_take PW *pw) +{ + pw = FN(PW,cow)(pw); + if (!pw) + return NULL; + pw->type = isl_fold_type_negate(pw->type); + return pw; +} +#else +/* Negate the type of "pw". + * Since "pw" does not have a type, do nothing. + */ +static __isl_give PW *FN(PW,negate_type)(__isl_take PW *pw) +{ + return pw; +} +#endif + __isl_give PW *FN(PW,mul_isl_int)(__isl_take PW *pw, isl_int v) { int i; @@ -1874,24 +2188,18 @@ if (pw && DEFAULT_IS_ZERO && isl_int_is_zero(v)) { PW *zero; isl_space *dim = FN(PW,get_space)(pw); -#ifdef HAS_TYPE - zero = FN(PW,ZERO)(dim, pw->type); -#else - zero = FN(PW,ZERO)(dim); -#endif + zero = FN(PW,ZERO)(dim OPT_TYPE_ARG(pw->)); FN(PW,free)(pw); return zero; } pw = FN(PW,cow)(pw); + if (isl_int_is_neg(v)) + pw = FN(PW,negate_type)(pw); if (!pw) return NULL; if (pw->n == 0) return pw; -#ifdef HAS_TYPE - if (isl_int_is_neg(v)) - pw->type = isl_fold_type_negate(pw->type); -#endif for (i = 0; i < pw->n; ++i) { pw->p[i].FIELD = FN(EL,scale)(pw->p[i].FIELD, v); if (!pw->p[i].FIELD) @@ -1920,11 +2228,7 @@ if (pw && DEFAULT_IS_ZERO && isl_val_is_zero(v)) { PW *zero; isl_space *space = FN(PW,get_space)(pw); -#ifdef HAS_TYPE - zero = FN(PW,ZERO)(space, pw->type); -#else - zero = FN(PW,ZERO)(space); -#endif + zero = FN(PW,ZERO)(space OPT_TYPE_ARG(pw->)); FN(PW,free)(pw); isl_val_free(v); return zero; @@ -1934,13 +2238,11 @@ return pw; } pw = FN(PW,cow)(pw); + if (isl_val_is_neg(v)) + pw = FN(PW,negate_type)(pw); if (!pw) goto error; -#ifdef HAS_TYPE - if (isl_val_is_neg(v)) - pw->type = isl_fold_type_negate(pw->type); -#endif for (i = 0; i < pw->n; ++i) { pw->p[i].FIELD = FN(EL,scale_val)(pw->p[i].FIELD, isl_val_copy(v)); @@ -1982,13 +2284,11 @@ return pw; } pw = FN(PW,cow)(pw); + if (isl_val_is_neg(v)) + pw = FN(PW,negate_type)(pw); if (!pw) goto error; -#ifdef HAS_TYPE - if (isl_val_is_neg(v)) - pw->type = isl_fold_type_negate(pw->type); -#endif for (i = 0; i < pw->n; ++i) { pw->p[i].FIELD = FN(EL,scale_down_val)(pw->p[i].FIELD, isl_val_copy(v)); @@ -2071,7 +2371,7 @@ if (!pw1 || !pw2) goto error; - equal = pw1->n == pw2->n; + equal = isl_bool_ok(pw1->n == pw2->n); for (i = 0; equal && i < pw1->n; ++i) { equal = isl_set_plain_is_equal(pw1->p[i].set, pw2->p[i].set); if (equal < 0) @@ -2132,8 +2432,9 @@ return fn(pw, ma); } ctx = FN(PW,get_ctx)(pw); - if (!isl_space_has_named_params(pw->dim) || - !isl_space_has_named_params(ma_space)) + if (FN(PW,check_named_params)(pw) < 0) + goto error; + if (!isl_space_has_named_params(ma_space)) isl_die(ctx, isl_error_invalid, "unaligned unnamed parameters", goto error); pw = FN(PW,align_params)(pw, ma_space); @@ -2151,7 +2452,6 @@ __isl_give PW *(*fn)(__isl_take PW *pw, __isl_take isl_pw_multi_aff *ma)) { - isl_ctx *ctx; isl_bool equal_params; isl_space *pma_space; @@ -2165,11 +2465,9 @@ isl_space_free(pma_space); return fn(pw, pma); } - ctx = FN(PW,get_ctx)(pw); - if (!isl_space_has_named_params(pw->dim) || - !isl_space_has_named_params(pma_space)) - isl_die(ctx, isl_error_invalid, - "unaligned unnamed parameters", goto error); + if (FN(PW,check_named_params)(pw) < 0 || + isl_pw_multi_aff_check_named_params(pma) < 0) + goto error; pw = FN(PW,align_params)(pw, pma_space); pma = isl_pw_multi_aff_align_params(pma, FN(PW,get_space)(pw)); return fn(pw, pma); diff --git a/gcc/isl/isl_range.c b/gcc/isl/isl_range.c index 690d7b9..5bcfcff 100644 --- a/gcc/isl/isl_range.c +++ a/gcc/isl/isl_range.c @@ -26,17 +26,19 @@ * is non-negative and if sign == -1, check that the upper bound on * the polynomial is non-positive. */ -static int has_sign(__isl_keep isl_basic_set *bset, +static isl_bool has_sign(__isl_keep isl_basic_set *bset, __isl_keep isl_qpolynomial *poly, int sign, int *signs) { struct range_data data_m; - unsigned nparam; - isl_space *dim; + isl_size nparam; + isl_space *space; isl_val *opt; - int r; + isl_bool r; enum isl_fold type; nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0) + return isl_bool_error; bset = isl_basic_set_copy(bset); poly = isl_qpolynomial_copy(poly); @@ -46,16 +48,16 @@ poly = isl_qpolynomial_move_dims(poly, isl_dim_in, 0, isl_dim_param, 0, nparam); - dim = isl_qpolynomial_get_space(poly); - dim = isl_space_params(dim); - dim = isl_space_from_domain(dim); - dim = isl_space_add_dims(dim, isl_dim_out, 1); + space = isl_qpolynomial_get_space(poly); + space = isl_space_params(space); + space = isl_space_from_domain(space); + space = isl_space_add_dims(space, isl_dim_out, 1); data_m.test_monotonicity = 0; data_m.signs = signs; data_m.sign = -sign; type = data_m.sign < 0 ? isl_fold_min : isl_fold_max; - data_m.pwf = isl_pw_qpolynomial_fold_zero(dim, type); + data_m.pwf = isl_pw_qpolynomial_fold_zero(space, type); data_m.tight = 0; data_m.pwf_tight = NULL; @@ -68,20 +70,20 @@ opt = isl_pw_qpolynomial_fold_max(data_m.pwf); if (!opt) - r = -1; + r = isl_bool_error; else if (isl_val_is_nan(opt) || isl_val_is_infty(opt) || isl_val_is_neginfty(opt)) - r = 0; + r = isl_bool_false; else - r = sign * isl_val_sgn(opt) >= 0; + r = isl_bool_ok(sign * isl_val_sgn(opt) >= 0); isl_val_free(opt); return r; error: isl_pw_qpolynomial_fold_free(data_m.pwf); - return -1; + return isl_bool_error; } /* Return 1 if poly is monotonically increasing in the last set variable, @@ -95,21 +97,24 @@ __isl_keep isl_qpolynomial *poly, struct range_data *data) { isl_ctx *ctx; - isl_space *dim; + isl_space *space; isl_qpolynomial *sub = NULL; isl_qpolynomial *diff = NULL; int result = 0; - int s; - unsigned nvar; - - ctx = isl_qpolynomial_get_ctx(poly); - dim = isl_qpolynomial_get_domain_space(poly); + isl_bool s; + isl_size nvar; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0) + return -2; + + ctx = isl_qpolynomial_get_ctx(poly); + space = isl_qpolynomial_get_domain_space(poly); - sub = isl_qpolynomial_var_on_domain(isl_space_copy(dim), isl_dim_set, nvar - 1); + sub = isl_qpolynomial_var_on_domain(isl_space_copy(space), + isl_dim_set, nvar - 1); sub = isl_qpolynomial_add(sub, - isl_qpolynomial_rat_cst_on_domain(dim, ctx->one, ctx->one)); + isl_qpolynomial_rat_cst_on_domain(space, ctx->one, ctx->one)); diff = isl_qpolynomial_substitute(isl_qpolynomial_copy(poly), isl_dim_in, nvar - 1, 1, &sub); @@ -159,7 +164,7 @@ return isl_qpolynomial_from_constraint(bound, isl_dim_set, pos); } -static int bound_is_integer(__isl_take isl_constraint *bound, unsigned pos) +static int bound_is_integer(__isl_keep isl_constraint *bound, unsigned pos) { isl_int c; int is_int; @@ -192,30 +197,36 @@ isl_int n; int i; int sign; - unsigned nparam; - unsigned nvar; - - if (!term) - return isl_stat_error; + isl_size nparam; + isl_size nvar; + isl_size exp; nparam = isl_term_dim(term, isl_dim_param); nvar = isl_term_dim(term, isl_dim_set); + if (nparam < 0 || nvar < 0) + return isl_stat_error; isl_int_init(n); - isl_term_get_num(term, &n); - sign = isl_int_sgn(n); + isl_int_clear(n); + for (i = 0; i < nparam; ++i) { if (data->signs[i] > 0) continue; - if (isl_term_get_exp(term, isl_dim_param, i) % 2) + exp = isl_term_get_exp(term, isl_dim_param, i); + if (exp < 0) + return isl_stat_error; + if (exp % 2) sign = -sign; } for (i = 0; i < nvar; ++i) { if (data->signs[nparam + i] > 0) continue; - if (isl_term_get_exp(term, isl_dim_set, i) % 2) + exp = isl_term_get_exp(term, isl_dim_set, i); + if (exp < 0) + return isl_stat_error; + if (exp % 2) sign = -sign; } @@ -225,8 +236,6 @@ data->poly = isl_qpolynomial_add(data->poly, t); } else isl_term_free(term); - - isl_int_clear(n); return isl_stat_ok; } @@ -348,22 +357,25 @@ int save_tight = data->tight; isl_qpolynomial *poly; isl_stat r; - unsigned nvar; + isl_size nvar, nparam; nvar = isl_basic_set_dim(bset, isl_dim_set); + nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nvar < 0 || nparam < 0) + goto error; if (data->monotonicity) { isl_qpolynomial *sub; - isl_space *dim = isl_qpolynomial_get_domain_space(data->poly); + isl_space *space = isl_qpolynomial_get_domain_space(data->poly); if (data->monotonicity * data->sign > 0) { if (data->tight) data->tight = bound_is_integer(upper, nvar); - sub = bound2poly(upper, dim, nvar, 1); + sub = bound2poly(upper, space, nvar, 1); isl_constraint_free(lower); } else { if (data->tight) data->tight = bound_is_integer(lower, nvar); - sub = bound2poly(lower, dim, nvar, -1); + sub = bound2poly(lower, space, nvar, -1); isl_constraint_free(upper); } poly = isl_qpolynomial_copy(data->poly); @@ -372,14 +384,13 @@ } else { isl_qpolynomial *l, *u; isl_qpolynomial *pos, *neg; - isl_space *dim = isl_qpolynomial_get_domain_space(data->poly); - unsigned nparam = isl_basic_set_dim(bset, isl_dim_param); + isl_space *space = isl_qpolynomial_get_domain_space(data->poly); int sign = data->sign * data->signs[nparam + nvar]; data->tight = 0; - u = bound2poly(upper, isl_space_copy(dim), nvar, 1); - l = bound2poly(lower, dim, nvar, -1); + u = bound2poly(upper, isl_space_copy(space), nvar, 1); + l = bound2poly(lower, space, nvar, -1); pos = isl_qpolynomial_terms_of_sign(data->poly, data->signs, sign); neg = isl_qpolynomial_terms_of_sign(data->poly, data->signs, -sign); @@ -391,7 +402,7 @@ poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, nvar, 1); } - if (isl_basic_set_dim(bset, isl_dim_set) == 0) + if (nvar == 0) r = add_guarded_poly(bset, poly, data); else r = propagate_on_domain(bset, poly, data); @@ -399,6 +410,11 @@ data->tight = save_tight; return r; +error: + isl_constraint_free(lower); + isl_constraint_free(upper); + isl_basic_set_free(bset); + return isl_stat_error; } /* Recursively perform range propagation on the polynomial "poly" @@ -407,19 +423,21 @@ static isl_stat propagate_on_domain(__isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, struct range_data *data) { + isl_bool is_cst; isl_ctx *ctx; isl_qpolynomial *save_poly = data->poly; int save_monotonicity = data->monotonicity; - unsigned d; + isl_size d; - if (!bset || !poly) + d = isl_basic_set_dim(bset, isl_dim_set); + is_cst = isl_qpolynomial_is_cst(poly, NULL, NULL); + if (d < 0 || is_cst < 0) goto error; ctx = isl_basic_set_get_ctx(bset); - d = isl_basic_set_dim(bset, isl_dim_set); isl_assert(ctx, d >= 1, goto error); - if (isl_qpolynomial_is_cst(poly, NULL, NULL)) { + if (is_cst) { bset = isl_basic_set_project_out(bset, isl_dim_set, 0, d); poly = isl_qpolynomial_drop_dims(poly, isl_dim_in, 0, d); return add_guarded_poly(bset, poly, data); @@ -456,15 +474,18 @@ { struct range_data *data = (struct range_data *)user; isl_ctx *ctx; - unsigned nparam = isl_basic_set_dim(bset, isl_dim_param); - unsigned dim = isl_basic_set_dim(bset, isl_dim_set); + isl_size nparam = isl_basic_set_dim(bset, isl_dim_param); + isl_size dim = isl_basic_set_dim(bset, isl_dim_set); + isl_size total = isl_basic_set_dim(bset, isl_dim_all); isl_stat r; data->signs = NULL; + + if (nparam < 0 || dim < 0 || total < 0) + goto error; ctx = isl_basic_set_get_ctx(bset); - data->signs = isl_alloc_array(ctx, int, - isl_basic_set_dim(bset, isl_dim_all)); + data->signs = isl_alloc_array(ctx, int, total); if (isl_basic_set_dims_get_sign(bset, isl_dim_set, 0, dim, data->signs + nparam) < 0) @@ -488,11 +509,11 @@ __isl_take isl_basic_set *bset, __isl_take isl_qpolynomial *poly, struct range_data *data) { - unsigned nparam = isl_basic_set_dim(bset, isl_dim_param); - unsigned nvar = isl_basic_set_dim(bset, isl_dim_set); + isl_size nparam = isl_basic_set_dim(bset, isl_dim_param); + isl_size nvar = isl_basic_set_dim(bset, isl_dim_set); isl_set *set = NULL; - if (!bset) + if (nparam < 0 || nvar < 0) goto error; if (nvar == 0) diff --git a/gcc/isl/isl_reordering.c b/gcc/isl/isl_reordering.c index b65443e..33a8976 100644 --- a/gcc/isl/isl_reordering.c +++ a/gcc/isl/isl_reordering.c @@ -9,6 +9,7 @@ */ #include +#include #include #include @@ -23,7 +24,7 @@ exp->ref = 1; exp->len = len; - exp->dim = NULL; + exp->space = NULL; return exp; } @@ -45,12 +46,12 @@ if (!r) return NULL; - dup = isl_reordering_alloc(r->dim->ctx, r->len); + dup = isl_reordering_alloc(isl_reordering_get_ctx(r), r->len); if (!dup) return NULL; - dup->dim = isl_space_copy(r->dim); - if (!dup->dim) + dup->space = isl_reordering_get_space(r); + if (!dup->space) return isl_reordering_free(dup); for (i = 0; i < dup->len; ++i) dup->pos[i] = r->pos[i]; @@ -69,7 +70,7 @@ return isl_reordering_dup(r); } -void *isl_reordering_free(__isl_take isl_reordering *exp) +__isl_null isl_reordering *isl_reordering_free(__isl_take isl_reordering *exp) { if (!exp) return NULL; @@ -77,11 +78,34 @@ if (--exp->ref > 0) return NULL; - isl_space_free(exp->dim); + isl_space_free(exp->space); free(exp); return NULL; } +/* Return the isl_ctx to which "r" belongs. + */ +isl_ctx *isl_reordering_get_ctx(__isl_keep isl_reordering *r) +{ + return isl_space_get_ctx(isl_reordering_peek_space(r)); +} + +/* Return the space of "r". + */ +__isl_keep isl_space *isl_reordering_peek_space(__isl_keep isl_reordering *r) +{ + if (!r) + return NULL; + return r->space; +} + +/* Return a copy of the space of "r". + */ +__isl_give isl_space *isl_reordering_get_space(__isl_keep isl_reordering *r) +{ + return isl_space_copy(isl_reordering_peek_space(r)); +} + /* Construct a reordering that maps the parameters of "alignee" * to the corresponding parameters in a new dimension specification * that has the parameters of "aligner" first, followed by @@ -100,7 +124,7 @@ if (!exp) return NULL; - exp->dim = isl_space_copy(aligner); + exp->space = isl_space_params(isl_space_copy(aligner)); for (i = 0; i < alignee->nparam; ++i) { isl_id *id_i; @@ -119,16 +143,19 @@ exp->pos[i] = j; isl_id_free(id_i); } else { - int pos; - pos = isl_space_dim(exp->dim, isl_dim_param); - exp->dim = isl_space_add_dims(exp->dim, isl_dim_param, 1); - exp->dim = isl_space_set_dim_id(exp->dim, + isl_size pos; + pos = isl_space_dim(exp->space, isl_dim_param); + if (pos < 0) + exp->space = isl_space_free(exp->space); + exp->space = isl_space_add_dims(exp->space, + isl_dim_param, 1); + exp->space = isl_space_set_dim_id(exp->space, isl_dim_param, pos, id_i); exp->pos[i] = pos; } } - if (!exp->dim) + if (!exp->space) return isl_reordering_free(exp); return exp; error: @@ -136,23 +163,101 @@ return NULL; } +/* Return a reordering that moves the parameters identified by + * the elements of "tuple" to a domain tuple inserted into "space". + * The parameters that remain, are moved from their original positions + * in the list of parameters to their new positions in this list. + * The parameters that get removed, are moved to the corresponding + * positions in the new domain. Note that these set dimensions + * do not necessarily need to appear as parameters in "space". + * Any other dimensions are shifted by the number of extra dimensions + * introduced, i.e., the number of dimensions in the new domain + * that did not appear as parameters in "space". + */ +__isl_give isl_reordering *isl_reordering_unbind_params_insert_domain( + __isl_keep isl_space *space, __isl_keep isl_multi_id *tuple) +{ + int i, n; + int offset, first; + isl_ctx *ctx; + isl_reordering *r; + + if (!space || !tuple) + return NULL; + + ctx = isl_space_get_ctx(space); + r = isl_reordering_alloc(ctx, isl_space_dim(space, isl_dim_all)); + if (!r) + return NULL; + + r->space = isl_space_copy(space); + r->space = isl_space_unbind_params_insert_domain(r->space, tuple); + if (!r->space) + return isl_reordering_free(r); + + n = isl_space_dim(r->space, isl_dim_param); + for (i = 0; i < n; ++i) { + int pos; + isl_id *id; + + id = isl_space_get_dim_id(r->space, isl_dim_param, i); + if (!id) + return isl_reordering_free(r); + pos = isl_space_find_dim_by_id(space, isl_dim_param, id); + isl_id_free(id); + r->pos[pos] = i; + } + + offset = isl_space_dim(r->space, isl_dim_param); + n = isl_multi_id_size(tuple); + for (i = 0; i < n; ++i) { + int pos; + isl_id *id; + + id = isl_multi_id_get_id(tuple, i); + if (!id) + return isl_reordering_free(r); + pos = isl_space_find_dim_by_id(space, isl_dim_param, id); + isl_id_free(id); + if (pos < 0) + continue; + r->pos[pos] = offset + i; + } + + offset = isl_space_dim(r->space, isl_dim_all) - r->len; + first = isl_space_dim(space, isl_dim_param); + n = r->len - first; + for (i = 0; i < n; ++i) + r->pos[first + i] = first + offset + i; + + return r; +} + __isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp, unsigned extra) { int i; + isl_ctx *ctx; + isl_space *space; isl_reordering *res; int offset; + isl_size dim; if (!exp) return NULL; if (extra == 0) return exp; - offset = isl_space_dim(exp->dim, isl_dim_all) - exp->len; - res = isl_reordering_alloc(exp->dim->ctx, exp->len + extra); + ctx = isl_reordering_get_ctx(exp); + space = isl_reordering_peek_space(exp); + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + return isl_reordering_free(exp); + offset = dim - exp->len; + res = isl_reordering_alloc(ctx, exp->len + extra); if (!res) goto error; - res->dim = isl_space_copy(exp->dim); + res->space = isl_reordering_get_space(exp); for (i = 0; i < exp->len; ++i) res->pos[i] = exp->pos[i]; for (i = exp->len; i < res->len; ++i) @@ -169,22 +274,25 @@ __isl_give isl_reordering *isl_reordering_extend_space( __isl_take isl_reordering *exp, __isl_take isl_space *space) { + isl_space *exp_space; isl_reordering *res; + isl_size dim; - if (!exp || !space) + dim = isl_space_dim(space, isl_dim_all); + if (!exp || dim < 0) goto error; - res = isl_reordering_extend(isl_reordering_copy(exp), - isl_space_dim(space, isl_dim_all) - exp->len); + res = isl_reordering_extend(isl_reordering_copy(exp), dim - exp->len); res = isl_reordering_cow(res); if (!res) goto error; - isl_space_free(res->dim); - res->dim = isl_space_replace_params(space, exp->dim); + isl_space_free(res->space); + exp_space = isl_reordering_peek_space(exp); + res->space = isl_space_replace_params(space, exp_space); isl_reordering_free(exp); - if (!res->dim) + if (!res->space) return isl_reordering_free(res); return res; @@ -198,7 +306,7 @@ { int i; - isl_space_dump(exp->dim); + isl_space_dump(exp->space); for (i = 0; i < exp->len; ++i) fprintf(stderr, "%d -> %d; ", i, exp->pos[i]); fprintf(stderr, "\n"); diff --git a/gcc/isl/isl_reordering.h b/gcc/isl/isl_reordering.h index 944d9f0..6664749 100644 --- a/gcc/isl/isl_reordering.h +++ a/gcc/isl/isl_reordering.h @@ -1,10 +1,10 @@ #ifndef ISL_REORDERING_H #define ISL_REORDERING_H #include /* pos maps original dimensions to new dimensions. - * The final dimension is given by dim. + * The final space is given by "space". * The number of dimensions (i.e., the range of values) in the result * may be larger than the number of dimensions in the input. * In particular, the possible values of the entries in pos ranges from 0 to @@ -13,16 +13,21 @@ */ struct isl_reordering { int ref; - isl_space *dim; + isl_space *space; unsigned len; int pos[1]; }; typedef struct isl_reordering isl_reordering; +isl_ctx *isl_reordering_get_ctx(__isl_keep isl_reordering *r); +__isl_keep isl_space *isl_reordering_peek_space(__isl_keep isl_reordering *r); +__isl_give isl_space *isl_reordering_get_space(__isl_keep isl_reordering *r); __isl_give isl_reordering *isl_parameter_alignment_reordering( __isl_keep isl_space *alignee, __isl_keep isl_space *aligner); +__isl_give isl_reordering *isl_reordering_unbind_params_insert_domain( + __isl_keep isl_space *space, __isl_keep isl_multi_id *tuple); __isl_give isl_reordering *isl_reordering_copy(__isl_keep isl_reordering *exp); -void *isl_reordering_free(__isl_take isl_reordering *exp); +__isl_null isl_reordering *isl_reordering_free(__isl_take isl_reordering *exp); __isl_give isl_reordering *isl_reordering_extend_space( __isl_take isl_reordering *exp, __isl_take isl_space *space); __isl_give isl_reordering *isl_reordering_extend(__isl_take isl_reordering *exp, diff --git a/gcc/isl/isl_sample.c b/gcc/isl/isl_sample.c index 058d689..ec3a3b6 100644 --- a/gcc/isl/isl_sample.c +++ a/gcc/isl/isl_sample.c @@ -39,10 +39,12 @@ */ static __isl_give isl_vec *zero_sample(__isl_take isl_basic_set *bset) { - unsigned dim; + isl_size dim; struct isl_vec *sample; - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + goto error; sample = isl_vec_alloc(bset->ctx, 1 + dim); if (sample) { isl_int_set_si(sample->el[0], 1); @@ -50,6 +52,9 @@ } isl_basic_set_free(bset); return sample; +error: + isl_basic_set_free(bset); + return NULL; } static __isl_give isl_vec *interval_sample(__isl_take isl_basic_set *bset) @@ -535,17 +540,18 @@ int i, n; isl_vec *sample = NULL; isl_ctx *ctx; - unsigned nparam; - unsigned nvar; + isl_size nparam; + isl_size nvar; + isl_size total; ctx = isl_basic_set_get_ctx(bset); - if (!ctx) - goto error; - nparam = isl_basic_set_dim(bset, isl_dim_param); nvar = isl_basic_set_dim(bset, isl_dim_set); + total = isl_basic_set_dim(bset, isl_dim_all); + if (!ctx || nparam < 0 || nvar < 0 || total < 0) + goto error; - sample = isl_vec_alloc(ctx, 1 + isl_basic_set_total_dim(bset)); + sample = isl_vec_alloc(ctx, 1 + total); if (!sample) goto error; isl_int_set_si(sample->el[0], 1); @@ -603,7 +609,7 @@ */ static __isl_give isl_vec *sample_bounded(__isl_take isl_basic_set *bset) { - unsigned dim; + isl_size dim; struct isl_vec *sample; struct isl_tab *tab = NULL; isl_factorizer *f; @@ -614,7 +620,9 @@ if (isl_basic_set_plain_is_empty(bset)) return empty_sample(bset); - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + bset = isl_basic_set_free(bset); if (dim == 0) return zero_sample(bset); if (dim == 1) @@ -676,13 +684,13 @@ __isl_take isl_vec *sample) { int i; - unsigned total; + isl_size total; struct isl_mat *T; - if (!bset || !sample) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0 || !sample) goto error; - total = isl_basic_set_total_dim(bset); T = isl_mat_alloc(bset->ctx, 1 + total, 1 + total - (sample->size - 1)); if (!T) goto error; @@ -762,16 +770,15 @@ __isl_take isl_vec *vec) { int i, j, k; - unsigned total; + isl_size total; struct isl_basic_set *shift = NULL; - if (!cone || !vec) + total = isl_basic_set_dim(cone, isl_dim_all); + if (total < 0 || !vec) goto error; isl_assert(cone->ctx, cone->n_eq == 0, goto error); - - total = isl_basic_set_total_dim(cone); shift = isl_basic_set_alloc_space(isl_basic_set_get_space(cone), 0, 0, cone->n_ineq); @@ -819,7 +826,7 @@ static __isl_give isl_vec *round_up_in_cone(__isl_take isl_vec *vec, __isl_take isl_basic_set *cone, __isl_take isl_mat *U) { - unsigned total; + isl_size total; if (!vec || !cone || !U) goto error; @@ -831,7 +838,9 @@ return vec; } - total = isl_basic_set_total_dim(cone); + total = isl_basic_set_dim(cone, isl_dim_all); + if (total < 0) + goto error; cone = isl_basic_set_preimage(cone, U); cone = isl_basic_set_remove_dims(cone, isl_dim_set, 0, total - (vec->size - 1)); @@ -920,7 +929,7 @@ __isl_give isl_vec *isl_basic_set_sample_with_cone( __isl_take isl_basic_set *bset, __isl_take isl_basic_set *cone) { - unsigned total; + isl_size total; unsigned cone_dim; struct isl_mat *M, *U; struct isl_vec *sample; @@ -928,11 +937,11 @@ struct isl_ctx *ctx; struct isl_basic_set *bounded; - if (!bset || !cone) + total = isl_basic_set_dim(cone, isl_dim_all); + if (!bset || total < 0) goto error; ctx = isl_basic_set_get_ctx(bset); - total = isl_basic_set_total_dim(cone); cone_dim = total - cone->n_eq; M = isl_mat_sub_alloc6(ctx, cone->eq, 0, cone->n_eq, 1, total); @@ -1103,10 +1112,12 @@ */ static __isl_give isl_vec *gbr_sample(__isl_take isl_basic_set *bset) { - unsigned dim; + isl_size dim; struct isl_basic_set *cone; - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + goto error; cone = isl_basic_set_recession_cone(isl_basic_set_copy(bset)); if (!cone) @@ -1126,7 +1137,7 @@ int bounded) { struct isl_ctx *ctx; - unsigned dim; + isl_size dim; if (!bset) return NULL; @@ -1134,9 +1145,11 @@ if (isl_basic_set_plain_is_empty(bset)) return empty_sample(bset); - dim = isl_basic_set_n_dim(bset); - isl_assert(ctx, isl_basic_set_n_param(bset) == 0, goto error); - isl_assert(ctx, bset->n_div == 0, goto error); + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0 || + isl_basic_set_check_no_params(bset) < 0 || + isl_basic_set_check_no_locals(bset) < 0) + goto error; if (bset->sample && bset->sample->size == 1 + dim) { int contains = isl_basic_set_contains(bset, bset->sample); @@ -1184,7 +1197,7 @@ int k; struct isl_basic_set *bset = NULL; struct isl_ctx *ctx; - unsigned dim; + isl_size dim; if (!vec) return NULL; @@ -1192,9 +1205,9 @@ isl_assert(ctx, vec->size != 0, goto error); bset = isl_basic_set_alloc(ctx, 0, vec->size - 1, 0, vec->size - 1, 0); - if (!bset) + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) goto error; - dim = isl_basic_set_n_dim(bset); for (i = dim - 1; i >= 0; --i) { k = isl_basic_set_alloc_equality(bset); if (k < 0) @@ -1272,13 +1285,13 @@ __isl_give isl_point *isl_basic_set_sample_point(__isl_take isl_basic_set *bset) { isl_vec *vec; - isl_space *dim; + isl_space *space; - dim = isl_basic_set_get_space(bset); + space = isl_basic_set_get_space(bset); bset = isl_basic_set_underlying_set(bset); vec = isl_basic_set_sample_vec(bset); - return isl_point_alloc(dim, vec); + return isl_point_alloc(space, vec); } __isl_give isl_point *isl_set_sample_point(__isl_take isl_set *set) diff --git a/gcc/isl/isl_scan.c b/gcc/isl/isl_scan.c index fea42f1..c4666ed 100644 --- a/gcc/isl/isl_scan.c +++ a/gcc/isl/isl_scan.c @@ -102,7 +102,7 @@ isl_stat isl_basic_set_scan(__isl_take isl_basic_set *bset, struct isl_scan_callback *callback) { - unsigned dim; + isl_size dim; struct isl_mat *B = NULL; struct isl_tab *tab = NULL; struct isl_vec *min; @@ -112,10 +112,12 @@ int init; enum isl_lp_result res; - if (!bset) + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) { + bset = isl_basic_set_free(bset); return isl_stat_error; + } - dim = isl_basic_set_total_dim(bset); if (dim == 0) return scan_0D(bset, callback); diff --git a/gcc/isl/isl_schedule.c b/gcc/isl/isl_schedule.c index ddf0832..bdeeaba 100644 --- a/gcc/isl/isl_schedule.c +++ a/gcc/isl/isl_schedule.c @@ -589,7 +589,7 @@ * with two filters corresponding to the domains of the input schedules. * If one (or both) of the top-level nodes of the two schedules is itself * of type "type", then the filter is pushed into the children of that - * node and the sequence of set is flattened. + * node and the sequence or set is flattened. */ __isl_give isl_schedule *isl_schedule_pair(enum isl_schedule_node_type type, __isl_take isl_schedule *schedule1, __isl_take isl_schedule *schedule2) diff --git a/gcc/isl/isl_schedule_band.c b/gcc/isl/isl_schedule_band.c index e4825f3..668579a 100644 --- a/gcc/isl/isl_schedule_band.c +++ a/gcc/isl/isl_schedule_band.c @@ -48,19 +48,21 @@ __isl_give isl_schedule_band *isl_schedule_band_from_multi_union_pw_aff( __isl_take isl_multi_union_pw_aff *mupa) { + isl_size dim; isl_ctx *ctx; isl_schedule_band *band; isl_space *space; mupa = isl_multi_union_pw_aff_floor(mupa); - if (!mupa) - return NULL; + dim = isl_multi_union_pw_aff_size(mupa); + if (dim < 0) + goto error; ctx = isl_multi_union_pw_aff_get_ctx(mupa); band = isl_schedule_band_alloc(ctx); if (!band) goto error; - band->n = isl_multi_union_pw_aff_dim(mupa, isl_dim_set); + band->n = dim; band->coincident = isl_calloc_array(ctx, int, band->n); band->mupa = mupa; space = isl_space_params_alloc(ctx, 0); @@ -221,9 +223,9 @@ /* Return the number of scheduling dimensions in the band. */ -int isl_schedule_band_n_member(__isl_keep isl_schedule_band *band) +isl_size isl_schedule_band_n_member(__isl_keep isl_schedule_band *band) { - return band ? band->n : 0; + return band ? band->n : isl_size_error; } /* Is the given scheduling dimension coincident within the band and @@ -239,7 +241,7 @@ isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid, "invalid member position", return isl_bool_error); - return band->coincident[pos]; + return isl_bool_ok(band->coincident[pos]); } /* Mark the given scheduling dimension as being coincident or not @@ -272,7 +274,7 @@ { if (!band) return isl_bool_error; - return band->permutable; + return isl_bool_ok(band->permutable); } /* Mark the schedule band permutable or not according to "permutable"? @@ -371,7 +373,7 @@ if (pos < 0 || pos >= band->n) isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid, - "invalid member position", return -1); + "invalid member position", return isl_ast_loop_error); if (!band->loop_type) return isl_ast_loop_default; @@ -426,7 +428,7 @@ if (pos < 0 || pos >= band->n) isl_die(isl_schedule_band_get_ctx(band), isl_error_invalid, - "invalid member position", return -1); + "invalid member position", return isl_ast_loop_error); if (!band->isolate_loop_type) return isl_ast_loop_default; @@ -571,18 +573,30 @@ return options; } -/* Does "uset" contain any set that satisfies "is"? - * "is" is assumed to set its integer argument to 1 if it is satisfied. +/* Internal data structure for not(). + */ +struct isl_not_data { + isl_bool (*is)(__isl_keep isl_set *set); +}; + +/* Does "set" not satisfy data->is()? */ -static int has_any(__isl_keep isl_union_set *uset, - isl_stat (*is)(__isl_take isl_set *set, void *user)) +static isl_bool not(__isl_keep isl_set *set, void *user) { - int found = 0; + struct isl_not_data *data = user; - if (isl_union_set_foreach_set(uset, is, &found) < 0 && !found) - return -1; + return isl_bool_not(data->is(set)); +} + +/* Does "uset" contain any set that satisfies "is"? + * In other words, is it not the case that all of them do not satisfy "is"? + */ +static isl_bool has_any(__isl_keep isl_union_set *uset, + isl_bool (*is)(__isl_keep isl_set *set)) +{ + struct isl_not_data data = { is }; - return found; + return isl_bool_not(isl_union_set_every_set(uset, ¬, &data)); } /* Does "set" live in a space of the form @@ -590,22 +604,17 @@ * isolate[[...] -> [...]] * * ? - * - * If so, set *found and abort the search. */ -static isl_stat is_isolate(__isl_take isl_set *set, void *user) +static isl_bool is_isolate(__isl_keep isl_set *set) { - int *found = user; - if (isl_set_has_tuple_name(set)) { const char *name; name = isl_set_get_tuple_name(set); if (isl_set_is_wrapping(set) && !strcmp(name, "isolate")) - *found = 1; + return isl_bool_true; } - isl_set_free(set); - return *found ? isl_stat_error : isl_stat_ok; + return isl_bool_false; } /* Does "options" include an option of the ofrm @@ -614,19 +623,21 @@ * * ? */ -static int has_isolate_option(__isl_keep isl_union_set *options) +static isl_bool has_isolate_option(__isl_keep isl_union_set *options) { return has_any(options, &is_isolate); } /* Does "set" encode a loop AST generation option? */ -static isl_stat is_loop_type_option(__isl_take isl_set *set, void *user) +static isl_bool is_loop_type_option(__isl_keep isl_set *set) { - int *found = user; + isl_size dim; - if (isl_set_dim(set, isl_dim_set) == 1 && - isl_set_has_tuple_name(set)) { + dim = isl_set_dim(set, isl_dim_set); + if (dim < 0) + return isl_bool_error; + if (dim == 1 && isl_set_has_tuple_name(set)) { const char *name; enum isl_ast_loop_type type; name = isl_set_get_tuple_name(set); @@ -634,13 +645,11 @@ type <= isl_ast_loop_separate; ++type) { if (strcmp(name, option_str[type])) continue; - *found = 1; - break; + return isl_bool_true; } } - isl_set_free(set); - return *found ? isl_stat_error : isl_stat_ok; + return isl_bool_false; } /* Does "set" encode a loop AST generation option for the isolated part? @@ -650,22 +659,19 @@ * * with t equal to "atomic", "unroll" or "separate"? */ -static isl_stat is_isolate_loop_type_option(__isl_take isl_set *set, void *user) +static isl_bool is_isolate_loop_type_option(__isl_keep isl_set *set) { - int *found = user; const char *name; enum isl_ast_loop_type type; isl_map *map; - if (!isl_set_is_wrapping(set)) { - isl_set_free(set); - return isl_stat_ok; - } - map = isl_set_unwrap(set); + if (!isl_set_is_wrapping(set)) + return isl_bool_false; + map = isl_set_unwrap(isl_set_copy(set)); if (!isl_map_has_tuple_name(map, isl_dim_in) || !isl_map_has_tuple_name(map, isl_dim_out)) { isl_map_free(map); - return isl_stat_ok; + return isl_bool_false; } name = isl_map_get_tuple_name(map, isl_dim_in); if (!strcmp(name, "isolate")) { @@ -674,26 +680,26 @@ type <= isl_ast_loop_separate; ++type) { if (strcmp(name, option_str[type])) continue; - *found = 1; - break; + isl_map_free(map); + return isl_bool_true; } } isl_map_free(map); - return *found ? isl_stat_error : isl_stat_ok; + return isl_bool_false; } /* Does "options" encode any loop AST generation options * for the isolated part? */ -static int has_isolate_loop_type_options(__isl_keep isl_union_set *options) +static isl_bool has_isolate_loop_type_options(__isl_keep isl_union_set *options) { return has_any(options, &is_isolate_loop_type_option); } /* Does "options" encode any loop AST generation options? */ -static int has_loop_type_options(__isl_keep isl_union_set *options) +static isl_bool has_loop_type_options(__isl_keep isl_union_set *options) { return has_any(options, &is_loop_type_option); } @@ -859,7 +865,7 @@ __isl_give isl_schedule_band *isl_schedule_band_set_ast_build_options( __isl_take isl_schedule_band *band, __isl_take isl_union_set *options) { - int has_isolate, has_loop_type, has_isolate_loop_type; + isl_bool has_isolate, has_loop_type, has_isolate_loop_type; band = isl_schedule_band_cow(band); if (!band || !options) @@ -1076,14 +1082,17 @@ __isl_take isl_multi_val *sizes) { isl_ctx *ctx; - int i, n; + int i; + isl_size n; isl_val *v; int scale; ctx = isl_multi_val_get_ctx(sizes); scale = isl_options_get_tile_scale_tile_loops(ctx); - n = isl_multi_union_pw_aff_dim(sched, isl_dim_set); + n = isl_multi_union_pw_aff_size(sched); + if (n < 0) + sched = isl_multi_union_pw_aff_free(sched); for (i = 0; i < n; ++i) { isl_union_pw_aff *upa; diff --git a/gcc/isl/isl_schedule_band.h b/gcc/isl/isl_schedule_band.h index dcf16eb..fa4e5ca 100644 --- a/gcc/isl/isl_schedule_band.h +++ a/gcc/isl/isl_schedule_band.h @@ -86,7 +86,7 @@ __isl_take isl_schedule_band *band, __isl_take isl_set *drop, __isl_take isl_set *add); -int isl_schedule_band_n_member(__isl_keep isl_schedule_band *band); +isl_size isl_schedule_band_n_member(__isl_keep isl_schedule_band *band); isl_bool isl_schedule_band_member_get_coincident( __isl_keep isl_schedule_band *band, int pos); __isl_give isl_schedule_band *isl_schedule_band_member_set_coincident( diff --git a/gcc/isl/isl_schedule_constraints.c b/gcc/isl/isl_schedule_constraints.c index 13e8e5f..3d92b53 100644 --- a/gcc/isl/isl_schedule_constraints.c +++ a/gcc/isl/isl_schedule_constraints.c @@ -479,6 +479,18 @@ [isl_sc_key_context] = "context", }; +#undef BASE +#define BASE set +#include "print_yaml_field_templ.c" + +#undef BASE +#define BASE union_set +#include "print_yaml_field_templ.c" + +#undef BASE +#define BASE union_map +#include "print_yaml_field_templ.c" + /* Print a key, value pair for the edge of type "type" in "sc" to "p". * * If the edge relation is empty, then it is not printed since @@ -495,10 +507,7 @@ if (empty) return p; - p = isl_printer_print_str(p, key_str[type]); - p = isl_printer_yaml_next(p); - p = isl_printer_print_union_map(p, sc->constraint[type]); - p = isl_printer_yaml_next(p); + p = print_yaml_field_union_map(p, key_str[type], sc->constraint[type]); return p; } @@ -518,19 +527,14 @@ return isl_printer_free(p); p = isl_printer_yaml_start_mapping(p); - p = isl_printer_print_str(p, key_str[isl_sc_key_domain]); - p = isl_printer_yaml_next(p); - p = isl_printer_print_union_set(p, sc->domain); - p = isl_printer_yaml_next(p); + p = print_yaml_field_union_set(p, key_str[isl_sc_key_domain], + sc->domain); universe = isl_set_plain_is_universe(sc->context); if (universe < 0) return isl_printer_free(p); - if (!universe) { - p = isl_printer_print_str(p, key_str[isl_sc_key_context]); - p = isl_printer_yaml_next(p); - p = isl_printer_print_set(p, sc->context); - p = isl_printer_yaml_next(p); - } + if (!universe) + p = print_yaml_field_set(p, key_str[isl_sc_key_context], + sc->context); p = print_constraint(p, sc, isl_edge_validity); p = print_constraint(p, sc, isl_edge_proximity); p = print_constraint(p, sc, isl_edge_coincidence); @@ -710,11 +714,13 @@ static isl_stat add_n_basic_map(__isl_take isl_map *map, void *user) { int *n = user; + isl_size n_basic_map; - *n += isl_map_n_basic_map(map); + n_basic_map = isl_map_n_basic_map(map); + *n += n_basic_map; isl_map_free(map); - return isl_stat_ok; + return n_basic_map < 0 ? isl_stat_error : isl_stat_ok; } /* Return the total number of isl_basic_maps in the constraints of "sc". @@ -738,13 +744,19 @@ /* Return the total number of isl_maps in the constraints of "sc". */ -int isl_schedule_constraints_n_map(__isl_keep isl_schedule_constraints *sc) +isl_size isl_schedule_constraints_n_map(__isl_keep isl_schedule_constraints *sc) { enum isl_edge_type i; int n = 0; - for (i = isl_edge_first; i <= isl_edge_last; ++i) - n += isl_union_map_n_map(sc->constraint[i]); + for (i = isl_edge_first; i <= isl_edge_last; ++i) { + isl_size n_i; + + n_i = isl_union_map_n_map(sc->constraint[i]); + if (n_i < 0) + return isl_size_error; + n += n_i; + } return n; } diff --git a/gcc/isl/isl_schedule_constraints.h b/gcc/isl/isl_schedule_constraints.h index a50ec62..8ec3864 100644 --- a/gcc/isl/isl_schedule_constraints.h +++ a/gcc/isl/isl_schedule_constraints.h @@ -25,6 +25,7 @@ int isl_schedule_constraints_n_basic_map( __isl_keep isl_schedule_constraints *sc); -int isl_schedule_constraints_n_map(__isl_keep isl_schedule_constraints *sc); +isl_size isl_schedule_constraints_n_map( + __isl_keep isl_schedule_constraints *sc); #endif diff --git a/gcc/isl/isl_schedule_node.c b/gcc/isl/isl_schedule_node.c index 4fa5a8e..5e37276 100644 --- a/gcc/isl/isl_schedule_node.c +++ a/gcc/isl/isl_schedule_node.c @@ -11,6 +11,7 @@ * B.P. 105 - 78153 Le Chesnay, France */ +#include #include #include #include @@ -28,11 +29,12 @@ { isl_ctx *ctx; isl_schedule_node *node; - int i, n; + int i; + isl_size n; - if (!schedule || !tree || !ancestors) - goto error; n = isl_schedule_tree_list_n_schedule_tree(ancestors); + if (!schedule || !tree || n < 0) + goto error; if (n > 0 && !child_pos) goto error; ctx = isl_schedule_get_ctx(schedule); @@ -133,6 +135,7 @@ enum isl_schedule_node_type isl_schedule_node_get_parent_type( __isl_keep isl_schedule_node *node) { + isl_size n; int pos; int has_parent; isl_schedule_tree *parent; @@ -146,8 +149,11 @@ if (!has_parent) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "node has no parent", return isl_schedule_node_error); + n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_schedule_node_error; - pos = isl_schedule_tree_list_n_schedule_tree(node->ancestors) - 1; + pos = n - 1; parent = isl_schedule_tree_list_get_schedule_tree(node->ancestors, pos); type = isl_schedule_tree_get_type(parent); isl_schedule_tree_free(parent); @@ -242,7 +248,8 @@ isl_bool isl_schedule_node_is_equal(__isl_keep isl_schedule_node *node1, __isl_keep isl_schedule_node *node2) { - int i, n1, n2; + int i; + isl_size n1, n2; if (!node1 || !node2) return isl_bool_error; @@ -253,6 +260,8 @@ n1 = isl_schedule_node_get_tree_depth(node1); n2 = isl_schedule_node_get_tree_depth(node2); + if (n1 < 0 || n2 < 0) + return isl_bool_error; if (n1 != n2) return isl_bool_false; for (i = 0; i < n1; ++i) @@ -265,27 +274,36 @@ /* Return the number of outer schedule dimensions of "node" * in its schedule tree. * - * Return -1 on error. + * Return isl_size_error on error. */ -int isl_schedule_node_get_schedule_depth(__isl_keep isl_schedule_node *node) +isl_size isl_schedule_node_get_schedule_depth( + __isl_keep isl_schedule_node *node) { - int i, n; + int i; + isl_size n; int depth = 0; if (!node) - return -1; + return isl_size_error; n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_size_error; for (i = n - 1; i >= 0; --i) { isl_schedule_tree *tree; + isl_size n; tree = isl_schedule_tree_list_get_schedule_tree( node->ancestors, i); if (!tree) - return -1; + return isl_size_error; + n = 0; if (tree->type == isl_schedule_node_band) - depth += isl_schedule_tree_band_n_member(tree); + n = isl_schedule_tree_band_n_member(tree); + depth += n; isl_schedule_tree_free(tree); + if (n < 0) + return isl_size_error; } return depth; @@ -313,7 +331,7 @@ isl_multi_union_pw_aff *prefix; }; -static int collect_filter_prefix(__isl_keep isl_schedule_tree_list *list, +static isl_stat collect_filter_prefix(__isl_keep isl_schedule_tree_list *list, int n, struct isl_schedule_node_get_filter_prefix_data *data); /* Update the filter and prefix information in "data" based on the first "n" @@ -324,7 +342,8 @@ * Then we map the results to the expanded space and combined them * with the results already in "data". */ -static int collect_filter_prefix_expansion(__isl_take isl_schedule_tree *tree, +static isl_stat collect_filter_prefix_expansion( + __isl_take isl_schedule_tree *tree, __isl_keep isl_schedule_tree_list *list, int n, struct isl_schedule_node_get_filter_prefix_data *data) { @@ -377,7 +396,7 @@ isl_union_map_free(exp); isl_schedule_tree_free(tree); - return 0; + return isl_stat_ok; } /* Update the filter information in "data" based on the first "n" @@ -388,7 +407,8 @@ * add it to the universe range of the extension (intersected * with the already collected filter, if any). */ -static int collect_universe_domain_extension(__isl_take isl_schedule_tree *tree, +static isl_stat collect_universe_domain_extension( + __isl_take isl_schedule_tree *tree, __isl_keep isl_schedule_tree_list *list, int n, struct isl_schedule_node_get_filter_prefix_data *data) { @@ -418,7 +438,7 @@ isl_schedule_tree_free(tree); - return 0; + return isl_stat_ok; } /* Update "data" based on the tree node "tree" in case "data" has @@ -436,30 +456,31 @@ * to the universe of the schedule domain and replace the zero-dimensional * data->prefix by the band schedule (if data->collect_prefix is set). */ -static int collect_filter_prefix_init(__isl_keep isl_schedule_tree *tree, +static isl_stat collect_filter_prefix_init(__isl_keep isl_schedule_tree *tree, struct isl_schedule_node_get_filter_prefix_data *data) { enum isl_schedule_node_type type; isl_multi_union_pw_aff *mupa; isl_union_set *filter; + isl_size n; type = isl_schedule_tree_get_type(tree); switch (type) { case isl_schedule_node_error: - return -1; + return isl_stat_error; case isl_schedule_node_expansion: isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "should be handled by caller", return -1); + "should be handled by caller", return isl_stat_error); case isl_schedule_node_extension: isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, - "cannot handle extension nodes", return -1); + "cannot handle extension nodes", return isl_stat_error); case isl_schedule_node_context: case isl_schedule_node_leaf: case isl_schedule_node_guard: case isl_schedule_node_mark: case isl_schedule_node_sequence: case isl_schedule_node_set: - return 0; + return isl_stat_ok; case isl_schedule_node_domain: filter = isl_schedule_tree_domain_get_domain(tree); if (data->universe_domain) @@ -467,8 +488,11 @@ data->filter = filter; break; case isl_schedule_node_band: - if (isl_schedule_tree_band_n_member(tree) == 0) - return 0; + n = isl_schedule_tree_band_n_member(tree); + if (n < 0) + return isl_stat_error; + if (n == 0) + return isl_stat_ok; mupa = isl_schedule_tree_band_get_partial_schedule(tree); if (data->collect_prefix) { isl_multi_union_pw_aff_free(data->prefix); @@ -489,11 +513,11 @@ } if ((data->collect_prefix && !data->prefix) || !data->filter) - return -1; + return isl_stat_error; data->initialized = 1; - return 0; + return isl_stat_ok; } /* Update "data" based on the tree node "tree" in case "data" has @@ -510,22 +534,23 @@ * If "tree" is an extension, then we make sure that we are not collecting * information on any extended domain elements. */ -static int collect_filter_prefix_update(__isl_keep isl_schedule_tree *tree, +static isl_stat collect_filter_prefix_update(__isl_keep isl_schedule_tree *tree, struct isl_schedule_node_get_filter_prefix_data *data) { enum isl_schedule_node_type type; isl_multi_union_pw_aff *mupa; isl_union_set *filter; isl_union_map *extension; - int empty; + isl_bool empty; + isl_size n; type = isl_schedule_tree_get_type(tree); switch (type) { case isl_schedule_node_error: - return -1; + return isl_stat_error; case isl_schedule_node_expansion: isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "should be handled by caller", return -1); + "should be handled by caller", return isl_stat_error); case isl_schedule_node_extension: extension = isl_schedule_tree_extension_get_extension(tree); extension = isl_union_map_intersect_range(extension, @@ -533,11 +558,11 @@ empty = isl_union_map_is_empty(extension); isl_union_map_free(extension); if (empty < 0) - return -1; + return isl_stat_error; if (empty) break; isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, - "cannot handle extension nodes", return -1); + "cannot handle extension nodes", return isl_stat_error); case isl_schedule_node_context: case isl_schedule_node_leaf: case isl_schedule_node_guard: @@ -552,7 +577,10 @@ data->filter = isl_union_set_intersect(data->filter, filter); break; case isl_schedule_node_band: - if (isl_schedule_tree_band_n_member(tree) == 0) + n = isl_schedule_tree_band_n_member(tree); + if (n < 0) + return isl_stat_error; + if (n == 0) break; if (!data->collect_prefix) break; @@ -560,7 +588,7 @@ data->prefix = isl_multi_union_pw_aff_flat_range_product(mupa, data->prefix); if (!data->prefix) - return -1; + return isl_stat_error; break; case isl_schedule_node_filter: filter = isl_schedule_tree_filter_get_filter(tree); @@ -568,11 +596,11 @@ filter = isl_union_set_universe(filter); data->filter = isl_union_set_intersect(data->filter, filter); if (!data->filter) - return -1; + return isl_stat_error; break; } - return 0; + return isl_stat_ok; } /* Collect filter and/or prefix information from the first "n" @@ -601,22 +629,22 @@ * On successful return, data->initialized will be set since the outermost * ancestor is a domain node, which always results in an initialization. */ -static int collect_filter_prefix(__isl_keep isl_schedule_tree_list *list, +static isl_stat collect_filter_prefix(__isl_keep isl_schedule_tree_list *list, int n, struct isl_schedule_node_get_filter_prefix_data *data) { int i; if (!list) - return -1; + return isl_stat_error; for (i = n - 1; i >= 0; --i) { isl_schedule_tree *tree; enum isl_schedule_node_type type; - int r; + isl_stat r; tree = isl_schedule_tree_list_get_schedule_tree(list, i); if (!tree) - return -1; + return isl_stat_error; type = isl_schedule_tree_get_type(tree); if (type == isl_schedule_node_expansion) return collect_filter_prefix_expansion(tree, list, i, @@ -631,10 +659,10 @@ r = collect_filter_prefix_update(tree, data); isl_schedule_tree_free(tree); if (r < 0) - return -1; + return isl_stat_error; } - return 0; + return isl_stat_ok; } /* Return the concatenation of the partial schedules of all outer band @@ -655,7 +683,7 @@ isl_schedule_node_get_prefix_schedule_multi_union_pw_aff( __isl_keep isl_schedule_node *node) { - int n; + isl_size n; isl_space *space; struct isl_schedule_node_get_filter_prefix_data data; @@ -675,7 +703,7 @@ data.prefix = isl_multi_union_pw_aff_zero(space); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - if (collect_filter_prefix(node->ancestors, n, &data) < 0) + if (n < 0 || collect_filter_prefix(node->ancestors, n, &data) < 0) data.prefix = isl_multi_union_pw_aff_free(data.prefix); data.prefix = isl_multi_union_pw_aff_intersect_domain(data.prefix, @@ -707,7 +735,7 @@ isl_schedule_node_get_prefix_schedule_union_pw_multi_aff( __isl_keep isl_schedule_node *node) { - int n; + isl_size n, dim; isl_space *space; isl_union_pw_multi_aff *prefix; struct isl_schedule_node_get_filter_prefix_data data; @@ -728,11 +756,13 @@ data.prefix = isl_multi_union_pw_aff_zero(space); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - if (collect_filter_prefix(node->ancestors, n, &data) < 0) + if (n < 0 || collect_filter_prefix(node->ancestors, n, &data) < 0) data.prefix = isl_multi_union_pw_aff_free(data.prefix); - if (data.prefix && - isl_multi_union_pw_aff_dim(data.prefix, isl_dim_set) == 0) { + dim = isl_multi_union_pw_aff_dim(data.prefix, isl_dim_set); + if (dim < 0) + data.prefix = isl_multi_union_pw_aff_free(data.prefix); + if (data.prefix && dim == 0) { isl_multi_union_pw_aff_free(data.prefix); prefix = isl_union_pw_multi_aff_from_domain(data.filter); } else { @@ -772,7 +802,7 @@ __isl_give isl_union_map *isl_schedule_node_get_prefix_schedule_relation( __isl_keep isl_schedule_node *node) { - int n; + isl_size n, dim; isl_space *space; isl_union_map *prefix; struct isl_schedule_node_get_filter_prefix_data data; @@ -793,11 +823,13 @@ data.prefix = isl_multi_union_pw_aff_zero(space); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - if (collect_filter_prefix(node->ancestors, n, &data) < 0) + if (n < 0 || collect_filter_prefix(node->ancestors, n, &data) < 0) data.prefix = isl_multi_union_pw_aff_free(data.prefix); - if (data.prefix && - isl_multi_union_pw_aff_dim(data.prefix, isl_dim_set) == 0) { + dim = isl_multi_union_pw_aff_dim(data.prefix, isl_dim_set); + if (dim < 0) + data.prefix = isl_multi_union_pw_aff_free(data.prefix); + if (data.prefix && dim == 0) { isl_multi_union_pw_aff_free(data.prefix); prefix = isl_union_map_from_domain(data.filter); } else { @@ -823,7 +855,7 @@ __isl_give isl_union_set *isl_schedule_node_get_domain( __isl_keep isl_schedule_node *node) { - int n; + isl_size n; struct isl_schedule_node_get_filter_prefix_data data; if (!node) @@ -844,7 +876,7 @@ data.prefix = NULL; n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - if (collect_filter_prefix(node->ancestors, n, &data) < 0) + if (n < 0 || collect_filter_prefix(node->ancestors, n, &data) < 0) data.filter = isl_union_set_free(data.filter); return data.filter; @@ -862,7 +894,7 @@ __isl_give isl_union_set *isl_schedule_node_get_universe_domain( __isl_keep isl_schedule_node *node) { - int n; + isl_size n; struct isl_schedule_node_get_filter_prefix_data data; if (!node) @@ -883,7 +915,7 @@ data.prefix = NULL; n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - if (collect_filter_prefix(node->ancestors, n, &data) < 0) + if (n < 0 || collect_filter_prefix(node->ancestors, n, &data) < 0) data.filter = isl_union_set_free(data.filter); return data.filter; @@ -925,10 +957,10 @@ /* Return the number of ancestors of "node" in its schedule tree. */ -int isl_schedule_node_get_tree_depth(__isl_keep isl_schedule_node *node) +isl_size isl_schedule_node_get_tree_depth(__isl_keep isl_schedule_node *node) { if (!node) - return -1; + return isl_size_error; return isl_schedule_tree_list_n_schedule_tree(node->ancestors); } @@ -938,32 +970,33 @@ */ isl_bool isl_schedule_node_has_parent(__isl_keep isl_schedule_node *node) { - if (!node) - return isl_bool_error; - if (!node->ancestors) - return isl_bool_error; + isl_size depth; - return isl_schedule_tree_list_n_schedule_tree(node->ancestors) != 0; + depth = isl_schedule_node_get_tree_depth(node); + if (depth < 0) + return isl_bool_error; + return isl_bool_ok(depth != 0); } /* Return the position of "node" among the children of its parent. */ -int isl_schedule_node_get_child_position(__isl_keep isl_schedule_node *node) +isl_size isl_schedule_node_get_child_position( + __isl_keep isl_schedule_node *node) { - int n; - int has_parent; + isl_size n; + isl_bool has_parent; if (!node) - return -1; + return isl_size_error; has_parent = isl_schedule_node_has_parent(node); if (has_parent < 0) - return -1; + return isl_size_error; if (!has_parent) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, - "node has no parent", return -1); + "node has no parent", return isl_size_error); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - return node->child_pos[n - 1]; + return n < 0 ? isl_size_error : node->child_pos[n - 1]; } /* Does the parent (if any) of "node" have any children with a smaller child @@ -972,7 +1005,7 @@ isl_bool isl_schedule_node_has_previous_sibling( __isl_keep isl_schedule_node *node) { - int n; + isl_size n; isl_bool has_parent; if (!node) @@ -982,8 +1015,10 @@ return has_parent; n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_bool_error; - return node->child_pos[n - 1] > 0; + return isl_bool_ok(node->child_pos[n - 1] > 0); } /* Does the parent (if any) of "node" have any children with a greater child @@ -991,7 +1026,7 @@ */ isl_bool isl_schedule_node_has_next_sibling(__isl_keep isl_schedule_node *node) { - int n, n_child; + isl_size n, n_child; isl_bool has_parent; isl_schedule_tree *tree; @@ -1002,13 +1037,15 @@ return has_parent; n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); - tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n - 1); - if (!tree) + if (n < 0) return isl_bool_error; - n_child = isl_schedule_tree_list_n_schedule_tree(tree->children); + tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n - 1); + n_child = isl_schedule_tree_n_children(tree); isl_schedule_tree_free(tree); + if (n_child < 0) + return isl_bool_error; - return node->child_pos[n - 1] + 1 < n_child; + return isl_bool_ok(node->child_pos[n - 1] + 1 < n_child); } /* Does "node" have any children? @@ -1021,7 +1058,7 @@ { if (!node) return isl_bool_error; - return !isl_schedule_tree_is_leaf(node->tree); + return isl_bool_ok(!isl_schedule_tree_is_leaf(node->tree)); } /* Return the number of children of "node"? @@ -1034,17 +1071,19 @@ * to the number of children of "node". If it has zero children, * then "node" still has a leaf node as child. */ -int isl_schedule_node_n_children(__isl_keep isl_schedule_node *node) +isl_size isl_schedule_node_n_children(__isl_keep isl_schedule_node *node) { - int n; + isl_size n; if (!node) - return -1; + return isl_size_error; if (isl_schedule_tree_is_leaf(node->tree)) return 0; n = isl_schedule_tree_n_children(node->tree); + if (n < 0) + return isl_size_error; if (n == 0) return 1; @@ -1058,7 +1097,7 @@ __isl_give isl_schedule_node *isl_schedule_node_ancestor( __isl_take isl_schedule_node *node, int generation) { - int n; + isl_size n; isl_schedule_tree *tree; if (!node) @@ -1107,7 +1146,7 @@ __isl_give isl_schedule_node *isl_schedule_node_root( __isl_take isl_schedule_node *node) { - int n; + isl_size n; if (!node) return NULL; @@ -1123,7 +1162,7 @@ __isl_give isl_schedule_node *isl_schedule_node_child( __isl_take isl_schedule_node *node, int pos) { - int n; + isl_size n; isl_ctx *ctx; isl_schedule_tree *tree; int *child_pos; @@ -1138,6 +1177,8 @@ ctx = isl_schedule_node_get_ctx(node); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_schedule_node_free(node); child_pos = isl_realloc_array(ctx, node->child_pos, int, n + 1); if (!child_pos) return isl_schedule_node_free(node); @@ -1175,7 +1216,7 @@ __isl_give isl_schedule_node *isl_schedule_node_previous_sibling( __isl_take isl_schedule_node *node) { - int n; + isl_size n; isl_schedule_tree *parent, *tree; node = isl_schedule_node_cow(node); @@ -1187,6 +1228,8 @@ return isl_schedule_node_free(node)); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_schedule_node_free(node); parent = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n - 1); if (!parent) @@ -1209,7 +1252,7 @@ __isl_give isl_schedule_node *isl_schedule_node_next_sibling( __isl_take isl_schedule_node *node) { - int n; + isl_size n; isl_schedule_tree *parent, *tree; node = isl_schedule_node_cow(node); @@ -1221,6 +1264,8 @@ return isl_schedule_node_free(node)); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_schedule_node_free(node); parent = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n - 1); if (!parent) @@ -1259,23 +1304,27 @@ __isl_take isl_schedule_node *node, void *user), void *user) { - int depth; - - if (!node) - return NULL; + isl_size depth; + isl_size node_depth; depth = isl_schedule_node_get_tree_depth(node); + if (depth < 0) + return isl_schedule_node_free(node); + do { node = enter(node, user); node = leave(node, user); - while (node && isl_schedule_node_get_tree_depth(node) > depth && + while ((node_depth = isl_schedule_node_get_tree_depth(node)) > + depth && !isl_schedule_node_has_next_sibling(node)) { node = isl_schedule_node_parent(node); node = leave(node, user); } - if (node && isl_schedule_node_get_tree_depth(node) > depth) + if (node_depth < 0) + return isl_schedule_node_free(node); + if (node_depth > depth) node = isl_schedule_node_next_sibling(node); - } while (node && isl_schedule_node_get_tree_depth(node) > depth); + } while (node_depth > depth); return node; } @@ -1477,12 +1526,13 @@ isl_stat (*fn)(__isl_keep isl_schedule_node *node, void *user), void *user) { - int i, n; + int i; + isl_size n; - if (!node) + n = isl_schedule_node_get_tree_depth(node); + if (n < 0) return isl_stat_error; - n = isl_schedule_node_get_tree_depth(node); for (i = 0; i < n; ++i) { isl_schedule_node *ancestor; isl_stat r; @@ -1511,9 +1561,11 @@ /* Return the number of members in the given band node. */ -unsigned isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node) +isl_size isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node) { - return node ? isl_schedule_tree_band_n_member(node->tree) : 0; + if (!node) + return isl_size_error; + return isl_schedule_tree_band_n_member(node->tree); } /* Is the band member at position "pos" of the band node "node" @@ -1613,6 +1665,7 @@ __isl_give isl_union_map *isl_schedule_node_band_get_partial_schedule_union_map( __isl_keep isl_schedule_node *node) { + isl_size n; isl_multi_union_pw_aff *mupa; if (!node) @@ -1621,7 +1674,10 @@ if (isl_schedule_node_get_type(node) != isl_schedule_node_band) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "not a band node", return NULL); - if (isl_schedule_node_band_n_member(node) == 0) { + n = isl_schedule_node_band_n_member(node); + if (n < 0) + return NULL; + if (n == 0) { isl_union_set *domain; domain = isl_schedule_node_get_universe_domain(node); @@ -1728,12 +1784,12 @@ __isl_give isl_set *isl_schedule_node_band_get_ast_isolate_option( __isl_keep isl_schedule_node *node) { - int depth; + isl_size depth; - if (!node) + depth = isl_schedule_node_get_schedule_depth(node); + if (depth < 0) return NULL; - depth = isl_schedule_node_get_schedule_depth(node); return isl_schedule_tree_band_get_ast_isolate_option(node->tree, depth); } @@ -1979,7 +2035,8 @@ enum isl_schedule_node_type type; isl_schedule_tree *tree, *child; isl_union_pw_multi_aff *contraction; - int anchored; + isl_bool anchored; + isl_size n; if (!node) return NULL; @@ -1995,7 +2052,10 @@ isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "cannot sink band node in anchored subtree", return isl_schedule_node_free(node)); - if (isl_schedule_tree_n_children(node->tree) == 0) + n = isl_schedule_tree_n_children(node->tree); + if (n < 0) + return isl_schedule_node_free(node); + if (n == 0) return node; contraction = isl_schedule_node_get_subtree_contraction(node); @@ -2018,10 +2078,12 @@ __isl_give isl_schedule_node *isl_schedule_node_band_split( __isl_take isl_schedule_node *node, int pos) { - int depth; + isl_size depth; isl_schedule_tree *tree; depth = isl_schedule_node_get_schedule_depth(node); + if (depth < 0) + return isl_schedule_node_free(node); tree = isl_schedule_node_get_tree(node); tree = isl_schedule_tree_band_split(tree, pos, depth); return isl_schedule_node_graft_tree(node, tree); @@ -2249,7 +2311,8 @@ __isl_give isl_schedule_node *isl_schedule_node_sequence_splice_child( __isl_take isl_schedule_node *node, int pos) { - int i, n; + int i; + isl_size n; isl_union_set *filter; isl_schedule_node *child; isl_schedule_tree *tree; @@ -2266,10 +2329,12 @@ isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "not a sequence node", return isl_schedule_node_free(node)); + n = isl_schedule_node_n_children(node); + if (n < 0) + return isl_schedule_node_free(node); child = isl_schedule_node_copy(node); node = isl_schedule_node_parent(node); filter = isl_schedule_node_filter_get_filter(node); - n = isl_schedule_node_n_children(child); for (i = 0; i < n; ++i) { child = isl_schedule_node_child(child, i); child = isl_schedule_node_filter_intersect_filter(child, @@ -2305,7 +2370,8 @@ __isl_give isl_schedule_tree *(*fn)(__isl_take isl_schedule_tree *tree, __isl_keep isl_schedule_node *pos, void *user), void *user) { - int i, n; + int i; + isl_size n; int is_leaf; isl_schedule_tree *tree; isl_schedule_node *pos = NULL; @@ -2318,6 +2384,8 @@ return isl_schedule_node_free(pos); n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) + return isl_schedule_node_free(pos); tree = isl_schedule_tree_copy(node->tree); for (i = n - 1; i >= 0; --i) { @@ -2571,7 +2639,8 @@ enum isl_schedule_node_type type, __isl_take isl_union_set_list *filters) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_schedule_tree *tree; isl_schedule_tree_list *list; @@ -2579,11 +2648,11 @@ if (check_insert(node) < 0) node = isl_schedule_node_free(node); - if (!node || !filters) + n = isl_union_set_list_n_union_set(filters); + if (!node || n < 0) goto error; ctx = isl_schedule_node_get_ctx(node); - n = isl_union_set_list_n_union_set(filters); list = isl_schedule_tree_list_alloc(ctx, n); for (i = 0; i < n; ++i) { isl_schedule_node *node_i; @@ -2676,18 +2745,19 @@ __isl_give isl_schedule_node *isl_schedule_node_delete( __isl_take isl_schedule_node *node) { - int n; + isl_size n, depth; isl_schedule_tree *tree; enum isl_schedule_node_type type; - if (!node) - return NULL; + depth = isl_schedule_node_get_tree_depth(node); + n = isl_schedule_node_n_children(node); + if (depth < 0 || n < 0) + return isl_schedule_node_free(node); - if (isl_schedule_node_get_tree_depth(node) == 0) + if (depth == 0) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "cannot delete root node", return isl_schedule_node_free(node)); - n = isl_schedule_node_n_children(node); if (n != 1) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, "can only delete node with a single child", @@ -2759,10 +2829,10 @@ /* Is domain covered by data->domain within data->domain_universe? */ -static int locally_covered_by_domain(__isl_keep isl_union_set *domain, +static isl_bool locally_covered_by_domain(__isl_keep isl_union_set *domain, struct isl_schedule_group_data *data) { - int is_subset; + isl_bool is_subset; isl_union_set *test; test = isl_union_set_copy(domain); @@ -2793,8 +2863,9 @@ isl_union_set *domain; isl_multi_aff *ma; isl_multi_union_pw_aff *mupa, *partial; - int is_covered; - int depth, n, has_id; + isl_bool is_covered; + isl_size depth, n; + isl_bool has_id; domain = isl_schedule_node_get_domain(pos); is_covered = locally_covered_by_domain(domain, data); @@ -2809,6 +2880,8 @@ return isl_schedule_tree_free(tree); depth = isl_schedule_node_get_schedule_depth(pos); n = isl_schedule_tree_band_n_member(tree); + if (depth < 0 || n < 0) + return isl_schedule_tree_free(tree); ma = isl_multi_aff_copy(data->sched); ma = isl_multi_aff_drop_dims(ma, isl_dim_out, 0, depth); ma = isl_multi_aff_drop_dims(ma, isl_dim_out, n, data->dim - depth - n); @@ -2835,10 +2908,12 @@ static __isl_give isl_union_set *union_set_drop_extra_params( __isl_take isl_union_set *uset, __isl_keep isl_space *space, int n) { - int n2; + isl_size n2; uset = isl_union_set_align_params(uset, isl_space_copy(space)); n2 = isl_union_set_dim(uset, isl_dim_param); + if (n2 < 0) + return isl_union_set_free(uset); uset = isl_union_set_project_out(uset, isl_dim_param, n, n2 - n); return uset; @@ -2859,10 +2934,14 @@ { isl_space *space; isl_union_set *domain; - int n1, n2; - int involves; - - if (isl_schedule_node_get_tree_depth(pos) == 1) + isl_size n1, n2; + isl_bool involves; + isl_size depth; + + depth = isl_schedule_node_get_tree_depth(pos); + if (depth < 0) + return isl_schedule_tree_free(tree); + if (depth == 1) return tree; domain = isl_schedule_node_get_universe_domain(pos); @@ -2873,7 +2952,7 @@ data->expansion = isl_union_map_align_params(data->expansion, space); n2 = isl_union_map_dim(data->expansion, isl_dim_param); - if (!data->expansion) + if (n1 < 0 || n2 < 0) return isl_schedule_tree_free(tree); if (n1 == n2) return tree; @@ -2894,6 +2973,9 @@ data->contraction = isl_union_pw_multi_aff_align_params( data->contraction, isl_space_copy(space)); n2 = isl_union_pw_multi_aff_dim(data->contraction, isl_dim_param); + if (n2 < 0) + data->contraction = + isl_union_pw_multi_aff_free(data->contraction); data->contraction = isl_union_pw_multi_aff_drop_dims(data->contraction, isl_dim_param, n1, n2 - n1); @@ -2907,6 +2989,8 @@ data->sched = isl_multi_aff_align_params(data->sched, isl_space_copy(space)); n2 = isl_multi_aff_dim(data->sched, isl_dim_param); + if (n2 < 0) + data->sched = isl_multi_aff_free(data->sched); data->sched = isl_multi_aff_drop_dims(data->sched, isl_dim_param, n1, n2 - n1); @@ -2929,7 +3013,7 @@ struct isl_schedule_group_data *data) { isl_union_set *domain; - int is_subset; + isl_bool is_subset; domain = isl_schedule_tree_domain_get_domain(tree); is_subset = isl_union_set_is_subset(data->domain, domain); @@ -3032,7 +3116,7 @@ { struct isl_schedule_group_data *data = user; isl_union_set *domain; - int is_covered; + isl_bool is_covered; if (!tree || !pos) return isl_schedule_tree_free(tree); @@ -3113,9 +3197,11 @@ isl_union_set *domain; isl_union_pw_multi_aff *contraction; isl_union_map *expansion; - int disjoint; + isl_bool disjoint; + isl_size depth; - if (!node || !group_id) + depth = isl_schedule_node_get_schedule_depth(node); + if (depth < 0 || !group_id) goto error; if (check_insert(node) < 0) goto error; @@ -3125,7 +3211,7 @@ data.domain_universe = isl_union_set_copy(domain); data.domain_universe = isl_union_set_universe(data.domain_universe); - data.dim = isl_schedule_node_get_schedule_depth(node); + data.dim = depth; if (data.dim == 0) { isl_ctx *ctx; isl_set *set; @@ -3235,7 +3321,7 @@ static __isl_give isl_schedule_node *gist_enter_expansion( __isl_take isl_schedule_node *node, struct isl_node_gist_data *data) { - int n; + isl_size n; isl_union_set *inner; isl_union_map *expansion; isl_union_pw_multi_aff *contraction; @@ -3243,6 +3329,8 @@ data->n_expansion++; n = isl_union_set_list_n_union_set(data->filters); + if (n < 0) + return isl_schedule_node_free(node); inner = isl_union_set_list_get_union_set(data->filters, n - 1); expansion = isl_schedule_node_expansion_get_expansion(node); inner = isl_union_set_apply(inner, expansion); @@ -3274,7 +3362,7 @@ static __isl_give isl_schedule_node *gist_leave_expansion( __isl_take isl_schedule_node *node, struct isl_node_gist_data *data) { - int n; + isl_size n; isl_bool identity; isl_union_map *expansion; @@ -3288,6 +3376,8 @@ node = isl_schedule_node_delete(node); n = isl_union_set_list_n_union_set(data->filters); + if (n < 0) + return isl_schedule_node_free(node); data->filters = isl_union_set_list_drop(data->filters, n - 1, 1); data->n_expansion--; @@ -3304,11 +3394,13 @@ static __isl_give isl_schedule_node *gist_enter_extension( __isl_take isl_schedule_node *node, struct isl_node_gist_data *data) { - int n; + isl_size n; isl_union_set *inner, *extra; isl_union_map *extension; n = isl_union_set_list_n_union_set(data->filters); + if (n < 0) + return isl_schedule_node_free(node); inner = isl_union_set_list_get_union_set(data->filters, n - 1); extension = isl_schedule_node_extension_get_extension(node); extra = isl_union_map_range(extension); @@ -3326,14 +3418,14 @@ * this test since the current domain elements are incomparable * to the domain elements in the original context. */ -static int gist_done(__isl_keep isl_schedule_node *node, +static isl_bool gist_done(__isl_keep isl_schedule_node *node, struct isl_node_gist_data *data) { isl_union_set *filter, *outer; - int subset; + isl_bool subset; if (data->n_expansion != 0) - return 0; + return isl_bool_false; filter = isl_schedule_node_filter_get_filter(node); outer = isl_union_set_list_get_union_set(data->filters, 0); @@ -3380,8 +3472,8 @@ do { isl_union_set *filter, *inner; - int done, empty; - int n; + isl_bool done, empty; + isl_size n; switch (isl_schedule_node_get_type(node)) { case isl_schedule_node_error: @@ -3406,14 +3498,14 @@ } done = gist_done(node, data); filter = isl_schedule_node_filter_get_filter(node); - if (done < 0 || done) { + n = isl_union_set_list_n_union_set(data->filters); + if (n < 0 || done < 0 || done) { data->filters = isl_union_set_list_add(data->filters, filter); - if (done < 0) + if (n < 0 || done < 0) return isl_schedule_node_free(node); return node; } - n = isl_union_set_list_n_union_set(data->filters); inner = isl_union_set_list_get_union_set(data->filters, n - 1); filter = isl_union_set_gist(filter, isl_union_set_copy(inner)); node = isl_schedule_node_filter_set_filter(node, @@ -3466,7 +3558,8 @@ { struct isl_node_gist_data *data = user; isl_schedule_tree *tree; - int i, n; + int i; + isl_size n; isl_union_set *filter; switch (isl_schedule_node_get_type(node)) { @@ -3478,11 +3571,15 @@ case isl_schedule_node_extension: case isl_schedule_node_filter: n = isl_union_set_list_n_union_set(data->filters); + if (n < 0) + return isl_schedule_node_free(node); data->filters = isl_union_set_list_drop(data->filters, n - 1, 1); break; case isl_schedule_node_band: n = isl_union_set_list_n_union_set(data->filters); + if (n < 0) + return isl_schedule_node_free(node); filter = isl_union_set_list_get_union_set(data->filters, n - 1); node = isl_schedule_node_band_gist(node, filter); break; @@ -3490,10 +3587,12 @@ case isl_schedule_node_sequence: tree = isl_schedule_node_get_tree(node); n = isl_schedule_tree_n_children(tree); + if (n < 0) + tree = isl_schedule_tree_free(tree); for (i = n - 1; i >= 0; --i) { isl_schedule_tree *child; isl_union_set *filter; - int empty; + isl_bool empty; child = isl_schedule_tree_get_child(tree, i); filter = isl_schedule_tree_filter_get_filter(child); @@ -3506,6 +3605,8 @@ tree = isl_schedule_tree_drop_child(tree, i); } n = isl_schedule_tree_n_children(tree); + if (n < 0) + tree = isl_schedule_tree_free(tree); node = isl_schedule_node_graft_tree(node, tree); if (n == 1) { node = isl_schedule_node_delete(node); @@ -3661,7 +3762,7 @@ enum isl_schedule_node_type type; isl_union_set *filter; isl_union_map *inner, *expansion; - int n; + isl_size n; switch (isl_schedule_node_get_type(node)) { case isl_schedule_node_error: @@ -3673,6 +3774,9 @@ break; filter = isl_schedule_node_filter_get_filter(node); n = isl_union_map_list_n_union_map(data->expansions); + if (n < 0) + data->expansions = + isl_union_map_list_free(data->expansions); inner = isl_union_map_list_get_union_map(data->expansions, n - 1); @@ -3682,6 +3786,9 @@ break; case isl_schedule_node_expansion: n = isl_union_map_list_n_union_map(data->expansions); + if (n < 0) + data->expansions = + isl_union_map_list_free(data->expansions); expansion = isl_schedule_node_expansion_get_expansion(node); inner = @@ -3723,7 +3830,7 @@ __isl_take isl_schedule_node *node, void *user) { struct isl_subtree_expansion_data *data = user; - int n; + isl_size n; isl_union_map *inner; enum isl_schedule_node_type type; @@ -3736,11 +3843,17 @@ type != isl_schedule_node_sequence) break; n = isl_union_map_list_n_union_map(data->expansions); + if (n < 0) + data->expansions = + isl_union_map_list_free(data->expansions); data->expansions = isl_union_map_list_drop(data->expansions, n - 1, 1); break; case isl_schedule_node_leaf: n = isl_union_map_list_n_union_map(data->expansions); + if (n < 0) + data->expansions = + isl_union_map_list_free(data->expansions); inner = isl_union_map_list_get_union_map(data->expansions, n - 1); data->res = isl_union_map_union(data->res, inner); @@ -3834,7 +3947,7 @@ enum isl_schedule_node_type type; isl_union_set *filter; isl_union_pw_multi_aff *inner, *contraction; - int n; + isl_size n; switch (isl_schedule_node_get_type(node)) { case isl_schedule_node_error: @@ -3847,6 +3960,10 @@ filter = isl_schedule_node_filter_get_filter(node); n = isl_union_pw_multi_aff_list_n_union_pw_multi_aff( data->contractions); + if (n < 0) + data->contractions = + isl_union_pw_multi_aff_list_free( + data->contractions); inner = isl_union_pw_multi_aff_list_get_union_pw_multi_aff( data->contractions, n - 1); @@ -3859,6 +3976,10 @@ case isl_schedule_node_expansion: n = isl_union_pw_multi_aff_list_n_union_pw_multi_aff( data->contractions); + if (n < 0) + data->contractions = + isl_union_pw_multi_aff_list_free( + data->contractions); contraction = isl_schedule_node_expansion_get_contraction(node); inner = @@ -3902,7 +4023,7 @@ __isl_take isl_schedule_node *node, void *user) { struct isl_subtree_contraction_data *data = user; - int n; + isl_size n; isl_union_pw_multi_aff *inner; enum isl_schedule_node_type type; @@ -3916,6 +4037,9 @@ break; n = isl_union_pw_multi_aff_list_n_union_pw_multi_aff( data->contractions); + if (n < 0) + data->contractions = isl_union_pw_multi_aff_list_free( + data->contractions); data->contractions = isl_union_pw_multi_aff_list_drop(data->contractions, n - 1, 1); @@ -3923,6 +4047,9 @@ case isl_schedule_node_leaf: n = isl_union_pw_multi_aff_list_n_union_pw_multi_aff( data->contractions); + if (n < 0) + data->contractions = isl_union_pw_multi_aff_list_free( + data->contractions); inner = isl_union_pw_multi_aff_list_get_union_pw_multi_aff( data->contractions, n - 1); data->res = isl_union_pw_multi_aff_union_add(data->res, inner); @@ -3986,17 +4113,20 @@ /* Do the nearest "n" ancestors of "node" have the types given in "types" * (starting at the parent of "node")? */ -static int has_ancestors(__isl_keep isl_schedule_node *node, +static isl_bool has_ancestors(__isl_keep isl_schedule_node *node, int n, enum isl_schedule_node_type *types) { - int i, n_ancestor; + int i; + isl_size n_ancestor; if (!node) - return -1; + return isl_bool_error; n_ancestor = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n_ancestor < 0) + return isl_bool_error; if (n_ancestor < n) - return 0; + return isl_bool_false; for (i = 0; i < n; ++i) { isl_schedule_tree *tree; @@ -4005,14 +4135,14 @@ tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n_ancestor - 1 - i); if (!tree) - return -1; + return isl_bool_error; correct_type = isl_schedule_tree_get_type(tree) == types[i]; isl_schedule_tree_free(tree); if (!correct_type) - return 0; + return isl_bool_false; } - return 1; + return isl_bool_true; } /* Given a node "node" that appears in an extension (i.e., it is the child @@ -4057,12 +4187,14 @@ static __isl_give isl_schedule_node *extend_extension( __isl_take isl_schedule_node *node, __isl_take isl_union_map *extension) { - int pos; - int disjoint; + isl_size pos; + isl_bool disjoint; isl_union_map *node_extension; node = isl_schedule_node_parent(node); pos = isl_schedule_node_get_child_position(node); + if (pos < 0) + node = isl_schedule_node_free(node); node = isl_schedule_node_parent(node); node = isl_schedule_node_parent(node); node_extension = isl_schedule_node_extension_get_extension(node); @@ -4141,7 +4273,7 @@ isl_schedule_node_extension }; isl_union_set *domain; isl_union_set *filter; - int in_ext; + isl_bool in_ext; in_ext = has_ancestors(node, 3, ancestors); if (in_ext < 0) @@ -4182,11 +4314,13 @@ __isl_take isl_schedule_node *node, __isl_take isl_schedule_tree *tree, int tree_pos) { - int pos; + isl_size pos; if (isl_schedule_node_get_parent_type(node) == isl_schedule_node_sequence) { pos = isl_schedule_node_get_child_position(node); + if (pos < 0) + node = isl_schedule_node_free(node); node = isl_schedule_node_parent(node); node = isl_schedule_node_sequence_splice(node, pos, tree); } else { @@ -4265,21 +4399,21 @@ isl_union_set *universe; isl_union_set *domain; isl_union_map *ext; - int depth; - int anchored; + isl_size depth; + isl_bool anchored; isl_space *space; isl_schedule_node *res; isl_schedule_tree *tree; + depth = isl_schedule_node_get_schedule_depth(pos); anchored = isl_schedule_node_is_subtree_anchored(node); - if (anchored < 0) + if (depth < 0 || anchored < 0) return isl_schedule_node_free(node); if (anchored) isl_die(isl_schedule_node_get_ctx(node), isl_error_unsupported, "cannot graft anchored tree with domain root", return isl_schedule_node_free(node)); - depth = isl_schedule_node_get_schedule_depth(pos); domain = isl_schedule_node_domain_get_domain(node); space = isl_union_set_get_space(domain); space = isl_space_set_from_params(space); @@ -4413,8 +4547,8 @@ isl_union_set *node_domain, *node_filter = NULL, *parent_filter; isl_schedule_node *node2; isl_schedule_tree *tree1, *tree2; - int empty1, empty2; - int in_seq; + isl_bool empty1, empty2; + isl_bool in_seq; if (!node || !filter) goto error; @@ -4648,33 +4782,32 @@ * of "ancestor". "node" is assumed to be a descendant of "ancestor". * In particular, both nodes should point to the same schedule tree. * - * Return -1 on error. + * Return isl_size_error on error. */ -int isl_schedule_node_get_ancestor_child_position( +isl_size isl_schedule_node_get_ancestor_child_position( __isl_keep isl_schedule_node *node, __isl_keep isl_schedule_node *ancestor) { - int n1, n2; + isl_size n1, n2; isl_schedule_tree *tree; - if (!node || !ancestor) - return -1; + n1 = isl_schedule_node_get_tree_depth(ancestor); + n2 = isl_schedule_node_get_tree_depth(node); + if (n1 < 0 || n2 < 0) + return isl_size_error; if (node->schedule != ancestor->schedule) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, - "not a descendant", return -1); - - n1 = isl_schedule_node_get_tree_depth(ancestor); - n2 = isl_schedule_node_get_tree_depth(node); + "not a descendant", return isl_size_error); if (n1 >= n2) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, - "not a descendant", return -1); + "not a descendant", return isl_size_error); tree = isl_schedule_tree_list_get_schedule_tree(node->ancestors, n1); isl_schedule_tree_free(tree); if (tree != ancestor->tree) isl_die(isl_schedule_node_get_ctx(node), isl_error_invalid, - "not a descendant", return -1); + "not a descendant", return isl_size_error); return node->child_pos[n1]; } @@ -4694,15 +4827,16 @@ __isl_keep isl_schedule_node *node1, __isl_keep isl_schedule_node *node2) { - int i, n1, n2; + int i; + isl_size n1, n2; - if (!node1 || !node2) + n1 = isl_schedule_node_get_tree_depth(node1); + n2 = isl_schedule_node_get_tree_depth(node2); + if (n1 < 0 || n2 < 0) return NULL; if (node1->schedule != node2->schedule) isl_die(isl_schedule_node_get_ctx(node1), isl_error_invalid, "not part of same schedule", return NULL); - n1 = isl_schedule_node_get_tree_depth(node1); - n2 = isl_schedule_node_get_tree_depth(node2); if (n2 < n1) return isl_schedule_node_get_shared_ancestor(node2, node1); if (n1 == 0) @@ -4723,10 +4857,14 @@ __isl_give isl_printer *isl_printer_print_schedule_node( __isl_take isl_printer *p, __isl_keep isl_schedule_node *node) { + isl_size n; + if (!node) + return isl_printer_free(p); + n = isl_schedule_tree_list_n_schedule_tree(node->ancestors); + if (n < 0) return isl_printer_free(p); - return isl_printer_print_schedule_tree_mark(p, node->schedule->root, - isl_schedule_tree_list_n_schedule_tree(node->ancestors), + return isl_printer_print_schedule_tree_mark(p, node->schedule->root, n, node->child_pos); } diff --git a/gcc/isl/isl_schedule_read.c b/gcc/isl/isl_schedule_read.c index eafc720..71fdeed 100644 --- a/gcc/isl/isl_schedule_read.c +++ a/gcc/isl/isl_schedule_read.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -477,10 +478,12 @@ __isl_take isl_schedule_band *band, __isl_take isl_val_list *coincident) { int i; - int n, m; + isl_size n, m; n = isl_schedule_band_n_member(band); m = isl_val_list_n_val(coincident); + if (n < 0 || m < 0) + band = isl_schedule_band_free(band); for (i = 0; i < n && i < m; ++i) { isl_val *v; @@ -713,7 +716,7 @@ break; case isl_schedule_key_child: isl_die(isl_stream_get_ctx(s), isl_error_unsupported, - "cannot identity node type", return NULL); + "cannot identify node type", return NULL); case isl_schedule_key_end: case isl_schedule_key_error: return NULL; diff --git a/gcc/isl/isl_schedule_tree.c b/gcc/isl/isl_schedule_tree.c index 1b92e86..2a20a33 100644 --- a/gcc/isl/isl_schedule_tree.c +++ a/gcc/isl/isl_schedule_tree.c @@ -13,6 +13,7 @@ * CS 42112, 75589 Paris Cedex 12, France */ +#include #include #include #include @@ -24,8 +25,8 @@ #include -#undef BASE -#define BASE schedule_tree +#undef EL_BASE +#define EL_BASE schedule_tree #include @@ -441,7 +442,7 @@ isl_bool isl_schedule_tree_is_subtree_anchored( __isl_keep isl_schedule_tree *tree) { - return tree ? tree->anchored : isl_bool_error; + return tree ? isl_bool_ok(tree->anchored) : isl_bool_error; } /* Does the root node of "tree" depend on its position in the complete @@ -486,17 +487,15 @@ __isl_give isl_schedule_tree *isl_schedule_tree_update_anchored( __isl_take isl_schedule_tree *tree) { - int i, n; + int i; + isl_size n; int anchored; - - if (!tree) - return NULL; anchored = isl_schedule_tree_is_anchored(tree); - if (anchored < 0) + n = isl_schedule_tree_n_children(tree); + if (anchored < 0 || n < 0) return isl_schedule_tree_free(tree); - n = isl_schedule_tree_list_n_schedule_tree(tree->children); for (i = 0; !anchored && i < n; ++i) { isl_schedule_tree *child; @@ -630,7 +629,8 @@ __isl_keep isl_schedule_tree *tree2) { isl_bool equal; - int i, n; + int i; + isl_size n1, n2; if (!tree1 || !tree2) return isl_bool_error; @@ -668,7 +668,7 @@ equal = isl_set_is_equal(tree1->guard, tree2->guard); break; case isl_schedule_node_mark: - equal = tree1->mark == tree2->mark; + equal = isl_bool_ok(tree1->mark == tree2->mark); break; case isl_schedule_node_leaf: case isl_schedule_node_sequence: @@ -683,10 +683,13 @@ if (equal < 0 || !equal) return equal; - n = isl_schedule_tree_n_children(tree1); - if (n != isl_schedule_tree_n_children(tree2)) + n1 = isl_schedule_tree_n_children(tree1); + n2 = isl_schedule_tree_n_children(tree2); + if (n1 < 0 || n2 < 0) + return isl_bool_error; + if (n1 != n2) return isl_bool_false; - for (i = 0; i < n; ++i) { + for (i = 0; i < n1; ++i) { isl_schedule_tree *child1, *child2; child1 = isl_schedule_tree_get_child(tree1, i); @@ -713,12 +716,16 @@ } /* Return the number of children of "tree", excluding implicit leaves. + * The "children" field is NULL if there are + * no children (except for the implicit leaves). */ -int isl_schedule_tree_n_children(__isl_keep isl_schedule_tree *tree) +isl_size isl_schedule_tree_n_children(__isl_keep isl_schedule_tree *tree) { if (!tree) - return -1; + return isl_size_error; + if (!tree->children) + return 0; return isl_schedule_tree_list_n_schedule_tree(tree->children); } @@ -766,17 +773,17 @@ __isl_give isl_schedule_tree *isl_schedule_tree_drop_child( __isl_take isl_schedule_tree *tree, int pos) { - int n; + isl_size n; tree = isl_schedule_tree_cow(tree); - if (!tree) - return NULL; - if (!isl_schedule_tree_has_children(tree)) + n = isl_schedule_tree_n_children(tree); + if (n < 0) + return isl_schedule_tree_free(tree); + if (n == 0) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, "tree does not have any explicit children", return isl_schedule_tree_free(tree)); - n = isl_schedule_tree_list_n_schedule_tree(tree->children); if (pos < 0 || pos >= n) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, "position out of bounds", @@ -808,10 +815,15 @@ goto error; if (isl_schedule_tree_is_leaf(child)) { + isl_size n; + isl_schedule_tree_free(child); if (!tree->children && pos == 0) return tree; - if (isl_schedule_tree_n_children(tree) != 1) + n = isl_schedule_tree_n_children(tree); + if (n < 0) + return isl_schedule_tree_free(tree); + if (n != 1) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, "can only replace single child by leaf", @@ -946,12 +958,13 @@ __isl_give isl_schedule_tree *isl_schedule_tree_children_insert_filter( __isl_take isl_schedule_tree *tree, __isl_take isl_union_set *filter) { - int i, n; + int i; + isl_size n; - if (!tree || !filter) + n = isl_schedule_tree_n_children(tree); + if (n < 0 || !filter) goto error; - n = isl_schedule_tree_n_children(tree); for (i = 0; i < n; ++i) { isl_schedule_tree *child; @@ -995,14 +1008,14 @@ /* Return the number of members in the band tree root. */ -unsigned isl_schedule_tree_band_n_member(__isl_keep isl_schedule_tree *tree) +isl_size isl_schedule_tree_band_n_member(__isl_keep isl_schedule_tree *tree) { if (!tree) - return 0; + return isl_size_error; if (tree->type != isl_schedule_node_band) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, - "not a band node", return 0); + "not a band node", return isl_size_error); return isl_schedule_band_n_member(tree->band); } @@ -1527,7 +1540,7 @@ */ static isl_stat set_range_dim(__isl_take isl_map *map, void *user) { - int *dim = user; + isl_size *dim = user; *dim = isl_map_dim(map, isl_dim_out); isl_map_free(map); @@ -1541,15 +1554,17 @@ * * We extract the range dimension from the first map in "umap". */ -static int range_dim(__isl_keep isl_union_map *umap) +static isl_size range_dim(__isl_keep isl_union_map *umap) { - int dim = -1; + isl_size dim = isl_size_error; + isl_size n; - if (!umap) - return -1; - if (isl_union_map_n_map(umap) == 0) + n = isl_union_map_n_map(umap); + if (n < 0) + return isl_size_error; + if (n == 0) isl_die(isl_union_map_get_ctx(umap), isl_error_internal, - "unexpected empty input", return -1); + "unexpected empty input", return isl_size_error); isl_union_map_foreach_map(umap, &set_range_dim, &dim); @@ -1594,18 +1609,20 @@ * from an extension node, but extension nodes are not supported * by the caller and it will error out on them. */ -static int domain_less(__isl_keep isl_schedule_tree *tree) +static isl_bool domain_less(__isl_keep isl_schedule_tree *tree) { enum isl_schedule_node_type type; + isl_size n; type = isl_schedule_tree_get_type(tree); switch (type) { case isl_schedule_node_band: - return isl_schedule_tree_band_n_member(tree) == 0; + n = isl_schedule_tree_band_n_member(tree); + return n < 0 ? isl_bool_error : isl_bool_ok(n == 0); case isl_schedule_node_context: case isl_schedule_node_guard: case isl_schedule_node_mark: - return 1; + return isl_bool_true; case isl_schedule_node_leaf: case isl_schedule_node_error: case isl_schedule_node_domain: @@ -1614,11 +1631,11 @@ case isl_schedule_node_filter: case isl_schedule_node_set: case isl_schedule_node_sequence: - return 0; + return isl_bool_false; } isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "unhandled case", return 0); + "unhandled case", return isl_bool_error); } /* Move down to the first descendant of "tree" that contains any schedule @@ -1627,7 +1644,9 @@ __isl_give isl_schedule_tree *isl_schedule_tree_first_schedule_descendant( __isl_take isl_schedule_tree *tree, __isl_keep isl_schedule_tree *leaf) { - while (domain_less(tree)) { + isl_bool down; + + while ((down = domain_less(tree)) == isl_bool_true) { if (!isl_schedule_tree_has_children(tree)) { isl_schedule_tree_free(tree); return isl_schedule_tree_copy(leaf); @@ -1635,6 +1654,9 @@ tree = isl_schedule_tree_child(tree, 0); } + if (down < 0) + return isl_schedule_tree_free(tree); + return tree; } @@ -1709,27 +1731,24 @@ static __isl_give isl_union_map *subtree_schedule_extend_from_children( __isl_keep isl_schedule_tree *tree, __isl_take isl_union_map *outer) { - int i, n; - int dim; + int i; + isl_size n; + isl_size dim; int separate; isl_ctx *ctx; isl_val *v = NULL; isl_multi_val *mv; isl_space *space; isl_union_map *umap; - - if (!tree) - return NULL; - ctx = isl_schedule_tree_get_ctx(tree); - if (!tree->children) - isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "missing children", return NULL); - n = isl_schedule_tree_list_n_schedule_tree(tree->children); + n = isl_schedule_tree_n_children(tree); + if (n < 0) + return isl_union_map_free(outer); if (n == 0) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "missing children", return NULL); + "missing children", return isl_union_map_free(outer)); + ctx = isl_schedule_tree_get_ctx(tree); separate = n > 1 && (tree->type == isl_schedule_node_sequence || isl_options_get_schedule_separate_components(ctx)); @@ -1744,14 +1763,16 @@ mv = isl_multi_val_zero(space); dim = isl_multi_val_dim(mv, isl_dim_set); + if (dim < 0) + umap = isl_union_map_free(umap); for (i = 0; i < n; ++i) { isl_multi_val *mv_copy; isl_union_pw_multi_aff *upma; isl_union_map *umap_i; isl_union_set *dom; isl_schedule_tree *child; - int dim_i; - int empty; + isl_size dim_i; + isl_bool empty; child = isl_schedule_tree_list_get_schedule_tree( tree->children, i); @@ -1814,6 +1835,7 @@ isl_multi_union_pw_aff *mupa; isl_union_map *umap; isl_union_set *domain; + isl_size n; if (!tree) return NULL; @@ -1831,7 +1853,10 @@ case isl_schedule_node_mark: return subtree_schedule_extend_child(tree, outer); case isl_schedule_node_band: - if (isl_schedule_tree_band_n_member(tree) == 0) + n = isl_schedule_tree_band_n_member(tree); + if (n < 0) + return isl_union_map_free(outer); + if (n == 0) return subtree_schedule_extend_child(tree, outer); mupa = isl_schedule_band_get_partial_schedule(tree->band); umap = isl_union_map_from_multi_union_pw_aff(mupa); @@ -1877,14 +1902,14 @@ static __isl_give isl_union_set *initial_domain_from_children( __isl_keep isl_schedule_tree *tree) { - int i, n; + int i; + isl_size n; isl_space *space; isl_union_set *domain; - if (!tree->children) - isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, - "missing children", return NULL); - n = isl_schedule_tree_list_n_schedule_tree(tree->children); + n = isl_schedule_tree_n_children(tree); + if (n < 0) + return NULL; if (n == 0) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, "missing children", return NULL); @@ -1916,6 +1941,7 @@ isl_multi_union_pw_aff *mupa; isl_union_set *domain; isl_union_map *exp; + isl_size n; if (!tree) return NULL; @@ -1940,7 +1966,10 @@ "cannot construct subtree schedule of tree " "with extension nodes", return NULL); case isl_schedule_node_band: - if (isl_schedule_tree_band_n_member(tree) == 0) + n = isl_schedule_tree_band_n_member(tree); + if (n < 0) + return NULL; + if (n == 0) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_internal, "0D band should be handled by caller", @@ -2112,7 +2141,7 @@ __isl_take isl_schedule_tree *tree, int pos, __isl_take isl_schedule_tree *child) { - int n; + isl_size n; isl_schedule_tree_list *list1, *list2; tree = isl_schedule_tree_cow(tree); @@ -2122,6 +2151,8 @@ isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, "not a sequence node", goto error); n = isl_schedule_tree_n_children(tree); + if (n < 0) + goto error; if (pos < 0 || pos >= n) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, "position out of bounds", goto error); @@ -2275,7 +2306,7 @@ __isl_give isl_schedule_tree *isl_schedule_tree_band_split( __isl_take isl_schedule_tree *tree, int pos, int depth) { - int n; + isl_size n; isl_set *isolate, *tree_isolate, *child_isolate; isl_schedule_tree *child; @@ -2286,6 +2317,8 @@ "not a band node", return isl_schedule_tree_free(tree)); n = isl_schedule_tree_band_n_member(tree); + if (n < 0) + return isl_schedule_tree_free(tree); if (pos < 0 || pos > n) isl_die(isl_schedule_tree_get_ctx(tree), isl_error_invalid, "position out of bounds", @@ -2329,11 +2362,12 @@ __isl_take isl_schedule_tree *tree1, __isl_take isl_schedule_tree *tree2) { - int i, n; + int i; + isl_size n; - if (!tree1 || !tree2) - goto error; n = isl_schedule_tree_n_children(tree1); + if (n < 0 || !tree2) + goto error; if (n == 0) { isl_schedule_tree_list *list; list = isl_schedule_tree_list_from_schedule_tree(tree2); @@ -2617,16 +2651,23 @@ /* Are any members in "band" marked coincident? */ -static int any_coincident(__isl_keep isl_schedule_band *band) +static isl_bool any_coincident(__isl_keep isl_schedule_band *band) { - int i, n; + int i; + isl_size n; n = isl_schedule_band_n_member(band); - for (i = 0; i < n; ++i) - if (isl_schedule_band_member_get_coincident(band, i)) - return 1; + if (n < 0) + return isl_bool_error; + for (i = 0; i < n; ++i) { + isl_bool coincident; + + coincident = isl_schedule_band_member_get_coincident(band, i); + if (coincident < 0 || coincident) + return coincident; + } - return 0; + return isl_bool_false; } /* Print the band node "band" to "p". @@ -2639,7 +2680,8 @@ __isl_keep isl_schedule_band *band) { isl_union_set *options; - int empty; + isl_bool empty; + isl_bool coincident; p = isl_printer_print_str(p, "schedule"); p = isl_printer_yaml_next(p); @@ -2652,8 +2694,12 @@ p = isl_printer_yaml_next(p); p = isl_printer_print_int(p, 1); } - if (any_coincident(band)) { - int i, n; + coincident = any_coincident(band); + if (coincident < 0) + return isl_printer_free(p); + if (coincident) { + int i; + isl_size n; int style; p = isl_printer_yaml_next(p); @@ -2663,6 +2709,8 @@ p = isl_printer_set_yaml_style(p, ISL_YAML_STYLE_FLOW); p = isl_printer_yaml_start_sequence(p); n = isl_schedule_band_n_member(band); + if (n < 0) + return isl_printer_free(p); for (i = 0; i < n; ++i) { p = isl_printer_print_int(p, isl_schedule_band_member_get_coincident(band, i)); @@ -2687,7 +2735,28 @@ return p; } + +#undef BASE +#define BASE str +#define isl_str const char +#include "print_yaml_field_templ.c" + +#undef BASE +#define BASE set +#include "print_yaml_field_templ.c" + +#undef BASE +#define BASE union_set +#include "print_yaml_field_templ.c" + +#undef BASE +#define BASE union_map +#include "print_yaml_field_templ.c" +#undef BASE +#define BASE union_pw_multi_aff +#include "print_yaml_field_templ.c" + /* Print "tree" to "p". * * If "n_ancestor" is non-negative, then "child_pos" contains the child @@ -2703,7 +2772,8 @@ __isl_take isl_printer *p, __isl_keep isl_schedule_tree *tree, int n_ancestor, int *child_pos) { - int i, n; + int i; + isl_size n; int sequence = 0; int block; @@ -2718,80 +2788,56 @@ switch (tree->type) { case isl_schedule_node_error: p = isl_printer_print_str(p, "ERROR"); + p = isl_printer_yaml_next(p); break; case isl_schedule_node_leaf: p = isl_printer_print_str(p, "leaf"); + p = isl_printer_yaml_next(p); break; case isl_schedule_node_sequence: p = isl_printer_print_str(p, "sequence"); + p = isl_printer_yaml_next(p); sequence = 1; break; case isl_schedule_node_set: p = isl_printer_print_str(p, "set"); + p = isl_printer_yaml_next(p); sequence = 1; break; case isl_schedule_node_context: - p = isl_printer_print_str(p, "context"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_set(p, tree->context); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_set(p, "context", tree->context); break; case isl_schedule_node_domain: - p = isl_printer_print_str(p, "domain"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_set(p, tree->domain); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_union_set(p, "domain", tree->domain); break; case isl_schedule_node_expansion: - p = isl_printer_print_str(p, "contraction"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_pw_multi_aff(p, tree->contraction); - p = isl_printer_print_str(p, "\""); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "expansion"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_map(p, tree->expansion); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_union_pw_multi_aff(p, "contraction", + tree->contraction); + p = print_yaml_field_union_map(p, "expansion", tree->expansion); break; case isl_schedule_node_extension: - p = isl_printer_print_str(p, "extension"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_map(p, tree->extension); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_union_map(p, "extension", tree->extension); break; case isl_schedule_node_filter: - p = isl_printer_print_str(p, "filter"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_union_set(p, tree->filter); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_union_set(p, "filter", tree->filter); break; case isl_schedule_node_guard: - p = isl_printer_print_str(p, "guard"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_set(p, tree->guard); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_set(p, "guard", tree->guard); break; case isl_schedule_node_mark: - p = isl_printer_print_str(p, "mark"); - p = isl_printer_yaml_next(p); - p = isl_printer_print_str(p, "\""); - p = isl_printer_print_str(p, isl_id_get_name(tree->mark)); - p = isl_printer_print_str(p, "\""); + p = print_yaml_field_str(p, "mark", + isl_id_get_name(tree->mark)); break; case isl_schedule_node_band: p = print_tree_band(p, tree->band); + p = isl_printer_yaml_next(p); break; } - p = isl_printer_yaml_next(p); - if (!tree->children) { + n = isl_schedule_tree_n_children(tree); + if (n < 0) + return isl_printer_free(p); + if (n == 0) { if (n_ancestor > 0 && block) { isl_schedule_tree *leaf; @@ -2813,7 +2859,6 @@ p = isl_printer_yaml_next(p); } - n = isl_schedule_tree_list_n_schedule_tree(tree->children); for (i = 0; i < n; ++i) { isl_schedule_tree *t; diff --git a/gcc/isl/isl_schedule_tree.h b/gcc/isl/isl_schedule_tree.h index 8bc4cf2..a1ecfad 100644 --- a/gcc/isl/isl_schedule_tree.h +++ a/gcc/isl/isl_schedule_tree.h @@ -178,7 +178,7 @@ __isl_give isl_union_map *isl_schedule_tree_get_subtree_schedule_union_map( __isl_keep isl_schedule_tree *tree); -unsigned isl_schedule_tree_band_n_member(__isl_keep isl_schedule_tree *tree); +isl_size isl_schedule_tree_band_n_member(__isl_keep isl_schedule_tree *tree); isl_bool isl_schedule_tree_band_member_get_coincident( __isl_keep isl_schedule_tree *tree, int pos); @@ -190,7 +190,7 @@ __isl_take isl_schedule_tree *tree, int permutable); int isl_schedule_tree_has_children(__isl_keep isl_schedule_tree *tree); -int isl_schedule_tree_n_children(__isl_keep isl_schedule_tree *tree); +isl_size isl_schedule_tree_n_children(__isl_keep isl_schedule_tree *tree); __isl_give isl_schedule_tree *isl_schedule_tree_get_child( __isl_keep isl_schedule_tree *tree, int pos); diff --git a/gcc/isl/isl_scheduler.c b/gcc/isl/isl_scheduler.c index 6c7a951..1e20588 100644 --- a/gcc/isl/isl_scheduler.c +++ a/gcc/isl/isl_scheduler.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -105,7 +106,7 @@ int compressed; isl_set *hull; isl_multi_aff *compress; - isl_multi_aff *decompress; + isl_pw_multi_aff *decompress; isl_mat *sched; isl_map *sched_map; int rank; @@ -125,7 +126,7 @@ isl_vec *max; }; -static int node_has_tuples(const void *entry, const void *val) +static isl_bool node_has_tuples(const void *entry, const void *val) { struct isl_sched_node *node = (struct isl_sched_node *)entry; isl_space *space = (isl_space *) val; @@ -435,8 +436,12 @@ hash = isl_space_get_tuple_hash(space); entry = isl_hash_table_find(ctx, graph->node_table, hash, &node_has_tuples, space, 0); + if (!entry) + return NULL; + if (entry == isl_hash_table_entry_none) + return graph->node + graph->n; - return entry ? entry->data : graph->node + graph->n; + return entry->data; } /* Is "node" a node in "graph"? @@ -447,12 +452,12 @@ return node && node >= &graph->node[0] && node < &graph->node[graph->n]; } -static int edge_has_src_and_dst(const void *entry, const void *val) +static isl_bool edge_has_src_and_dst(const void *entry, const void *val) { const struct isl_sched_edge *edge = entry; const struct isl_sched_edge *temp = val; - return edge->src == temp->src && edge->dst == temp->dst; + return isl_bool_ok(edge->src == temp->src && edge->dst == temp->dst); } /* Add the given edge to graph->edge_table[type]. @@ -534,17 +539,21 @@ /* If graph->edge_table[type] contains an edge from the given source * to the given destination, then return this edge. - * Otherwise, return NULL. + * Return "none" if no such edge can be found. + * Return NULL on error. */ static struct isl_sched_edge *graph_find_edge(struct isl_sched_graph *graph, enum isl_edge_type type, - struct isl_sched_node *src, struct isl_sched_node *dst) + struct isl_sched_node *src, struct isl_sched_node *dst, + struct isl_sched_edge *none) { struct isl_hash_table_entry *entry; entry = graph_find_edge_entry(graph, type, src, dst); if (!entry) return NULL; + if (entry == isl_hash_table_entry_none) + return none; return entry->data; } @@ -556,18 +565,19 @@ enum isl_edge_type type, struct isl_sched_node *src, struct isl_sched_node *dst) { + struct isl_sched_edge dummy; struct isl_sched_edge *edge; isl_bool empty; - edge = graph_find_edge(graph, type, src, dst); + edge = graph_find_edge(graph, type, src, dst, &dummy); if (!edge) - return 0; + return isl_bool_error; + if (edge == &dummy) + return isl_bool_false; empty = isl_map_plain_is_empty(edge->map); - if (empty < 0) - return isl_bool_error; - return !empty; + return isl_bool_not(empty); } /* Look for any edge with the same src, dst and map fields as "model". @@ -585,8 +595,10 @@ for (i = isl_edge_first; i <= isl_edge_last; ++i) { int is_equal; - edge = graph_find_edge(graph, i, model->src, model->dst); + edge = graph_find_edge(graph, i, model->src, model->dst, model); if (!edge) + return NULL; + if (edge == model) continue; is_equal = isl_map_plain_is_equal(model->map, edge->map); if (is_equal < 0) @@ -600,7 +612,7 @@ /* Remove the given edge from all the edge_tables that refer to it. */ -static void graph_remove_edge(struct isl_sched_graph *graph, +static isl_stat graph_remove_edge(struct isl_sched_graph *graph, struct isl_sched_edge *edge) { isl_ctx *ctx = isl_map_get_ctx(edge->map); @@ -611,11 +623,15 @@ entry = graph_find_edge_entry(graph, i, edge->src, edge->dst); if (!entry) + return isl_stat_error; + if (entry == isl_hash_table_entry_none) continue; if (entry->data != edge) continue; isl_hash_table_remove(ctx, graph->edge_table[i], entry); } + + return isl_stat_ok; } /* Check whether the dependence graph has any edge @@ -702,7 +718,7 @@ isl_space_free(node->space); isl_set_free(node->hull); isl_multi_aff_free(node->compress); - isl_multi_aff_free(node->decompress); + isl_pw_multi_aff_free(node->decompress); isl_mat_free(node->sched); isl_map_free(node->sched_map); isl_mat_free(node->indep); @@ -747,7 +763,7 @@ static isl_stat init_n_maxvar(__isl_take isl_set *set, void *user) { struct isl_sched_graph *graph = user; - int nvar = isl_set_dim(set, isl_dim_set); + isl_size nvar = isl_set_dim(set, isl_dim_set); graph->n++; if (nvar > graph->maxvar) @@ -755,6 +771,8 @@ isl_set_free(set); + if (nvar < 0) + return isl_stat_error; return isl_stat_ok; } @@ -790,12 +808,13 @@ */ static isl_bool has_any_defining_equality(__isl_keep isl_basic_set *bset) { - int i, n; + int i; + isl_size n; - if (!bset) + n = isl_basic_set_dim(bset, isl_dim_set); + if (n < 0) return isl_bool_error; - n = isl_basic_set_dim(bset, isl_dim_set); for (i = 0; i < n; ++i) { isl_bool has; @@ -887,6 +906,57 @@ error: isl_vec_free(v); return isl_stat_error; +} + +/* Construct an identifier for node "node", which will represent "set". + * The name of the identifier is either "compressed" or + * "compressed_", with the name of the space of "set". + * The user pointer of the identifier points to "node". + */ +static __isl_give isl_id *construct_compressed_id(__isl_keep isl_set *set, + struct isl_sched_node *node) +{ + isl_bool has_name; + isl_ctx *ctx; + isl_id *id; + isl_printer *p; + const char *name; + char *id_name; + + has_name = isl_set_has_tuple_name(set); + if (has_name < 0) + return NULL; + + ctx = isl_set_get_ctx(set); + if (!has_name) + return isl_id_alloc(ctx, "compressed", node); + + p = isl_printer_to_str(ctx); + name = isl_set_get_tuple_name(set); + p = isl_printer_print_str(p, "compressed_"); + p = isl_printer_print_str(p, name); + id_name = isl_printer_get_str(p); + isl_printer_free(p); + + id = isl_id_alloc(ctx, id_name, node); + free(id_name); + + return id; +} + +/* Construct a map that isolates the variable in position "pos" in "set". + * + * That is, construct + * + * [i_0, ..., i_pos-1, i_pos+1, ...] -> [i_pos] + */ +static __isl_give isl_map *isolate(__isl_take isl_set *set, int pos) +{ + isl_map *map; + + map = isl_set_project_onto_map(set, isl_dim_set, pos, 1); + map = isl_map_project_out(map, isl_dim_in, pos, 1); + return map; } /* Compute and return the size of "set" in dimension "dim". @@ -912,8 +982,7 @@ isl_aff *obj; isl_val *v; - map = isl_set_project_onto_map(set, isl_dim_set, dim, 1); - map = isl_map_project_out(map, isl_dim_in, dim, 1); + map = isolate(set, dim); map = isl_map_range_product(map, isl_map_copy(map)); map = isl_set_unwrap(isl_map_range(map)); set = isl_map_deltas(map); @@ -926,50 +995,183 @@ return v; } -/* Compute the size of the instance set "set" of "node", after compression, - * as well as bounds on the corresponding coefficients, if needed. +/* Perform a compression on "node" where "hull" represents the constraints + * that were used to derive the compression, while "compress" and + * "decompress" map the original space to the compressed space and + * vice versa. * - * The sizes are needed when the schedule_treat_coalescing option is set. - * The bounds are needed when the schedule_treat_coalescing option or - * the schedule_max_coefficient option is set. + * If "node" was not compressed already, then simply store + * the compression information. + * Otherwise the "original" space is actually the result + * of a previous compression, which is then combined + * with the present compression. * - * If the schedule_treat_coalescing option is not set, then at most - * the bounds need to be set and this is done in set_max_coefficient. - * Otherwise, compress the domain if needed, compute the size - * in each direction and store the results in node->size. + * The dimensionality of the compressed domain is also adjusted. + * Other information, such as the sizes and the maximal coefficient values, + * has not been computed yet and therefore does not need to be adjusted. + */ +static isl_stat compress_node(struct isl_sched_node *node, + __isl_take isl_set *hull, __isl_take isl_multi_aff *compress, + __isl_take isl_pw_multi_aff *decompress) +{ + node->nvar = isl_multi_aff_dim(compress, isl_dim_out); + if (!node->compressed) { + node->compressed = 1; + node->hull = hull; + node->compress = compress; + node->decompress = decompress; + } else { + hull = isl_set_preimage_multi_aff(hull, + isl_multi_aff_copy(node->compress)); + node->hull = isl_set_intersect(node->hull, hull); + node->compress = isl_multi_aff_pullback_multi_aff( + compress, node->compress); + node->decompress = isl_pw_multi_aff_pullback_pw_multi_aff( + node->decompress, decompress); + } + + if (!node->hull || !node->compress || !node->decompress) + return isl_stat_error; + + return isl_stat_ok; +} + +/* Given that dimension "pos" in "set" has a fixed value + * in terms of the other dimensions, (further) compress "node" + * by projecting out this dimension. + * "set" may be the result of a previous compression. + * "uncompressed" is the original domain (without compression). + * + * The compression function simply projects out the dimension. + * The decompression function adds back the dimension + * in the right position as an expression of the other dimensions + * derived from "set". + * As in extract_node, the compressed space has an identifier + * that references "node" such that each compressed space is unique and + * such that the node can be recovered from the compressed space. + * + * The constraint removed through the compression is added to the "hull" + * such that only edges that relate to the original domains + * are taken into account. + * In particular, it is obtained by composing compression and decompression and + * taking the relation among the variables in the range. + */ +static isl_stat project_out_fixed(struct isl_sched_node *node, + __isl_keep isl_set *uncompressed, __isl_take isl_set *set, int pos) +{ + isl_id *id; + isl_space *space; + isl_set *domain; + isl_map *map; + isl_multi_aff *compress; + isl_pw_multi_aff *decompress, *pma; + isl_multi_pw_aff *mpa; + isl_set *hull; + + map = isolate(isl_set_copy(set), pos); + pma = isl_pw_multi_aff_from_map(map); + domain = isl_pw_multi_aff_domain(isl_pw_multi_aff_copy(pma)); + pma = isl_pw_multi_aff_gist(pma, domain); + space = isl_pw_multi_aff_get_domain_space(pma); + mpa = isl_multi_pw_aff_identity(isl_space_map_from_set(space)); + mpa = isl_multi_pw_aff_range_splice(mpa, pos, + isl_multi_pw_aff_from_pw_multi_aff(pma)); + decompress = isl_pw_multi_aff_from_multi_pw_aff(mpa); + space = isl_set_get_space(set); + compress = isl_multi_aff_project_out_map(space, isl_dim_set, pos, 1); + id = construct_compressed_id(uncompressed, node); + compress = isl_multi_aff_set_tuple_id(compress, isl_dim_out, id); + space = isl_space_reverse(isl_multi_aff_get_space(compress)); + decompress = isl_pw_multi_aff_reset_space(decompress, space); + pma = isl_pw_multi_aff_pullback_multi_aff( + isl_pw_multi_aff_copy(decompress), isl_multi_aff_copy(compress)); + hull = isl_map_range(isl_map_from_pw_multi_aff(pma)); + + isl_set_free(set); + + return compress_node(node, hull, compress, decompress); +} + +/* Compute the size of the compressed domain in each dimension and + * store the results in node->sizes. + * "uncompressed" is the original domain (without compression). + * + * First compress the domain if needed and then compute the size + * in each direction. * If the domain is not convex, then the sizes are computed * on a convex superset in order to avoid picking up sizes * that are valid for the individual disjuncts, but not for * the domain as a whole. - * Finally, set the bounds on the coefficients based on the sizes - * and the schedule_max_coefficient option in compute_max_coefficient. + * + * If any of the sizes turns out to be zero, then this means + * that this dimension has a fixed value in terms of + * the other dimensions. Perform an (extra) compression + * to remove this dimensions. */ -static isl_stat compute_sizes_and_max(isl_ctx *ctx, struct isl_sched_node *node, - __isl_take isl_set *set) +static isl_stat compute_sizes(struct isl_sched_node *node, + __isl_keep isl_set *uncompressed) { - int j, n; + int j; + isl_size n; isl_multi_val *mv; - - if (!isl_options_get_schedule_treat_coalescing(ctx)) { - isl_set_free(set); - return set_max_coefficient(ctx, node); - } + isl_set *set = isl_set_copy(uncompressed); if (node->compressed) - set = isl_set_preimage_multi_aff(set, - isl_multi_aff_copy(node->decompress)); + set = isl_set_preimage_pw_multi_aff(set, + isl_pw_multi_aff_copy(node->decompress)); set = isl_set_from_basic_set(isl_set_simple_hull(set)); mv = isl_multi_val_zero(isl_set_get_space(set)); n = isl_set_dim(set, isl_dim_set); + if (n < 0) + mv = isl_multi_val_free(mv); for (j = 0; j < n; ++j) { + isl_bool is_zero; isl_val *v; v = compute_size(isl_set_copy(set), j); + is_zero = isl_val_is_zero(v); mv = isl_multi_val_set_val(mv, j, v); + if (is_zero >= 0 && is_zero) { + isl_multi_val_free(mv); + if (project_out_fixed(node, uncompressed, set, j) < 0) + return isl_stat_error; + return compute_sizes(node, uncompressed); + } } node->sizes = mv; isl_set_free(set); if (!node->sizes) + return isl_stat_error; + return isl_stat_ok; +} + +/* Compute the size of the instance set "set" of "node", after compression, + * as well as bounds on the corresponding coefficients, if needed. + * + * The sizes are needed when the schedule_treat_coalescing option is set. + * The bounds are needed when the schedule_treat_coalescing option or + * the schedule_max_coefficient option is set. + * + * If the schedule_treat_coalescing option is not set, then at most + * the bounds need to be set and this is done in set_max_coefficient. + * Otherwise, compute the size of the compressed domain + * in each direction and store the results in node->size. + * Finally, set the bounds on the coefficients based on the sizes + * and the schedule_max_coefficient option in compute_max_coefficient. + */ +static isl_stat compute_sizes_and_max(isl_ctx *ctx, struct isl_sched_node *node, + __isl_take isl_set *set) +{ + isl_stat r; + + if (!isl_options_get_schedule_treat_coalescing(ctx)) { + isl_set_free(set); + return set_max_coefficient(ctx, node); + } + + r = compute_sizes(node, set); + isl_set_free(set); + if (r < 0) return isl_stat_error; return compute_max_coefficient(ctx, node); } @@ -991,20 +1193,20 @@ static isl_stat add_node(struct isl_sched_graph *graph, __isl_take isl_set *set, int nvar, int compressed, __isl_take isl_set *hull, __isl_take isl_multi_aff *compress, - __isl_take isl_multi_aff *decompress) + __isl_take isl_pw_multi_aff *decompress) { - int nparam; + isl_size nparam; isl_ctx *ctx; isl_mat *sched; isl_space *space; int *coincident; struct isl_sched_node *node; - if (!set) - return isl_stat_error; + nparam = isl_set_dim(set, isl_dim_param); + if (nparam < 0) + goto error; ctx = isl_set_get_ctx(set); - nparam = isl_set_dim(set, isl_dim_param); if (!ctx->opt->schedule_parametric) nparam = 0; sched = isl_mat_alloc(ctx, 0, 1 + nparam + nvar); @@ -1031,42 +1233,12 @@ return isl_stat_error; return isl_stat_ok; -} - -/* Construct an identifier for node "node", which will represent "set". - * The name of the identifier is either "compressed" or - * "compressed_", with the name of the space of "set". - * The user pointer of the identifier points to "node". - */ -static __isl_give isl_id *construct_compressed_id(__isl_keep isl_set *set, - struct isl_sched_node *node) -{ - isl_bool has_name; - isl_ctx *ctx; - isl_id *id; - isl_printer *p; - const char *name; - char *id_name; - - has_name = isl_set_has_tuple_name(set); - if (has_name < 0) - return NULL; - - ctx = isl_set_get_ctx(set); - if (!has_name) - return isl_id_alloc(ctx, "compressed", node); - - p = isl_printer_to_str(ctx); - name = isl_set_get_tuple_name(set); - p = isl_printer_print_str(p, "compressed_"); - p = isl_printer_print_str(p, name); - id_name = isl_printer_get_str(p); - isl_printer_free(p); - - id = isl_id_alloc(ctx, id_name, node); - free(id_name); - - return id; +error: + isl_set_free(set); + isl_set_free(hull); + isl_multi_aff_free(compress); + isl_pw_multi_aff_free(decompress); + return isl_stat_error; } /* Add a new node to the graph representing the given set. @@ -1080,13 +1252,14 @@ */ static isl_stat extract_node(__isl_take isl_set *set, void *user) { - int nvar; + isl_size nvar; isl_bool has_equality; isl_id *id; isl_basic_set *hull; isl_set *hull_set; isl_morph *morph; - isl_multi_aff *compress, *decompress; + isl_multi_aff *compress, *decompress_ma; + isl_pw_multi_aff *decompress; struct isl_sched_graph *graph = user; hull = isl_set_affine_hull(isl_set_copy(set)); @@ -1094,7 +1267,7 @@ nvar = isl_set_dim(set, isl_dim_set); has_equality = has_any_defining_equality(hull); - if (has_equality < 0) + if (nvar < 0 || has_equality < 0) goto error; if (!has_equality) { isl_basic_set_free(hull); @@ -1102,13 +1275,15 @@ } id = construct_compressed_id(set, &graph->node[graph->n]); - morph = isl_basic_set_variable_compression_with_id(hull, - isl_dim_set, id); + morph = isl_basic_set_variable_compression_with_id(hull, id); isl_id_free(id); nvar = isl_morph_ran_dim(morph, isl_dim_set); + if (nvar < 0) + set = isl_set_free(set); compress = isl_morph_get_var_multi_aff(morph); morph = isl_morph_inverse(morph); - decompress = isl_morph_get_var_multi_aff(morph); + decompress_ma = isl_morph_get_var_multi_aff(morph); + decompress = isl_pw_multi_aff_from_multi_aff(decompress_ma); isl_morph_free(morph); hull_set = isl_set_from_basic_set(hull); @@ -1392,6 +1567,7 @@ struct isl_extract_edge_data data; enum isl_edge_type i; isl_stat r; + isl_size n; if (!sc) return isl_stat_error; @@ -1399,11 +1575,14 @@ ctx = isl_schedule_constraints_get_ctx(sc); domain = isl_schedule_constraints_get_domain(sc); - graph->n = isl_union_set_n_set(domain); + n = isl_union_set_n_set(domain); + graph->n = n; isl_union_set_free(domain); + if (n < 0) + return isl_stat_error; - if (graph_alloc(ctx, graph, graph->n, - isl_schedule_constraints_n_map(sc)) < 0) + n = isl_schedule_constraints_n_map(sc); + if (n < 0 || graph_alloc(ctx, graph, graph->n, n) < 0) return isl_stat_error; if (compute_max_row(graph, sc) < 0) @@ -1420,10 +1599,13 @@ if (graph_init_table(ctx, graph) < 0) return isl_stat_error; for (i = isl_edge_first; i <= isl_edge_last; ++i) { + isl_size n; + c = isl_schedule_constraints_get(sc, i); - graph->max_edge[i] = isl_union_map_n_map(c); + n = isl_union_map_n_map(c); + graph->max_edge[i] = n; isl_union_map_free(c); - if (!c) + if (n < 0) return isl_stat_error; } if (graph_init_edge_tables(ctx, graph) < 0) @@ -1550,17 +1732,15 @@ isl_space *space; isl_basic_set *bounds; int i; - unsigned nparam; if (node->bounds) return isl_basic_set_copy(node->bounds); if (node->compressed) - space = isl_multi_aff_get_domain_space(node->decompress); + space = isl_pw_multi_aff_get_domain_space(node->decompress); else space = isl_space_copy(node->space); - nparam = isl_space_dim(space, isl_dim_param); - space = isl_space_drop_dims(space, isl_dim_param, 0, nparam); + space = isl_space_drop_all_params(space); bounds = isl_basic_set_universe(space); for (i = 0; i < node->nvar; ++i) { @@ -1581,6 +1761,22 @@ node->bounds = isl_basic_set_copy(bounds); return bounds; +} + +/* Compress the dependence relation "map", if needed, i.e., + * when the source node "src" and/or the destination node "dst" + * has been compressed. + */ +static __isl_give isl_map *compress(__isl_take isl_map *map, + struct isl_sched_node *src, struct isl_sched_node *dst) +{ + if (src->compressed) + map = isl_map_preimage_domain_pw_multi_aff(map, + isl_pw_multi_aff_copy(src->decompress)); + if (dst->compressed) + map = isl_map_preimage_range_pw_multi_aff(map, + isl_pw_multi_aff_copy(dst->decompress)); + return map; } /* Drop some constraints from "delta" that could be exploited @@ -1592,12 +1788,15 @@ static __isl_give isl_set *drop_coalescing_constraints( __isl_take isl_set *delta, struct isl_sched_node *node) { - unsigned nparam; + isl_size nparam; isl_basic_set *bounds; + + nparam = isl_set_dim(delta, isl_dim_param); + if (nparam < 0) + return isl_set_free(delta); bounds = get_size_bounds(node); - nparam = isl_set_dim(delta, isl_dim_param); delta = isl_set_project_out(delta, isl_dim_param, 0, nparam); delta = isl_set_remove_divs(delta); delta = isl_set_plain_gist_basic_set(delta, bounds); @@ -1661,12 +1860,7 @@ } key = isl_map_copy(map); - if (node->compressed) { - map = isl_map_preimage_domain_multi_aff(map, - isl_multi_aff_copy(node->decompress)); - map = isl_map_preimage_range_multi_aff(map, - isl_multi_aff_copy(node->decompress)); - } + map = compress(map, node, node); delta = isl_map_deltas(map); if (treat) delta = drop_coalescing_constraints(delta, node); @@ -1704,12 +1898,7 @@ } key = isl_map_copy(map); - if (edge->src->compressed) - map = isl_map_preimage_domain_multi_aff(map, - isl_multi_aff_copy(edge->src->decompress)); - if (edge->dst->compressed) - map = isl_map_preimage_range_multi_aff(map, - isl_multi_aff_copy(edge->dst->decompress)); + map = compress(map, edge->src, edge->dst); set = isl_map_wrap(isl_map_remove_divs(map)); coef = isl_set_coefficients(set); graph->inter_hmap = isl_map_to_basic_set_set(graph->inter_hmap, key, @@ -1727,9 +1916,9 @@ * * Return the position of S. */ -static int coef_var_offset(__isl_keep isl_basic_set *coef) +static isl_size coef_var_offset(__isl_keep isl_basic_set *coef) { - int offset; + isl_size offset; isl_space *space; space = isl_space_unwrap(isl_basic_set_get_space(coef)); @@ -1814,13 +2003,13 @@ int offset, int s) { int pos; - unsigned total; + isl_size total; isl_dim_map *dim_map; - if (!node || !graph->lp) + total = isl_basic_set_dim(graph->lp, isl_dim_all); + if (!node || total < 0) return NULL; - total = isl_basic_set_total_dim(graph->lp); pos = node_var_coef_pos(node, 0); dim_map = isl_dim_map_alloc(ctx, total); isl_dim_map_range(dim_map, pos, -2, offset, 1, node->nvar, -s); @@ -1854,13 +2043,13 @@ struct isl_sched_node *dst, int offset, int s) { int pos; - unsigned total; + isl_size total; isl_dim_map *dim_map; - if (!src || !dst || !graph->lp) + total = isl_basic_set_dim(graph->lp, isl_dim_all); + if (!src || !dst || total < 0) return NULL; - total = isl_basic_set_total_dim(graph->lp); dim_map = isl_dim_map_alloc(ctx, total); pos = node_cst_coef_offset(dst); @@ -1918,7 +2107,7 @@ static isl_stat add_intra_validity_constraints(struct isl_sched_graph *graph, struct isl_sched_edge *edge) { - int offset; + isl_size offset; isl_map *map = isl_map_copy(edge->map); isl_ctx *ctx = isl_map_get_ctx(map); isl_dim_map *dim_map; @@ -1928,7 +2117,8 @@ coef = intra_coefficients(graph, node, map, 0); offset = coef_var_offset(coef); - + if (offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; @@ -1954,7 +2144,7 @@ static isl_stat add_inter_validity_constraints(struct isl_sched_graph *graph, struct isl_sched_edge *edge) { - int offset; + isl_size offset; isl_map *map; isl_ctx *ctx; isl_dim_map *dim_map; @@ -1970,7 +2160,8 @@ coef = inter_coefficients(graph, edge, map); offset = coef_var_offset(coef); - + if (offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; @@ -2030,8 +2221,8 @@ static isl_stat add_intra_proximity_constraints(struct isl_sched_graph *graph, struct isl_sched_edge *edge, int s, int local) { - int offset; - unsigned nparam; + isl_size offset; + isl_size nparam; isl_map *map = isl_map_copy(edge->map); isl_ctx *ctx = isl_map_get_ctx(map); isl_dim_map *dim_map; @@ -2039,13 +2230,14 @@ struct isl_sched_node *node = edge->src; coef = intra_coefficients(graph, node, map, !local); + nparam = isl_space_dim(node->space, isl_dim_param); offset = coef_var_offset(coef); - + if (nparam < 0 || offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; - nparam = isl_space_dim(node->space, isl_dim_param); dim_map = intra_dim_map(ctx, graph, node, offset, -s); if (!local) { @@ -2108,8 +2300,8 @@ static isl_stat add_inter_proximity_constraints(struct isl_sched_graph *graph, struct isl_sched_edge *edge, int s, int local) { - int offset; - unsigned nparam; + isl_size offset; + isl_size nparam; isl_map *map = isl_map_copy(edge->map); isl_ctx *ctx = isl_map_get_ctx(map); isl_dim_map *dim_map; @@ -2118,13 +2310,14 @@ struct isl_sched_node *dst = edge->dst; coef = inter_coefficients(graph, edge, map); + nparam = isl_space_dim(src->space, isl_dim_param); offset = coef_var_offset(coef); - + if (nparam < 0 || offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; - nparam = isl_space_dim(src->space, isl_dim_param); dim_map = inter_dim_map(ctx, graph, src, dst, offset, -s); if (!local) { @@ -2245,6 +2438,18 @@ indep = isl_mat_reverse_gauss(indep); indep = isl_mat_lexnonneg_rows(indep); return indep; +} + +/* Extract the linear part of the current schedule for node "node". + */ +static __isl_give isl_mat *extract_linear_schedule(struct isl_sched_node *node) +{ + isl_size n_row = isl_mat_rows(node->sched); + + if (n_row < 0) + return NULL; + return isl_mat_sub_alloc(node->sched, 0, n_row, + 1 + node->nparam, node->nvar); } /* Compute a basis for the rows in the linear part of the schedule @@ -2278,10 +2483,8 @@ static int node_update_vmap(struct isl_sched_node *node) { isl_mat *H, *U, *Q; - int n_row = isl_mat_rows(node->sched); - H = isl_mat_sub_alloc(node->sched, 0, n_row, - 1 + node->nparam, node->nvar); + H = extract_linear_schedule(node); H = isl_mat_left_hermite(H, 0, &U, &Q); isl_mat_free(node->indep); @@ -2472,13 +2675,15 @@ { int i, k; int max; - int total; + isl_size total; max = isl_options_get_schedule_max_constant_term(ctx); if (max == -1) return isl_stat_ok; total = isl_basic_set_dim(graph->lp, isl_dim_set); + if (total < 0) + return isl_stat_error; for (i = 0; i < graph->n; ++i) { struct isl_sched_node *node = &graph->node[i]; @@ -2551,10 +2756,12 @@ struct isl_sched_graph *graph, struct isl_sched_node *node, int max) { int i, j, k; - int total; + isl_size total; isl_vec *ineq; total = isl_basic_set_dim(graph->lp, isl_dim_set); + if (total < 0) + return isl_stat_error; for (j = 0; j < node->nparam; ++j) { int dim; @@ -2642,9 +2849,11 @@ int sum_pos, int first, int n) { int i, k; - int total; + isl_size total; total = isl_basic_set_dim(graph->lp, isl_dim_set); + if (total < 0) + return isl_stat_error; k = isl_basic_set_alloc_equality(graph->lp); if (k < 0) @@ -2664,9 +2873,11 @@ int sum_pos) { int i, j, k; - int total; + isl_size total; total = isl_basic_set_dim(graph->lp, isl_dim_set); + if (total < 0) + return isl_stat_error; k = isl_basic_set_alloc_equality(graph->lp); if (k < 0) @@ -2690,9 +2901,11 @@ int sum_pos) { int i, j, k; - int total; + isl_size total; total = isl_basic_set_dim(graph->lp, isl_dim_set); + if (total < 0) + return isl_stat_error; k = isl_basic_set_alloc_equality(graph->lp); if (k < 0) @@ -2744,7 +2957,7 @@ int use_coincidence) { int i; - unsigned nparam; + isl_size nparam; unsigned total; isl_space *space; int parametric; @@ -2753,6 +2966,8 @@ parametric = ctx->opt->schedule_parametric; nparam = isl_space_dim(graph->node[0].space, isl_dim_param); + if (nparam < 0) + return isl_stat_error; param_pos = 4; total = param_pos + 2 * nparam; for (i = 0; i < graph->n; ++i) { @@ -2855,14 +3070,15 @@ { isl_ctx *ctx; isl_mat *mat; - int i, j, n, n_var; + int i, j; + isl_size n, n_var; - if (!indep) + n = isl_mat_rows(indep); + n_var = isl_mat_cols(indep); + if (n < 0 || n_var < 0) return NULL; ctx = isl_mat_get_ctx(indep); - n = isl_mat_rows(indep); - n_var = isl_mat_cols(indep); mat = isl_mat_alloc(ctx, n, 2 * n_var); if (!mat) return NULL; @@ -2968,11 +3184,11 @@ for (i = 0; i < graph->n; ++i) { struct isl_sched_node *node = &graph->node[i]; int pos; - int row = isl_mat_rows(node->sched); + isl_size row = isl_mat_rows(node->sched); isl_vec_free(csol); csol = extract_var_coef(node, sol); - if (!csol) + if (row < 0 || !csol) goto error; isl_map_free(node->sched_map); @@ -3055,13 +3271,15 @@ isl_local_space *ls; isl_aff *aff; isl_multi_aff *ma; - int nrow; + isl_size nrow; if (!node) return NULL; nrow = isl_mat_rows(node->sched); + if (nrow < 0) + return NULL; if (node->compressed) - space = isl_multi_aff_get_domain_space(node->decompress); + space = isl_pw_multi_aff_get_domain_space(node->decompress); else space = isl_space_copy(node->space); ls = isl_local_space_from_space(isl_space_copy(space)); @@ -3090,9 +3308,11 @@ static __isl_give isl_multi_aff *node_extract_schedule_multi_aff( struct isl_sched_node *node) { - int nrow; + isl_size nrow; nrow = isl_mat_rows(node->sched); + if (nrow < 0) + return NULL; return node_extract_partial_schedule_multi_aff(node, 0, nrow); } @@ -3188,7 +3408,8 @@ if (empty < 0) goto error; if (empty) { - graph_remove_edge(graph, edge); + if (graph_remove_edge(graph, edge) < 0) + goto error; } else if (is_multi_edge_type(edge)) { if (graph_edge_tables_add(ctx, graph, edge) < 0) goto error; @@ -3474,7 +3695,7 @@ dst->node[j].compress = isl_multi_aff_copy(src->node[i].compress); dst->node[j].decompress = - isl_multi_aff_copy(src->node[i].decompress); + isl_pw_multi_aff_copy(src->node[i].decompress); dst->node[j].nvar = src->node[i].nvar; dst->node[j].nparam = src->node[i].nparam; dst->node[j].sched = isl_mat_copy(src->node[i].sched); @@ -3861,15 +4082,17 @@ static isl_stat add_intra_constraints(struct isl_sched_graph *graph, struct isl_sched_node *node, __isl_take isl_basic_set *coef, int pos) { - int offset; + isl_size offset; isl_ctx *ctx; isl_dim_map *dim_map; + offset = coef_var_offset(coef); + if (offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; ctx = isl_basic_set_get_ctx(coef); - offset = coef_var_offset(coef); dim_map = intra_dim_map(ctx, graph, node, offset, 1); isl_dim_map_range(dim_map, 3 + pos, 0, 0, 0, 1, -1); graph->lp = add_constraints_dim_map(graph->lp, coef, dim_map); @@ -3905,15 +4128,17 @@ struct isl_sched_node *src, struct isl_sched_node *dst, __isl_take isl_basic_set *coef, int pos) { - int offset; + isl_size offset; isl_ctx *ctx; isl_dim_map *dim_map; + offset = coef_var_offset(coef); + if (offset < 0) + coef = isl_basic_set_free(coef); if (!coef) return isl_stat_error; ctx = isl_basic_set_get_ctx(coef); - offset = coef_var_offset(coef); dim_map = inter_dim_map(ctx, graph, src, dst, offset, 1); if (pos >= 0) isl_dim_map_range(dim_map, 3 + pos, 0, 0, 0, 1, -1); @@ -4256,6 +4481,7 @@ int row; isl_ctx *ctx; isl_int gcd, gcd_i; + isl_size n_row; if (!node) return NULL; @@ -4265,23 +4491,30 @@ return compute_next_band(node, graph, 0); if (graph->n <= 1) return compute_next_band(node, graph, 0); + n_row = isl_mat_rows(graph->node[0].sched); + if (n_row < 0) + return isl_schedule_node_free(node); isl_int_init(gcd); isl_int_init(gcd_i); isl_int_set_si(gcd, 0); - row = isl_mat_rows(graph->node[0].sched) - 1; + row = n_row - 1; for (i = 0; i < graph->n; ++i) { struct isl_sched_node *node = &graph->node[i]; - int cols = isl_mat_cols(node->sched); + isl_size cols = isl_mat_cols(node->sched); + if (cols < 0) + break; isl_seq_gcd(node->sched->row[row] + 1, cols - 1, &gcd_i); isl_int_gcd(gcd, gcd, gcd_i); } isl_int_clear(gcd_i); + if (i < graph->n) + goto error; if (isl_int_cmp_si(gcd, 1) <= 0) { isl_int_clear(gcd); @@ -4619,12 +4852,7 @@ return umap; map = isl_map_copy(edge->map); - if (node->compressed) { - map = isl_map_preimage_domain_multi_aff(map, - isl_multi_aff_copy(node->decompress)); - map = isl_map_preimage_range_multi_aff(map, - isl_multi_aff_copy(node->decompress)); - } + map = compress(map, node, node); umap = isl_union_map_add_map(umap, map); return umap; } @@ -4643,12 +4871,7 @@ return umap; map = isl_map_copy(edge->map); - if (edge->src->compressed) - map = isl_map_preimage_domain_multi_aff(map, - isl_multi_aff_copy(edge->src->decompress)); - if (edge->dst->compressed) - map = isl_map_preimage_range_multi_aff(map, - isl_multi_aff_copy(edge->dst->decompress)); + map = compress(map, edge->src, edge->dst); umap = isl_union_map_add_map(umap, map); return umap; } @@ -4736,13 +4959,10 @@ isl_multi_aff *ma; isl_multi_pw_aff *mpa; isl_map *map; - int n; + isl_size n; - if (!lineality) - return isl_stat_error; - if (isl_basic_set_dim(lineality, isl_dim_div) != 0) - isl_die(isl_basic_set_get_ctx(lineality), isl_error_internal, - "local variables not allowed", goto error); + if (isl_basic_set_check_no_locals(lineality) < 0) + goto error; space = isl_basic_set_get_space(lineality); if (!data->any_non_trivial) { @@ -4756,6 +4976,8 @@ eq = isl_basic_set_extract_equalities(lineality); n = isl_mat_rows(eq); + if (n < 0) + space = isl_space_free(space); eq = isl_mat_insert_zero_rows(eq, 0, 1); eq = isl_mat_set_element_si(eq, 0, 0, 1); space = isl_space_from_domain(space); @@ -4784,18 +5006,22 @@ { struct isl_exploit_lineality_data *data = user; isl_basic_set *hull; - int dim, n_eq; + isl_size dim; + int n_eq; set = isl_set_remove_divs(set); hull = isl_set_unshifted_simple_hull(set); dim = isl_basic_set_dim(hull, isl_dim_set); n_eq = isl_basic_set_n_equality(hull); - if (!hull) - return isl_stat_error; + if (dim < 0) + goto error; if (dim != n_eq) return add_non_trivial_lineality(hull, data); isl_basic_set_free(hull); return isl_stat_ok; +error: + isl_basic_set_free(hull); + return isl_stat_error; } /* Check if the difference set on intra-node schedule constraints "intra" @@ -4911,17 +5137,6 @@ } return umap; -} - -/* Project out all parameters from "uset" and return the result. - */ -static __isl_give isl_union_set *union_set_drop_parameters( - __isl_take isl_union_set *uset) -{ - unsigned nparam; - - nparam = isl_union_set_dim(uset, isl_dim_param); - return isl_union_set_project_out(uset, isl_dim_param, 0, nparam); } /* For each dependence relation on a (conditional) validity edge @@ -4970,7 +5185,7 @@ intra = collect_validity(graph, &add_intra, coincidence); delta = isl_union_map_deltas(intra); - delta = union_set_drop_parameters(delta); + delta = isl_union_set_project_out_all_params(delta); delta = isl_union_set_remove_divs(delta); if (isl_options_get_schedule_treat_coalescing(ctx)) delta = union_drop_coalescing_constraints(ctx, graph, delta); @@ -5084,7 +5299,7 @@ static __isl_give isl_vec *compute_carrying_sol(isl_ctx *ctx, struct isl_sched_graph *graph, int fallback, int coincidence) { - int n_intra, n_inter; + isl_size n_intra, n_inter; int n_edge; struct isl_carry carry = { 0 }; isl_vec *sol; @@ -5093,10 +5308,10 @@ &carry.lineality); carry.inter = collect_inter_validity(graph, coincidence, &carry.lineality); - if (!carry.intra || !carry.inter) - goto error; n_intra = isl_basic_set_list_n_basic_set(carry.intra); n_inter = isl_basic_set_list_n_basic_set(carry.inter); + if (n_intra < 0 || n_inter < 0) + goto error; if (fallback && n_intra > 0 && isl_options_get_schedule_carry_self_first(ctx)) { @@ -5388,10 +5603,12 @@ static __isl_give isl_map *final_row(struct isl_sched_node *node) { isl_multi_aff *ma; - int row; + isl_size n_row; - row = isl_mat_rows(node->sched) - 1; - ma = node_extract_partial_schedule_multi_aff(node, row, 1); + n_row = isl_mat_rows(node->sched); + if (n_row < 0) + return NULL; + ma = node_extract_partial_schedule_multi_aff(node, n_row - 1, 1); return isl_map_from_multi_aff(ma); } @@ -6405,7 +6622,7 @@ n_coincident = get_n_coincident(merge_graph); - return n_coincident >= max_coincident; + return isl_bool_ok(n_coincident >= max_coincident); } /* Return the transformation on "node" expressed by the current (and only) @@ -6489,13 +6706,13 @@ */ static isl_bool has_single_value(__isl_keep isl_set *set, int pos) { - int n; + isl_size n; isl_bool single; - if (!set) + n = isl_set_dim(set, isl_dim_set); + if (n < 0) return isl_bool_error; set = isl_set_copy(set); - n = isl_set_dim(set, isl_dim_set); set = isl_set_project_out(set, isl_dim_set, pos + 1, n - (pos + 1)); set = isl_set_project_out(set, isl_dim_set, 0, pos); single = isl_set_is_singleton(set); @@ -6556,7 +6773,8 @@ struct isl_sched_graph *graph, struct isl_clustering *c, struct isl_sched_graph *merge_graph) { - int i, n, n_slack; + int i, n_slack; + isl_size n; isl_bool bounded; isl_map *map, *t; isl_set *dist; @@ -6570,6 +6788,8 @@ bounded = isl_bool_true; n = isl_set_dim(dist, isl_dim_set); + if (n < 0) + goto error; n_slack = n - edge->weight; if (edge->weight < 0) n_slack -= graph->max_weight + 1; @@ -6700,12 +6920,15 @@ { int i, j; isl_mat *t; - int n_row, n_col, n_param, n_var; + isl_size n_row, n_col; + int n_param, n_var; n_param = node->nparam; n_var = node->nvar; n_row = isl_mat_rows(t_node->sched); n_col = isl_mat_cols(node->sched); + if (n_row < 0 || n_col < 0) + return NULL; t = isl_mat_alloc(ctx, n_row, n_col); if (!t) return NULL; @@ -6735,13 +6958,15 @@ struct isl_sched_node *t_node) { int i, j; - int n_new; + isl_size n_new; int start, n; start = graph->band_start; n = graph->n_total_row - start; n_new = isl_mat_rows(t_node->sched); + if (n_new < 0) + return isl_stat_error; for (i = 0; i < graph->n; ++i) { struct isl_sched_node *node = &graph->node[i]; isl_mat *t; @@ -7093,7 +7318,7 @@ struct isl_sched_node *dst = edge->dst; isl_basic_map *hull; isl_bool prox; - int n_in, n_out; + isl_size n_in, n_out; prox = is_non_empty_proximity(edge); if (prox < 0) @@ -7119,6 +7344,8 @@ hull = isl_basic_map_remove_divs(hull); n_in = isl_basic_map_dim(hull, isl_dim_in); n_out = isl_basic_map_dim(hull, isl_dim_out); + if (n_in < 0 || n_out < 0) + hull = isl_basic_map_free(hull); hull = isl_basic_map_drop_constraints_not_involving_dims(hull, isl_dim_in, 0, n_in); hull = isl_basic_map_drop_constraints_not_involving_dims(hull, @@ -7378,16 +7605,18 @@ isl_schedule *sched; isl_schedule_node *node; isl_union_set *domain; + isl_size n; sc = isl_schedule_constraints_align_params(sc); domain = isl_schedule_constraints_get_domain(sc); - if (isl_union_set_n_set(domain) == 0) { + n = isl_union_set_n_set(domain); + if (n == 0) { isl_schedule_constraints_free(sc); return isl_schedule_from_domain(domain); } - if (graph_init(&graph, sc) < 0) + if (n < 0 || graph_init(&graph, sc) < 0) domain = isl_union_set_free(domain); node = isl_schedule_node_from_domain(domain); diff --git a/gcc/isl/isl_set_list.c b/gcc/isl/isl_set_list.c index 3334413..2a6749a 100644 --- a/gcc/isl/isl_set_list.c +++ a/gcc/isl/isl_set_list.c @@ -16,17 +16,17 @@ #include -#undef BASE -#define BASE basic_set +#undef EL_BASE +#define EL_BASE basic_set #include -#undef BASE -#define BASE set +#undef EL_BASE +#define EL_BASE set #include -#undef BASE -#define BASE union_set +#undef EL_BASE +#define EL_BASE union_set #include diff --git a/gcc/isl/isl_space.c b/gcc/isl/isl_space.c index 53beee6..14fb01a 100644 --- a/gcc/isl/isl_space.c +++ a/gcc/isl/isl_space.c @@ -1,7 +1,8 @@ /* * Copyright 2008-2009 Katholieke Universiteit Leuven * Copyright 2010 INRIA Saclay * Copyright 2013-2014 Ecole Normale Superieure + * Copyright 2018 Cerebras Systems * * Use of this software is governed by the MIT license * @@ -10,6 +11,7 @@ * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite, * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France * and Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France + * and Cerebras Systems, 175 S San Antonio Rd, Los Altos, CA, USA */ #include @@ -18,37 +20,37 @@ #include #include -isl_ctx *isl_space_get_ctx(__isl_keep isl_space *dim) +isl_ctx *isl_space_get_ctx(__isl_keep isl_space *space) { - return dim ? dim->ctx : NULL; + return space ? space->ctx : NULL; } __isl_give isl_space *isl_space_alloc(isl_ctx *ctx, unsigned nparam, unsigned n_in, unsigned n_out) { - isl_space *dim; + isl_space *space; - dim = isl_alloc_type(ctx, struct isl_space); - if (!dim) + space = isl_alloc_type(ctx, struct isl_space); + if (!space) return NULL; - dim->ctx = ctx; + space->ctx = ctx; isl_ctx_ref(ctx); - dim->ref = 1; - dim->nparam = nparam; - dim->n_in = n_in; - dim->n_out = n_out; + space->ref = 1; + space->nparam = nparam; + space->n_in = n_in; + space->n_out = n_out; - dim->tuple_id[0] = NULL; - dim->tuple_id[1] = NULL; + space->tuple_id[0] = NULL; + space->tuple_id[1] = NULL; - dim->nested[0] = NULL; - dim->nested[1] = NULL; + space->nested[0] = NULL; + space->nested[1] = NULL; - dim->n_id = 0; - dim->ids = NULL; + space->n_id = 0; + space->ids = NULL; - return dim; + return space; } /* Mark the space as being that of a set, by setting the domain tuple @@ -74,16 +76,65 @@ if (space->tuple_id[0] != &isl_id_none) return isl_bool_false; return isl_bool_true; +} + +/* Check that "space" is a set space. + */ +isl_stat isl_space_check_is_set(__isl_keep isl_space *space) +{ + isl_bool is_set; + + is_set = isl_space_is_set(space); + if (is_set < 0) + return isl_stat_error; + if (!is_set) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "space is not a set", return isl_stat_error); + return isl_stat_ok; } /* Is the given space that of a map? */ isl_bool isl_space_is_map(__isl_keep isl_space *space) { + int r; + if (!space) return isl_bool_error; - return space->tuple_id[0] != &isl_id_none && - space->tuple_id[1] != &isl_id_none; + r = space->tuple_id[0] != &isl_id_none && + space->tuple_id[1] != &isl_id_none; + return isl_bool_ok(r); +} + +/* Check that "space" is the space of a map. + */ +static isl_stat isl_space_check_is_map(__isl_keep isl_space *space) +{ + isl_bool is_space; + + is_space = isl_space_is_map(space); + if (is_space < 0) + return isl_stat_error; + if (!is_space) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "expecting map space", return isl_stat_error); + return isl_stat_ok; +} + +/* Check that "space" is the space of a map + * where the range is a wrapped map space. + */ +isl_stat isl_space_check_range_is_wrapping(__isl_keep isl_space *space) +{ + isl_bool wrapping; + + wrapping = isl_space_range_is_wrapping(space); + if (wrapping < 0) + return isl_stat_error; + if (!wrapping) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "range not a product", return isl_stat_error); + return isl_stat_ok; } __isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx, @@ -131,134 +182,168 @@ space = isl_space_alloc(ctx, nparam, 0, 0); space = mark_as_params(space); return space; +} + +/* Create a space for a parameter domain, without any parameters. + */ +__isl_give isl_space *isl_space_unit(isl_ctx *ctx) +{ + return isl_space_params_alloc(ctx, 0); } -static unsigned global_pos(__isl_keep isl_space *dim, +static isl_size global_pos(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos) { - struct isl_ctx *ctx = dim->ctx; + if (isl_space_check_range(space, type, pos, 1) < 0) + return isl_size_error; switch (type) { case isl_dim_param: - isl_assert(ctx, pos < dim->nparam, - return isl_space_dim(dim, isl_dim_all)); return pos; case isl_dim_in: - isl_assert(ctx, pos < dim->n_in, - return isl_space_dim(dim, isl_dim_all)); - return pos + dim->nparam; + return pos + space->nparam; case isl_dim_out: - isl_assert(ctx, pos < dim->n_out, - return isl_space_dim(dim, isl_dim_all)); - return pos + dim->nparam + dim->n_in; + return pos + space->nparam + space->n_in; default: - isl_assert(ctx, 0, return isl_space_dim(dim, isl_dim_all)); + isl_assert(isl_space_get_ctx(space), 0, return isl_size_error); } - return isl_space_dim(dim, isl_dim_all); + return isl_size_error; } /* Extend length of ids array to the total number of dimensions. */ -static __isl_give isl_space *extend_ids(__isl_take isl_space *dim) +static __isl_give isl_space *extend_ids(__isl_take isl_space *space) { isl_id **ids; int i; + isl_size dim; - if (isl_space_dim(dim, isl_dim_all) <= dim->n_id) - return dim; + dim = isl_space_dim(space, isl_dim_all); + if (dim < 0) + return isl_space_free(space); + if (dim <= space->n_id) + return space; - if (!dim->ids) { - dim->ids = isl_calloc_array(dim->ctx, - isl_id *, isl_space_dim(dim, isl_dim_all)); - if (!dim->ids) + if (!space->ids) { + space->ids = isl_calloc_array(space->ctx, isl_id *, dim); + if (!space->ids) goto error; } else { - ids = isl_realloc_array(dim->ctx, dim->ids, - isl_id *, isl_space_dim(dim, isl_dim_all)); + ids = isl_realloc_array(space->ctx, space->ids, isl_id *, dim); if (!ids) goto error; - dim->ids = ids; - for (i = dim->n_id; i < isl_space_dim(dim, isl_dim_all); ++i) - dim->ids[i] = NULL; + space->ids = ids; + for (i = space->n_id; i < dim; ++i) + space->ids[i] = NULL; } - dim->n_id = isl_space_dim(dim, isl_dim_all); + space->n_id = dim; - return dim; + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } -static __isl_give isl_space *set_id(__isl_take isl_space *dim, +static __isl_give isl_space *set_id(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id) { - dim = isl_space_cow(dim); + isl_size gpos; - if (!dim) - goto error; + space = isl_space_cow(space); - pos = global_pos(dim, type, pos); - if (pos == isl_space_dim(dim, isl_dim_all)) + gpos = global_pos(space, type, pos); + if (gpos < 0) goto error; - if (pos >= dim->n_id) { + if (gpos >= space->n_id) { if (!id) - return dim; - dim = extend_ids(dim); - if (!dim) + return space; + space = extend_ids(space); + if (!space) goto error; } - dim->ids[pos] = id; + space->ids[gpos] = id; - return dim; + return space; error: isl_id_free(id); - isl_space_free(dim); + isl_space_free(space); return NULL; } -static __isl_keep isl_id *get_id(__isl_keep isl_space *dim, +static __isl_keep isl_id *get_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos) { - if (!dim) - return NULL; + isl_size gpos; - pos = global_pos(dim, type, pos); - if (pos == isl_space_dim(dim, isl_dim_all)) + gpos = global_pos(space, type, pos); + if (gpos < 0) + return NULL; + if (gpos >= space->n_id) return NULL; - if (pos >= dim->n_id) + return space->ids[gpos]; +} + +/* Return the nested space at the given position. + */ +static __isl_keep isl_space *isl_space_peek_nested(__isl_keep isl_space *space, + int pos) +{ + if (!space) return NULL; - return dim->ids[pos]; + if (!space->nested[pos]) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "no nested space", return NULL); + return space->nested[pos]; } -static unsigned offset(__isl_keep isl_space *dim, enum isl_dim_type type) +static unsigned offset(__isl_keep isl_space *space, enum isl_dim_type type) { switch (type) { case isl_dim_param: return 0; - case isl_dim_in: return dim->nparam; - case isl_dim_out: return dim->nparam + dim->n_in; + case isl_dim_in: return space->nparam; + case isl_dim_out: return space->nparam + space->n_in; default: return 0; } } -static unsigned n(__isl_keep isl_space *dim, enum isl_dim_type type) +static unsigned n(__isl_keep isl_space *space, enum isl_dim_type type) { switch (type) { - case isl_dim_param: return dim->nparam; - case isl_dim_in: return dim->n_in; - case isl_dim_out: return dim->n_out; - case isl_dim_all: return dim->nparam + dim->n_in + dim->n_out; + case isl_dim_param: return space->nparam; + case isl_dim_in: return space->n_in; + case isl_dim_out: return space->n_out; + case isl_dim_all: + return space->nparam + space->n_in + space->n_out; default: return 0; } } -unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type) +isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type) { - if (!dim) - return 0; - return n(dim, type); + if (!space) + return isl_size_error; + return n(space, type); +} + +/* Return the dimensionality of tuple "inner" within the wrapped relation + * inside tuple "outer". + */ +isl_size isl_space_wrapped_dim(__isl_keep isl_space *space, + enum isl_dim_type outer, enum isl_dim_type inner) +{ + int pos; + + if (!space) + return isl_size_error; + if (outer != isl_dim_in && outer != isl_dim_out) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "only input, output and set tuples " + "can have nested relations", return isl_size_error); + pos = outer - isl_dim_in; + return isl_space_dim(isl_space_peek_nested(space, pos), inner); } unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type) @@ -289,44 +374,47 @@ return dst; } -__isl_take isl_space *isl_space_dup(__isl_keep isl_space *dim) +__isl_take isl_space *isl_space_dup(__isl_keep isl_space *space) { isl_space *dup; - if (!dim) + if (!space) return NULL; - dup = isl_space_alloc(dim->ctx, dim->nparam, dim->n_in, dim->n_out); + dup = isl_space_alloc(space->ctx, + space->nparam, space->n_in, space->n_out); if (!dup) return NULL; - if (dim->tuple_id[0] && - !(dup->tuple_id[0] = isl_id_copy(dim->tuple_id[0]))) + if (space->tuple_id[0] && + !(dup->tuple_id[0] = isl_id_copy(space->tuple_id[0]))) goto error; - if (dim->tuple_id[1] && - !(dup->tuple_id[1] = isl_id_copy(dim->tuple_id[1]))) + if (space->tuple_id[1] && + !(dup->tuple_id[1] = isl_id_copy(space->tuple_id[1]))) goto error; - if (dim->nested[0] && !(dup->nested[0] = isl_space_copy(dim->nested[0]))) + if (space->nested[0] && + !(dup->nested[0] = isl_space_copy(space->nested[0]))) goto error; - if (dim->nested[1] && !(dup->nested[1] = isl_space_copy(dim->nested[1]))) + if (space->nested[1] && + !(dup->nested[1] = isl_space_copy(space->nested[1]))) goto error; - if (!dim->ids) + if (!space->ids) return dup; - dup = copy_ids(dup, isl_dim_param, 0, dim, isl_dim_param); - dup = copy_ids(dup, isl_dim_in, 0, dim, isl_dim_in); - dup = copy_ids(dup, isl_dim_out, 0, dim, isl_dim_out); + dup = copy_ids(dup, isl_dim_param, 0, space, isl_dim_param); + dup = copy_ids(dup, isl_dim_in, 0, space, isl_dim_in); + dup = copy_ids(dup, isl_dim_out, 0, space, isl_dim_out); return dup; error: isl_space_free(dup); return NULL; } -__isl_give isl_space *isl_space_cow(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_cow(__isl_take isl_space *space) { - if (!dim) + if (!space) return NULL; - if (dim->ref == 1) - return dim; - dim->ref--; - return isl_space_dup(dim); + if (space->ref == 1) + return space; + space->ref--; + return isl_space_dup(space); } __isl_give isl_space *isl_space_copy(__isl_keep isl_space *dim) @@ -380,6 +468,67 @@ return 0); return 1; +} + +/* Return a copy of the nested space at the given position. + */ +static __isl_keep isl_space *isl_space_get_nested(__isl_keep isl_space *space, + int pos) +{ + return isl_space_copy(isl_space_peek_nested(space, pos)); +} + +/* Return the nested space at the given position. + * This may be either a copy or the nested space itself + * if there is only one reference to "space". + * This allows the nested space to be modified inplace + * if both "space" and the nested space have only a single reference. + * The caller is not allowed to modify "space" between this call and + * a subsequent call to isl_space_restore_nested. + * The only exception is that isl_space_free can be called instead. + */ +static __isl_give isl_space *isl_space_take_nested(__isl_keep isl_space *space, + int pos) +{ + isl_space *nested; + + if (!space) + return NULL; + if (space->ref != 1) + return isl_space_get_nested(space, pos); + nested = space->nested[pos]; + space->nested[pos] = NULL; + return nested; +} + +/* Replace the nested space at the given position by "nested", + * where this nested space of "space" may be missing + * due to a preceding call to isl_space_take_nested. + * However, in this case, "space" only has a single reference and + * then the call to isl_space_cow has no effect. + */ +static __isl_give isl_space *isl_space_restore_nested( + __isl_take isl_space *space, int pos, __isl_take isl_space *nested) +{ + if (!space || !nested) + goto error; + + if (space->nested[pos] == nested) { + isl_space_free(nested); + return space; + } + + space = isl_space_cow(space); + if (!space) + goto error; + isl_space_free(space->nested[pos]); + space->nested[pos] = nested; + + return space; +error: + isl_space_free(space); + isl_space_free(nested); + return NULL; } /* Is it possible for the given dimension type to have a tuple id? @@ -405,68 +554,68 @@ /* Does the tuple have an id? */ -isl_bool isl_space_has_tuple_id(__isl_keep isl_space *dim, +isl_bool isl_space_has_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type) { - if (!space_can_have_id(dim, type)) + if (!space_can_have_id(space, type)) return isl_bool_error; - return dim->tuple_id[type - isl_dim_in] != NULL; + return isl_bool_ok(space->tuple_id[type - isl_dim_in] != NULL); } -__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim, +__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type) { int has_id; - if (!dim) + if (!space) return NULL; - has_id = isl_space_has_tuple_id(dim, type); + has_id = isl_space_has_tuple_id(space, type); if (has_id < 0) return NULL; if (!has_id) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "tuple has no id", return NULL); - return isl_id_copy(dim->tuple_id[type - isl_dim_in]); + return isl_id_copy(space->tuple_id[type - isl_dim_in]); } -__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *space, enum isl_dim_type type, __isl_take isl_id *id) { - dim = isl_space_cow(dim); - if (!dim || !id) + space = isl_space_cow(space); + if (!space || !id) goto error; if (type != isl_dim_in && type != isl_dim_out) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "only input, output and set tuples can have names", goto error); - isl_id_free(dim->tuple_id[type - isl_dim_in]); - dim->tuple_id[type - isl_dim_in] = id; + isl_id_free(space->tuple_id[type - isl_dim_in]); + space->tuple_id[type - isl_dim_in] = id; - return dim; + return space; error: isl_id_free(id); - isl_space_free(dim); + isl_space_free(space); return NULL; } -__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *space, enum isl_dim_type type) { - dim = isl_space_cow(dim); - if (!dim) + space = isl_space_cow(space); + if (!space) return NULL; if (type != isl_dim_in && type != isl_dim_out) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "only input, output and set tuples can have names", goto error); - isl_id_free(dim->tuple_id[type - isl_dim_in]); - dim->tuple_id[type - isl_dim_in] = NULL; + isl_id_free(space->tuple_id[type - isl_dim_in]); + space->tuple_id[type - isl_dim_in] = NULL; - return dim; + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -537,43 +686,43 @@ return NULL; } -isl_bool isl_space_has_dim_id(__isl_keep isl_space *dim, +isl_bool isl_space_has_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos) { - if (!dim) + if (!space) return isl_bool_error; - return get_id(dim, type, pos) != NULL; + return isl_bool_ok(get_id(space, type, pos) != NULL); } -__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim, +__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos) { - if (!dim) + if (!space) return NULL; - if (!get_id(dim, type, pos)) - isl_die(dim->ctx, isl_error_invalid, + if (!get_id(space, type, pos)) + isl_die(space->ctx, isl_error_invalid, "dim has no id", return NULL); - return isl_id_copy(get_id(dim, type, pos)); + return isl_id_copy(get_id(space, type, pos)); } -__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *space, enum isl_dim_type type, const char *s) { isl_id *id; - if (!dim) + if (!space) return NULL; if (!s) - return isl_space_reset_tuple_id(dim, type); + return isl_space_reset_tuple_id(space, type); - if (!name_ok(dim->ctx, s)) + if (!name_ok(space->ctx, s)) goto error; - id = isl_id_alloc(dim->ctx, s, NULL); - return isl_space_set_tuple_id(dim, type, id); + id = isl_id_alloc(space->ctx, s, NULL); + return isl_space_set_tuple_id(space, type, id); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -587,37 +736,37 @@ if (!space_can_have_id(space, type)) return isl_bool_error; id = space->tuple_id[type - isl_dim_in]; - return id && id->name; + return isl_bool_ok(id && id->name); } -__isl_keep const char *isl_space_get_tuple_name(__isl_keep isl_space *dim, +__isl_keep const char *isl_space_get_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type) { isl_id *id; - if (!dim) + if (!space) return NULL; if (type != isl_dim_in && type != isl_dim_out) return NULL; - id = dim->tuple_id[type - isl_dim_in]; + id = space->tuple_id[type - isl_dim_in]; return id ? id->name : NULL; } -__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, const char *s) { isl_id *id; - if (!dim) + if (!space) return NULL; if (!s) - return isl_space_reset_dim_id(dim, type, pos); - if (!name_ok(dim->ctx, s)) + return isl_space_reset_dim_id(space, type, pos); + if (!name_ok(space->ctx, s)) goto error; - id = isl_id_alloc(dim->ctx, s, NULL); - return isl_space_set_dim_id(dim, type, pos, id); + id = isl_id_alloc(space->ctx, s, NULL); + return isl_space_set_dim_id(space, type, pos, id); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -631,30 +780,30 @@ if (!space) return isl_bool_error; id = get_id(space, type, pos); - return id && id->name; + return isl_bool_ok(id && id->name); } -__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim, +__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos) { - isl_id *id = get_id(dim, type, pos); + isl_id *id = get_id(space, type, pos); return id ? id->name : NULL; } -int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type, - __isl_keep isl_id *id) +int isl_space_find_dim_by_id(__isl_keep isl_space *space, + enum isl_dim_type type, __isl_keep isl_id *id) { int i; int offset; - int n; + isl_size n; - if (!dim || !id) + n = isl_space_dim(space, type); + if (n < 0 || !id) return -1; - offset = isl_space_offset(dim, type); - n = isl_space_dim(dim, type); - for (i = 0; i < n && offset + i < dim->n_id; ++i) - if (dim->ids[offset + i] == id) + offset = isl_space_offset(space, type); + for (i = 0; i < n && offset + i < space->n_id; ++i) + if (space->ids[offset + i] == id) return i; return -1; @@ -665,13 +814,13 @@ { int i; int offset; - int n; + isl_size n; - if (!space || !name) + n = isl_space_dim(space, type); + if (n < 0 || !name) return -1; offset = isl_space_offset(space, type); - n = isl_space_dim(space, type); for (i = 0; i < n && offset + i < space->n_id; ++i) { isl_id *id = get_id(space, type, i); if (id && id->name && !strcmp(id->name, name)) @@ -727,14 +876,15 @@ } for (i = 0; i < 2; ++i) { + isl_space *nested; + if (!space->nested[i]) continue; - space = isl_space_cow(space); + nested = isl_space_take_nested(space, i); + nested = isl_space_reset_user(nested); + space = isl_space_restore_nested(space, i, nested); if (!space) return NULL; - space->nested[i] = isl_space_reset_user(space->nested[i]); - if (!space->nested[i]) - return isl_space_free(space); } return space; @@ -777,6 +927,24 @@ space2, isl_dim_in) && isl_space_tuple_is_equal(space1, isl_dim_out, space2, isl_dim_out); +} + +/* Check that the two spaces are the same, + * apart from positions and names of parameters. + */ +isl_stat isl_space_check_equal_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2) +{ + isl_bool is_equal; + + is_equal = isl_space_has_equal_tuples(space1, space2); + if (is_equal < 0) + return isl_stat_error; + if (!is_equal) + isl_die(isl_space_get_ctx(space1), isl_error_invalid, + "incompatible spaces", return isl_stat_error); + + return isl_stat_ok; } /* Check if the tuple of type "type1" of "space1" is the same as @@ -825,12 +993,17 @@ __isl_keep isl_space *space2, enum isl_dim_type type2) { int i; + isl_bool equal; + + if (!space1 || !space2) + return isl_bool_error; if (space1 == space2 && type1 == type2) return isl_bool_true; - if (!isl_space_tuple_is_equal(space1, type1, space2, type2)) - return isl_bool_false; + equal = isl_space_tuple_is_equal(space1, type1, space2, type2); + if (equal < 0 || !equal) + return equal; if (!space1->ids && !space2->ids) return isl_bool_true; @@ -847,9 +1020,6 @@ isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1, __isl_keep isl_space *space2) { - if (!space1 || !space2) - return isl_bool_error; - return match(space1, isl_dim_param, space2, isl_dim_param); } @@ -860,9 +1030,6 @@ __isl_keep isl_space *space2) { isl_bool equal; - - if (!space1 || !space2) - return isl_bool_error; equal = match(space1, isl_dim_in, space2, isl_dim_in); if (equal < 0 || !equal) @@ -873,9 +1040,6 @@ isl_bool isl_space_match(__isl_keep isl_space *space1, enum isl_dim_type type1, __isl_keep isl_space *space2, enum isl_dim_type type2) { - if (!space1 || !space2) - return isl_bool_error; - return match(space1, type1, space2, type2); } @@ -982,7 +1146,7 @@ __isl_give isl_space *isl_space_add_param_id(__isl_take isl_space *space, __isl_take isl_id *id) { - int pos; + isl_size pos; if (!space || !id) goto error; @@ -993,6 +1157,8 @@ } pos = isl_space_dim(space, isl_dim_param); + if (pos < 0) + goto error; space = isl_space_add_dims(space, isl_dim_param, 1); space = isl_space_set_dim_id(space, isl_dim_param, pos, id); @@ -1015,80 +1181,88 @@ } } +#undef TYPE +#define TYPE isl_space +#include "check_type_range_templ.c" + /* Insert "n" dimensions of type "type" at position "pos". * If we are inserting parameters, then they are also inserted in * any nested spaces. */ -__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, unsigned n) { + isl_ctx *ctx; isl_id **ids = NULL; - if (!dim) + if (!space) return NULL; if (n == 0) - return isl_space_reset(dim, type); + return isl_space_reset(space, type); + ctx = isl_space_get_ctx(space); if (!valid_dim_type(type)) - isl_die(dim->ctx, isl_error_invalid, + isl_die(ctx, isl_error_invalid, "cannot insert dimensions of specified type", goto error); - isl_assert(dim->ctx, pos <= isl_space_dim(dim, type), goto error); + if (isl_space_check_range(space, type, pos, 0) < 0) + return isl_space_free(space); - dim = isl_space_cow(dim); - if (!dim) + space = isl_space_cow(space); + if (!space) return NULL; - if (dim->ids) { + if (space->ids) { enum isl_dim_type t, o = isl_dim_param; int off; int s[3]; - ids = isl_calloc_array(dim->ctx, isl_id *, - dim->nparam + dim->n_in + dim->n_out + n); + ids = isl_calloc_array(ctx, isl_id *, + space->nparam + space->n_in + space->n_out + n); if (!ids) goto error; off = 0; - s[isl_dim_param - o] = dim->nparam; - s[isl_dim_in - o] = dim->n_in; - s[isl_dim_out - o] = dim->n_out; + s[isl_dim_param - o] = space->nparam; + s[isl_dim_in - o] = space->n_in; + s[isl_dim_out - o] = space->n_out; for (t = isl_dim_param; t <= isl_dim_out; ++t) { if (t != type) { - get_ids(dim, t, 0, s[t - o], ids + off); + get_ids(space, t, 0, s[t - o], ids + off); off += s[t - o]; } else { - get_ids(dim, t, 0, pos, ids + off); + get_ids(space, t, 0, pos, ids + off); off += pos + n; - get_ids(dim, t, pos, s[t - o] - pos, ids + off); + get_ids(space, t, pos, s[t - o] - pos, + ids + off); off += s[t - o] - pos; } } - free(dim->ids); - dim->ids = ids; - dim->n_id = dim->nparam + dim->n_in + dim->n_out + n; + free(space->ids); + space->ids = ids; + space->n_id = space->nparam + space->n_in + space->n_out + n; } switch (type) { - case isl_dim_param: dim->nparam += n; break; - case isl_dim_in: dim->n_in += n; break; - case isl_dim_out: dim->n_out += n; break; + case isl_dim_param: space->nparam += n; break; + case isl_dim_in: space->n_in += n; break; + case isl_dim_out: space->n_out += n; break; default: ; } - dim = isl_space_reset(dim, type); + space = isl_space_reset(space, type); if (type == isl_dim_param) { - if (dim && dim->nested[0] && - !(dim->nested[0] = isl_space_insert_dims(dim->nested[0], + if (space && space->nested[0] && + !(space->nested[0] = isl_space_insert_dims(space->nested[0], isl_dim_param, pos, n))) goto error; - if (dim && dim->nested[1] && - !(dim->nested[1] = isl_space_insert_dims(dim->nested[1], + if (space && space->nested[1] && + !(space->nested[1] = isl_space_insert_dims(space->nested[1], isl_dim_param, pos, n))) goto error; } - return dim; + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1105,8 +1279,8 @@ if (n == 0) return space; - isl_assert(space->ctx, src_pos + n <= isl_space_dim(space, src_type), - goto error); + if (isl_space_check_range(space, src_type, src_pos, n) < 0) + return isl_space_free(space); if (dst_type == src_type && dst_pos == src_pos) return space; @@ -1173,12 +1347,15 @@ return space; for (i = 0; i < 2; ++i) { + isl_space *nested; + if (!space->nested[i]) continue; - space->nested[i] = isl_space_replace_params(space->nested[i], - space); - if (!space->nested[i]) - goto error; + nested = isl_space_take_nested(space, i); + nested = isl_space_replace_params(nested, space); + space = isl_space_restore_nested(space, i, nested); + if (!space) + return NULL; } return space; @@ -1207,7 +1384,7 @@ __isl_give isl_space *isl_space_join(__isl_take isl_space *left, __isl_take isl_space *right) { - isl_space *dim; + isl_space *space; if (isl_space_check_equal_params(left, right) < 0) goto error; @@ -1216,31 +1393,32 @@ isl_space_tuple_is_equal(left, isl_dim_out, right, isl_dim_in), goto error); - dim = isl_space_alloc(left->ctx, left->nparam, left->n_in, right->n_out); - if (!dim) + space = isl_space_alloc(left->ctx, + left->nparam, left->n_in, right->n_out); + if (!space) goto error; - dim = copy_ids(dim, isl_dim_param, 0, left, isl_dim_param); - dim = copy_ids(dim, isl_dim_in, 0, left, isl_dim_in); - dim = copy_ids(dim, isl_dim_out, 0, right, isl_dim_out); + space = copy_ids(space, isl_dim_param, 0, left, isl_dim_param); + space = copy_ids(space, isl_dim_in, 0, left, isl_dim_in); + space = copy_ids(space, isl_dim_out, 0, right, isl_dim_out); - if (dim && left->tuple_id[0] && - !(dim->tuple_id[0] = isl_id_copy(left->tuple_id[0]))) + if (space && left->tuple_id[0] && + !(space->tuple_id[0] = isl_id_copy(left->tuple_id[0]))) goto error; - if (dim && right->tuple_id[1] && - !(dim->tuple_id[1] = isl_id_copy(right->tuple_id[1]))) + if (space && right->tuple_id[1] && + !(space->tuple_id[1] = isl_id_copy(right->tuple_id[1]))) goto error; - if (dim && left->nested[0] && - !(dim->nested[0] = isl_space_copy(left->nested[0]))) + if (space && left->nested[0] && + !(space->nested[0] = isl_space_copy(left->nested[0]))) goto error; - if (dim && right->nested[1] && - !(dim->nested[1] = isl_space_copy(right->nested[1]))) + if (space && right->nested[1] && + !(space->nested[1] = isl_space_copy(right->nested[1]))) goto error; isl_space_free(left); isl_space_free(right); - return dim; + return space; error: isl_space_free(left); isl_space_free(right); @@ -1459,11 +1637,8 @@ __isl_give isl_space *isl_space_range_factor_domain( __isl_take isl_space *space) { - if (!space) - return NULL; - if (!isl_space_range_is_wrapping(space)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "range not a product", return isl_space_free(space)); + if (isl_space_check_range_is_wrapping(space) < 0) + return isl_space_free(space); return range_factor_domain(space); } @@ -1537,11 +1712,8 @@ __isl_give isl_space *isl_space_range_factor_range( __isl_take isl_space *space) { - if (!space) - return NULL; - if (!isl_space_range_is_wrapping(space)) - isl_die(isl_space_get_ctx(space), isl_error_invalid, - "range not a product", return isl_space_free(space)); + if (isl_space_check_range_is_wrapping(space) < 0) + return isl_space_free(space); return range_factor_range(space); } @@ -1643,117 +1815,149 @@ return dim; } -__isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_reverse(__isl_take isl_space *space) { unsigned t; + isl_bool equal; isl_space *nested; isl_id **ids = NULL; isl_id *id; - if (!dim) - return NULL; - if (match(dim, isl_dim_in, dim, isl_dim_out)) - return dim; + equal = match(space, isl_dim_in, space, isl_dim_out); + if (equal < 0) + return isl_space_free(space); + if (equal) + return space; - dim = isl_space_cow(dim); - if (!dim) + space = isl_space_cow(space); + if (!space) return NULL; - id = dim->tuple_id[0]; - dim->tuple_id[0] = dim->tuple_id[1]; - dim->tuple_id[1] = id; + id = space->tuple_id[0]; + space->tuple_id[0] = space->tuple_id[1]; + space->tuple_id[1] = id; - nested = dim->nested[0]; - dim->nested[0] = dim->nested[1]; - dim->nested[1] = nested; + nested = space->nested[0]; + space->nested[0] = space->nested[1]; + space->nested[1] = nested; - if (dim->ids) { - int n_id = dim->n_in + dim->n_out; - ids = isl_alloc_array(dim->ctx, isl_id *, n_id); + if (space->ids) { + int n_id = space->n_in + space->n_out; + ids = isl_alloc_array(space->ctx, isl_id *, n_id); if (n_id && !ids) goto error; - get_ids(dim, isl_dim_in, 0, dim->n_in, ids); - get_ids(dim, isl_dim_out, 0, dim->n_out, ids + dim->n_in); + get_ids(space, isl_dim_in, 0, space->n_in, ids); + get_ids(space, isl_dim_out, 0, space->n_out, ids + space->n_in); } - t = dim->n_in; - dim->n_in = dim->n_out; - dim->n_out = t; + t = space->n_in; + space->n_in = space->n_out; + space->n_out = t; - if (dim->ids) { - dim = set_ids(dim, isl_dim_out, 0, dim->n_out, ids); - dim = set_ids(dim, isl_dim_in, 0, dim->n_in, ids + dim->n_out); + if (space->ids) { + space = set_ids(space, isl_dim_out, 0, space->n_out, ids); + space = set_ids(space, isl_dim_in, 0, space->n_in, + ids + space->n_out); free(ids); } - return dim; + return space; error: free(ids); - isl_space_free(dim); + isl_space_free(space); return NULL; +} + +/* Given a space A -> (B -> C), return the corresponding space + * A -> (C -> B). + * + * If the range tuple is named, then the name is only preserved + * if B and C are equal tuples, in which case the output + * of this function is identical to the input. + */ +__isl_give isl_space *isl_space_range_reverse(__isl_take isl_space *space) +{ + isl_space *nested; + isl_bool equal; + + if (isl_space_check_range_is_wrapping(space) < 0) + return isl_space_free(space); + + nested = isl_space_peek_nested(space, 1); + equal = isl_space_tuple_is_equal(nested, isl_dim_in, + nested, isl_dim_out); + if (equal < 0) + return isl_space_free(space); + + nested = isl_space_take_nested(space, 1); + nested = isl_space_reverse(nested); + space = isl_space_restore_nested(space, 1, nested); + if (!equal) + space = isl_space_reset_tuple_id(space, isl_dim_out); + + return space; } -__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned first, unsigned num) { int i; - if (!dim) + if (!space) return NULL; if (num == 0) - return isl_space_reset(dim, type); + return isl_space_reset(space, type); if (!valid_dim_type(type)) - isl_die(dim->ctx, isl_error_invalid, + isl_die(space->ctx, isl_error_invalid, "cannot drop dimensions of specified type", goto error); - if (first + num > n(dim, type) || first + num < first) - isl_die(isl_space_get_ctx(dim), isl_error_invalid, - "index out of bounds", return isl_space_free(dim)); - dim = isl_space_cow(dim); - if (!dim) + if (isl_space_check_range(space, type, first, num) < 0) + return isl_space_free(space); + space = isl_space_cow(space); + if (!space) goto error; - if (dim->ids) { - dim = extend_ids(dim); - if (!dim) + if (space->ids) { + space = extend_ids(space); + if (!space) goto error; for (i = 0; i < num; ++i) - isl_id_free(get_id(dim, type, first + i)); - for (i = first+num; i < n(dim, type); ++i) - set_id(dim, type, i - num, get_id(dim, type, i)); + isl_id_free(get_id(space, type, first + i)); + for (i = first+num; i < n(space, type); ++i) + set_id(space, type, i - num, get_id(space, type, i)); switch (type) { case isl_dim_param: - get_ids(dim, isl_dim_in, 0, dim->n_in, - dim->ids + offset(dim, isl_dim_in) - num); + get_ids(space, isl_dim_in, 0, space->n_in, + space->ids + offset(space, isl_dim_in) - num); case isl_dim_in: - get_ids(dim, isl_dim_out, 0, dim->n_out, - dim->ids + offset(dim, isl_dim_out) - num); + get_ids(space, isl_dim_out, 0, space->n_out, + space->ids + offset(space, isl_dim_out) - num); default: ; } - dim->n_id -= num; + space->n_id -= num; } switch (type) { - case isl_dim_param: dim->nparam -= num; break; - case isl_dim_in: dim->n_in -= num; break; - case isl_dim_out: dim->n_out -= num; break; + case isl_dim_param: space->nparam -= num; break; + case isl_dim_in: space->n_in -= num; break; + case isl_dim_out: space->n_out -= num; break; default: ; } - dim = isl_space_reset(dim, type); + space = isl_space_reset(space, type); if (type == isl_dim_param) { - if (dim && dim->nested[0] && - !(dim->nested[0] = isl_space_drop_dims(dim->nested[0], + if (space && space->nested[0] && + !(space->nested[0] = isl_space_drop_dims(space->nested[0], isl_dim_param, first, num))) goto error; - if (dim && dim->nested[1] && - !(dim->nested[1] = isl_space_drop_dims(dim->nested[1], + if (space && space->nested[1] && + !(space->nested[1] = isl_space_drop_dims(space->nested[1], isl_dim_param, first, num))) goto error; } - return dim; + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1771,6 +1975,18 @@ if (!dim) return NULL; return isl_space_drop_dims(dim, isl_dim_out, first, n); +} + +/* Remove all parameters from "space". + */ +__isl_give isl_space *isl_space_drop_all_params(__isl_take isl_space *space) +{ + isl_size nparam; + + nparam = isl_space_dim(space, isl_dim_param); + if (nparam < 0) + return isl_space_free(space); + return isl_space_drop_dims(space, isl_dim_param, 0, nparam); } __isl_give isl_space *isl_space_domain(__isl_take isl_space *space) @@ -1783,18 +1999,18 @@ return space; } -__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *space) { - if (!dim) + if (!space) return NULL; - if (!isl_space_is_set(dim)) - isl_die(isl_space_get_ctx(dim), isl_error_invalid, + if (!isl_space_is_set(space)) + isl_die(isl_space_get_ctx(space), isl_error_invalid, "not a set space", goto error); - dim = isl_space_reverse(dim); - dim = isl_space_reset(dim, isl_dim_out); - return dim; + space = isl_space_reverse(space); + space = isl_space_reset(space, isl_dim_out); + return space; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1807,16 +2023,16 @@ return space; } -__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_from_range(__isl_take isl_space *space) { - if (!dim) + if (!space) return NULL; - if (!isl_space_is_set(dim)) - isl_die(isl_space_get_ctx(dim), isl_error_invalid, + if (!isl_space_is_set(space)) + isl_die(isl_space_get_ctx(space), isl_error_invalid, "not a set space", goto error); - return isl_space_reset(dim, isl_dim_in); + return isl_space_reset(space, isl_dim_in); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1848,12 +2064,16 @@ __isl_give isl_space *isl_space_params(__isl_take isl_space *space) { + isl_size n_in, n_out; + if (isl_space_is_params(space)) return space; - space = isl_space_drop_dims(space, - isl_dim_in, 0, isl_space_dim(space, isl_dim_in)); - space = isl_space_drop_dims(space, - isl_dim_out, 0, isl_space_dim(space, isl_dim_out)); + n_in = isl_space_dim(space, isl_dim_in); + n_out = isl_space_dim(space, isl_dim_out); + if (n_in < 0 || n_out < 0) + return isl_space_free(space); + space = isl_space_drop_dims(space, isl_dim_in, 0, n_in); + space = isl_space_drop_dims(space, isl_dim_out, 0, n_out); space = mark_as_params(space); return space; } @@ -1869,32 +2089,275 @@ error: isl_space_free(space); return NULL; +} + +/* Add an unnamed tuple of dimension "dim" to "space". + * This requires "space" to be a parameter or set space. + * + * In particular, if "space" is a parameter space, then return + * a set space with the given dimension. + * If "space" is a set space, then return a map space + * with "space" as domain and a range of the given dimension. + */ +__isl_give isl_space *isl_space_add_unnamed_tuple_ui( + __isl_take isl_space *space, unsigned dim) +{ + isl_bool is_params, is_set; + + is_params = isl_space_is_params(space); + is_set = isl_space_is_set(space); + if (is_params < 0 || is_set < 0) + return isl_space_free(space); + if (!is_params && !is_set) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "cannot add tuple to map space", + return isl_space_free(space)); + if (is_params) + space = isl_space_set_from_params(space); + else + space = isl_space_from_domain(space); + space = isl_space_add_dims(space, isl_dim_out, dim); + return space; +} + +/* Add a tuple of dimension "dim" and with tuple identifier "tuple_id" + * to "space". + * This requires "space" to be a parameter or set space. + */ +__isl_give isl_space *isl_space_add_named_tuple_id_ui( + __isl_take isl_space *space, __isl_take isl_id *tuple_id, unsigned dim) +{ + space = isl_space_add_unnamed_tuple_ui(space, dim); + space = isl_space_set_tuple_id(space, isl_dim_out, tuple_id); + return space; +} + +/* Check that the identifiers in "tuple" do not appear as parameters + * in "space". + */ +static isl_stat check_fresh_params(__isl_keep isl_space *space, + __isl_keep isl_multi_id *tuple) +{ + int i; + isl_size n; + + n = isl_multi_id_size(tuple); + if (n < 0) + return isl_stat_error; + for (i = 0; i < n; ++i) { + isl_id *id; + int pos; + + id = isl_multi_id_get_at(tuple, i); + if (!id) + return isl_stat_error; + pos = isl_space_find_dim_by_id(space, isl_dim_param, id); + isl_id_free(id); + if (pos >= 0) + isl_die(isl_space_get_ctx(space), isl_error_invalid, + "parameters not unique", return isl_stat_error); + } + + return isl_stat_ok; +} + +/* Add the identifiers in "tuple" as parameters of "space" + * that are known to be fresh. + */ +static __isl_give isl_space *add_bind_params(__isl_take isl_space *space, + __isl_keep isl_multi_id *tuple) +{ + int i; + isl_size first, n; + + first = isl_space_dim(space, isl_dim_param); + n = isl_multi_id_size(tuple); + if (first < 0 || n < 0) + return isl_space_free(space); + space = isl_space_add_dims(space, isl_dim_param, n); + for (i = 0; i < n; ++i) { + isl_id *id; + + id = isl_multi_id_get_at(tuple, i); + space = isl_space_set_dim_id(space, + isl_dim_param, first + i, id); + } + + return space; +} + +/* Internal function that removes the set tuple of "space", + * which is assumed to correspond to the range space of "tuple", and + * adds the identifiers in "tuple" as fresh parameters. + * In other words, the set dimensions of "space" are reinterpreted + * as parameters, but stay in the same global positions. + */ +__isl_give isl_space *isl_space_bind_set(__isl_take isl_space *space, + __isl_keep isl_multi_id *tuple) +{ + isl_space *tuple_space; + + if (isl_space_check_is_set(space) < 0) + return isl_space_free(space); + tuple_space = isl_multi_id_peek_space(tuple); + if (isl_space_check_equal_tuples(tuple_space, space) < 0) + return isl_space_free(space); + if (check_fresh_params(space, tuple) < 0) + return isl_space_free(space); + space = isl_space_params(space); + space = add_bind_params(space, tuple); + return space; +} + +/* Internal function that removes the domain tuple of the map space "space", + * which is assumed to correspond to the range space of "tuple", and + * adds the identifiers in "tuple" as fresh parameters. + * In other words, the domain dimensions of "space" are reinterpreted + * as parameters, but stay in the same global positions. + */ +__isl_give isl_space *isl_space_bind_map_domain(__isl_take isl_space *space, + __isl_keep isl_multi_id *tuple) +{ + isl_space *tuple_space; + + if (isl_space_check_is_map(space) < 0) + return isl_space_free(space); + tuple_space = isl_multi_id_peek_space(tuple); + if (isl_space_check_domain_tuples(tuple_space, space) < 0) + return isl_space_free(space); + if (check_fresh_params(space, tuple) < 0) + return isl_space_free(space); + space = isl_space_range(space); + space = add_bind_params(space, tuple); + return space; +} + +/* Internal function that, given a space of the form [A -> B] -> C and + * a tuple of identifiers in A, returns a space B -> C with + * the identifiers in "tuple" added as fresh parameters. + * In other words, the domain dimensions of the wrapped relation + * in the domain of "space" are reinterpreted + * as parameters, but stay in the same global positions. + */ +__isl_give isl_space *isl_space_bind_domain_wrapped_domain( + __isl_take isl_space *space, __isl_keep isl_multi_id *tuple) +{ + isl_space *tuple_space; + + if (isl_space_check_is_map(space) < 0) + return isl_space_free(space); + tuple_space = isl_multi_id_peek_space(tuple); + if (isl_space_check_domain_wrapped_domain_tuples(tuple_space, + space) < 0) + return isl_space_free(space); + if (check_fresh_params(space, tuple) < 0) + return isl_space_free(space); + space = isl_space_domain_factor_range(space); + space = add_bind_params(space, tuple); + return space; +} + +/* Insert a domain tuple in "space" corresponding to the set space "domain". + * In particular, if "space" is a parameter space, then the result + * is the set space "domain" combined with the parameters of "space". + * If "space" is a set space, then the result + * is a map space with "domain" as domain and the original space as range. + */ +static __isl_give isl_space *isl_space_insert_domain( + __isl_take isl_space *space, __isl_take isl_space *domain) +{ + isl_bool is_params; + + domain = isl_space_replace_params(domain, space); + + is_params = isl_space_is_params(space); + if (is_params < 0) { + isl_space_free(domain); + space = isl_space_free(space); + } else if (is_params) { + isl_space_free(space); + space = domain; + } else { + space = isl_space_map_from_domain_and_range(domain, space); + } + return space; +} + +/* Internal function that introduces a domain in "space" + * corresponding to the range space of "tuple". + * In particular, if "space" is a parameter space, then the result + * is a set space. If "space" is a set space, then the result + * is a map space with the original space as range. + * Parameters that correspond to the identifiers in "tuple" are removed. + * + * The parameters are removed in reverse order (under the assumption + * that they appear in the same order in "multi") because + * it is slightly more efficient to remove parameters at the end. + * + * For pretty-printing purposes, the identifiers of the set dimensions + * of the introduced domain are set to the identifiers in "tuple". + */ +__isl_give isl_space *isl_space_unbind_params_insert_domain( + __isl_take isl_space *space, __isl_keep isl_multi_id *tuple) +{ + int i; + isl_size n; + isl_space *tuple_space; + + n = isl_multi_id_size(tuple); + if (!space || n < 0) + return isl_space_free(space); + for (i = n - 1; i >= 0; --i) { + isl_id *id; + int pos; + + id = isl_multi_id_get_id(tuple, i); + if (!id) + return isl_space_free(space); + pos = isl_space_find_dim_by_id(space, isl_dim_param, id); + isl_id_free(id); + if (pos < 0) + continue; + space = isl_space_drop_dims(space, isl_dim_param, pos, 1); + } + tuple_space = isl_multi_id_get_space(tuple); + for (i = 0; i < n; ++i) { + isl_id *id; + + id = isl_multi_id_get_id(tuple, i); + tuple_space = isl_space_set_dim_id(tuple_space, + isl_dim_set, i, id); + } + return isl_space_insert_domain(space, tuple_space); } -__isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_underlying(__isl_take isl_space *space, unsigned n_div) { int i; + isl_bool is_set; - if (!dim) - return NULL; - if (n_div == 0 && - dim->nparam == 0 && dim->n_in == 0 && dim->n_id == 0) - return isl_space_reset(isl_space_reset(dim, isl_dim_in), isl_dim_out); - dim = isl_space_cow(dim); - if (!dim) + is_set = isl_space_is_set(space); + if (is_set < 0) + return isl_space_free(space); + if (n_div == 0 && is_set && + space->nparam == 0 && space->n_in == 0 && space->n_id == 0) + return isl_space_reset(space, isl_dim_out); + space = isl_space_cow(space); + if (!space) return NULL; - dim->n_out += dim->nparam + dim->n_in + n_div; - dim->nparam = 0; - dim->n_in = 0; - - for (i = 0; i < dim->n_id; ++i) - isl_id_free(get_id(dim, isl_dim_out, i)); - dim->n_id = 0; - dim = isl_space_reset(dim, isl_dim_in); - dim = isl_space_reset(dim, isl_dim_out); + space->n_out += space->nparam + space->n_in + n_div; + space->nparam = 0; + space->n_in = 0; - return dim; + for (i = 0; i < space->n_id; ++i) + isl_id_free(get_id(space, isl_dim_out, i)); + space->n_id = 0; + space = isl_space_reset(space, isl_dim_in); + space = isl_space_reset(space, isl_dim_out); + space = mark_as_set(space); + + return space; } /* Are the two spaces the same, including positions and names of parameters? @@ -1912,6 +2375,80 @@ if (equal < 0 || !equal) return equal; return isl_space_has_equal_tuples(space1, space2); +} + +/* Do the tuples of "space1" correspond to those of the domain of "space2"? + * That is, is "space1" equal to the domain of "space2", ignoring parameters. + * + * "space2" is allowed to be a set space, in which case "space1" + * should be a parameter space. + */ +isl_bool isl_space_has_domain_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2) +{ + isl_bool is_set; + + is_set = isl_space_is_set(space1); + if (is_set < 0 || !is_set) + return is_set; + return isl_space_tuple_is_equal(space1, isl_dim_set, + space2, isl_dim_in); +} + +/* Do the tuples of "space1" correspond to those of the range of "space2"? + * That is, is "space1" equal to the range of "space2", ignoring parameters. + * + * "space2" is allowed to be the space of a set, + * in which case it should be equal to "space1", ignoring parameters. + */ +isl_bool isl_space_has_range_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2) +{ + isl_bool is_set; + + is_set = isl_space_is_set(space1); + if (is_set < 0 || !is_set) + return is_set; + return isl_space_tuple_is_equal(space1, isl_dim_set, + space2, isl_dim_out); +} + +/* Check that the tuples of "space1" correspond to those + * of the domain of "space2". + * That is, check that "space1" is equal to the domain of "space2", + * ignoring parameters. + */ +isl_stat isl_space_check_domain_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2) +{ + isl_bool is_equal; + + is_equal = isl_space_has_domain_tuples(space1, space2); + if (is_equal < 0) + return isl_stat_error; + if (!is_equal) + isl_die(isl_space_get_ctx(space1), isl_error_invalid, + "incompatible spaces", return isl_stat_error); + + return isl_stat_ok; +} + +/* Check that the tuples of "space1" correspond to those + * of the domain of the wrapped relation in the domain of "space2". + * That is, check that "space1" is equal to this domain, + * ignoring parameters. + */ +isl_stat isl_space_check_domain_wrapped_domain_tuples( + __isl_keep isl_space *space1, __isl_keep isl_space *space2) +{ + isl_space *domain; + isl_stat r; + + domain = isl_space_unwrap(isl_space_domain(isl_space_copy(space2))); + r = isl_space_check_domain_tuples(space1, domain); + isl_space_free(domain); + + return r; } /* Is space1 equal to the domain of space2? @@ -1926,13 +2463,10 @@ if (!space1 || !space2) return isl_bool_error; - if (!isl_space_is_set(space1)) - return isl_bool_false; equal_params = isl_space_has_equal_params(space1, space2); if (equal_params < 0 || !equal_params) return equal_params; - return isl_space_tuple_is_equal(space1, isl_dim_set, - space2, isl_dim_in); + return isl_space_has_domain_tuples(space1, space2); } /* Is space1 equal to the domain of space2? @@ -1959,13 +2493,10 @@ if (!space1 || !space2) return isl_bool_error; - if (!isl_space_is_set(space1)) - return isl_bool_false; equal_params = isl_space_has_equal_params(space1, space2); if (equal_params < 0 || !equal_params) return equal_params; - return isl_space_tuple_is_equal(space1, isl_dim_set, - space2, isl_dim_out); + return isl_space_has_range_tuples(space1, space2); } /* Is space1 equal to the range of space2? @@ -2096,15 +2627,17 @@ return hash; } -isl_bool isl_space_is_wrapping(__isl_keep isl_space *dim) +/* Is "space" the space of a set wrapping a map space? + */ +isl_bool isl_space_is_wrapping(__isl_keep isl_space *space) { - if (!dim) + if (!space) return isl_bool_error; - if (!isl_space_is_set(dim)) + if (!isl_space_is_set(space)) return isl_bool_false; - return dim->nested[1] != NULL; + return isl_bool_ok(space->nested[1] != NULL); } /* Is "space" the space of a map where the domain is a wrapped map space? @@ -2117,7 +2650,7 @@ if (isl_space_is_set(space)) return isl_bool_false; - return space->nested[0] != NULL; + return isl_bool_ok(space->nested[0] != NULL); } /* Is "space" the space of a map where the range is a wrapped map space? @@ -2130,7 +2663,7 @@ if (isl_space_is_set(space)) return isl_bool_false; - return space->nested[1] != NULL; + return isl_bool_ok(space->nested[1] != NULL); } /* Is "space" a product of two spaces? @@ -2153,48 +2686,48 @@ return isl_space_range_is_wrapping(space); } -__isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_wrap(__isl_take isl_space *space) { isl_space *wrap; - if (!dim) + if (!space) return NULL; - wrap = isl_space_set_alloc(dim->ctx, - dim->nparam, dim->n_in + dim->n_out); + wrap = isl_space_set_alloc(space->ctx, + space->nparam, space->n_in + space->n_out); - wrap = copy_ids(wrap, isl_dim_param, 0, dim, isl_dim_param); - wrap = copy_ids(wrap, isl_dim_set, 0, dim, isl_dim_in); - wrap = copy_ids(wrap, isl_dim_set, dim->n_in, dim, isl_dim_out); + wrap = copy_ids(wrap, isl_dim_param, 0, space, isl_dim_param); + wrap = copy_ids(wrap, isl_dim_set, 0, space, isl_dim_in); + wrap = copy_ids(wrap, isl_dim_set, space->n_in, space, isl_dim_out); if (!wrap) goto error; - wrap->nested[1] = dim; + wrap->nested[1] = space; return wrap; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } -__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *space) { isl_space *unwrap; - if (!dim) + if (!space) return NULL; - if (!isl_space_is_wrapping(dim)) - isl_die(dim->ctx, isl_error_invalid, "not a wrapping space", + if (!isl_space_is_wrapping(space)) + isl_die(space->ctx, isl_error_invalid, "not a wrapping space", goto error); - unwrap = isl_space_copy(dim->nested[1]); - isl_space_free(dim); + unwrap = isl_space_copy(space->nested[1]); + isl_space_free(space); return unwrap; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -2215,12 +2748,16 @@ isl_bool isl_space_may_be_set(__isl_keep isl_space *space) { isl_bool nested; + isl_size n_in; if (!space) return isl_bool_error; if (isl_space_is_set(space)) return isl_bool_true; - if (isl_space_dim(space, isl_dim_in) != 0) + n_in = isl_space_dim(space, isl_dim_in); + if (n_in < 0) + return isl_bool_error; + if (n_in != 0) return isl_bool_false; nested = isl_space_is_named_or_nested(space, isl_dim_in); if (nested < 0 || nested) @@ -2228,37 +2765,37 @@ return isl_bool_true; } -__isl_give isl_space *isl_space_reset(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_reset(__isl_take isl_space *space, enum isl_dim_type type) { - if (!isl_space_is_named_or_nested(dim, type)) - return dim; + if (!isl_space_is_named_or_nested(space, type)) + return space; - dim = isl_space_cow(dim); - if (!dim) + space = isl_space_cow(space); + if (!space) return NULL; - isl_id_free(dim->tuple_id[type - isl_dim_in]); - dim->tuple_id[type - isl_dim_in] = NULL; - isl_space_free(dim->nested[type - isl_dim_in]); - dim->nested[type - isl_dim_in] = NULL; + isl_id_free(space->tuple_id[type - isl_dim_in]); + space->tuple_id[type - isl_dim_in] = NULL; + isl_space_free(space->nested[type - isl_dim_in]); + space->nested[type - isl_dim_in] = NULL; - return dim; + return space; } -__isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_flatten(__isl_take isl_space *space) { - if (!dim) + if (!space) return NULL; - if (!dim->nested[0] && !dim->nested[1]) - return dim; + if (!space->nested[0] && !space->nested[1]) + return space; - if (dim->nested[0]) - dim = isl_space_reset(dim, isl_dim_in); - if (dim && dim->nested[1]) - dim = isl_space_reset(dim, isl_dim_out); + if (space->nested[0]) + space = isl_space_reset(space, isl_dim_in); + if (space && space->nested[1]) + space = isl_space_reset(space, isl_dim_out); - return dim; + return space; } __isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *space) @@ -2286,26 +2823,39 @@ __isl_give isl_space *isl_space_replace_params(__isl_take isl_space *dst, __isl_keep isl_space *src) { + isl_size dst_dim, src_dim; + isl_bool equal_params; enum isl_dim_type type = isl_dim_param; + + equal_params = isl_space_has_equal_params(dst, src); + if (equal_params < 0) + return isl_space_free(dst); + if (equal_params) + return dst; dst = isl_space_cow(dst); - if (!dst || !src) + dst_dim = isl_space_dim(dst, type); + src_dim = isl_space_dim(src, type); + if (dst_dim < 0 || src_dim < 0) goto error; - dst = isl_space_drop_dims(dst, type, 0, isl_space_dim(dst, type)); - dst = isl_space_add_dims(dst, type, isl_space_dim(src, type)); + dst = isl_space_drop_dims(dst, type, 0, dst_dim); + dst = isl_space_add_dims(dst, type, src_dim); dst = copy_ids(dst, type, 0, src, type); if (dst) { int i; for (i = 0; i <= 1; ++i) { + isl_space *nested; + if (!dst->nested[i]) continue; - dst->nested[i] = isl_space_replace_params( - dst->nested[i], src); - if (!dst->nested[i]) - goto error; + nested = isl_space_take_nested(dst, i); + nested = isl_space_replace_params(nested, src); + dst = isl_space_restore_nested(dst, i, nested); + if (!dst) + return NULL; } } @@ -2320,23 +2870,26 @@ * is of the form [dim -> local[..]], with n_local variables in the * range of the wrapped map. */ -__isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local) +__isl_give isl_space *isl_space_lift(__isl_take isl_space *space, + unsigned n_local) { - isl_space *local_dim; + isl_space *local_space; - if (!dim) + if (!space) return NULL; - local_dim = isl_space_dup(dim); - local_dim = isl_space_drop_dims(local_dim, isl_dim_set, 0, dim->n_out); - local_dim = isl_space_add_dims(local_dim, isl_dim_set, n_local); - local_dim = isl_space_set_tuple_name(local_dim, isl_dim_set, "local"); - dim = isl_space_join(isl_space_from_domain(dim), - isl_space_from_range(local_dim)); - dim = isl_space_wrap(dim); - dim = isl_space_set_tuple_name(dim, isl_dim_set, "lifted"); + local_space = isl_space_dup(space); + local_space = isl_space_drop_dims(local_space, isl_dim_set, 0, + space->n_out); + local_space = isl_space_add_dims(local_space, isl_dim_set, n_local); + local_space = isl_space_set_tuple_name(local_space, + isl_dim_set, "local"); + space = isl_space_join(isl_space_from_domain(space), + isl_space_from_range(local_space)); + space = isl_space_wrap(space); + space = isl_space_set_tuple_name(space, isl_dim_set, "lifted"); - return dim; + return space; } isl_bool isl_space_can_zip(__isl_keep isl_space *space) @@ -2351,19 +2904,19 @@ return isl_space_is_product(space); } -__isl_give isl_space *isl_space_zip(__isl_take isl_space *dim) +__isl_give isl_space *isl_space_zip(__isl_take isl_space *space) { isl_space *dom, *ran; isl_space *dom_dom, *dom_ran, *ran_dom, *ran_ran; - if (!isl_space_can_zip(dim)) - isl_die(dim->ctx, isl_error_invalid, "dim cannot be zipped", + if (!isl_space_can_zip(space)) + isl_die(space->ctx, isl_error_invalid, "space cannot be zipped", goto error); - if (!dim) + if (!space) return NULL; - dom = isl_space_unwrap(isl_space_domain(isl_space_copy(dim))); - ran = isl_space_unwrap(isl_space_range(dim)); + dom = isl_space_unwrap(isl_space_domain(isl_space_copy(space))); + ran = isl_space_unwrap(isl_space_range(space)); dom_dom = isl_space_domain(isl_space_copy(dom)); dom_ran = isl_space_range(dom); ran_dom = isl_space_domain(isl_space_copy(ran)); @@ -2375,19 +2928,16 @@ return isl_space_join(isl_space_from_domain(isl_space_wrap(dom)), isl_space_from_range(isl_space_wrap(ran))); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } /* Can we apply isl_space_curry to "space"? - * That is, does it have a nested relation in its domain? + * That is, does is it have a map space with a nested relation in its domain? */ isl_bool isl_space_can_curry(__isl_keep isl_space *space) { - if (!space) - return isl_bool_error; - - return !!space->nested[0]; + return isl_space_domain_is_wrapping(space); } /* Given a space (A -> B) -> C, return the corresponding space @@ -2439,6 +2989,8 @@ */ __isl_give isl_space *isl_space_range_curry(__isl_take isl_space *space) { + isl_space *nested; + if (!space) return NULL; @@ -2447,25 +2999,19 @@ "space range cannot be curried", return isl_space_free(space)); - space = isl_space_cow(space); - if (!space) - return NULL; - space->nested[1] = isl_space_curry(space->nested[1]); - if (!space->nested[1]) - return isl_space_free(space); + nested = isl_space_take_nested(space, 1); + nested = isl_space_curry(nested); + space = isl_space_restore_nested(space, 1, nested); return space; } /* Can we apply isl_space_uncurry to "space"? - * That is, does it have a nested relation in its range? + * That is, does it have a map space with a nested relation in its range? */ isl_bool isl_space_can_uncurry(__isl_keep isl_space *space) { - if (!space) - return isl_bool_error; - - return !!space->nested[1]; + return isl_space_range_is_wrapping(space); } /* Given a space A -> (B -> C), return the corresponding space @@ -2524,35 +3070,31 @@ return isl_stat_error; if (!named) isl_die(isl_space_get_ctx(space), isl_error_invalid, - "unaligned unnamed parameters", return isl_stat_error); + "unexpected unnamed parameters", return isl_stat_error); return isl_stat_ok; } -/* Align the initial parameters of dim1 to match the order in dim2. +/* Align the initial parameters of space1 to match the order in space2. */ -__isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1, - __isl_take isl_space *dim2) +__isl_give isl_space *isl_space_align_params(__isl_take isl_space *space1, + __isl_take isl_space *space2) { isl_reordering *exp; - if (!isl_space_has_named_params(dim1) || !isl_space_has_named_params(dim2)) - isl_die(isl_space_get_ctx(dim1), isl_error_invalid, - "parameter alignment requires named parameters", - goto error); + if (isl_space_check_named_params(space1) < 0 || + isl_space_check_named_params(space2) < 0) + goto error; - dim2 = isl_space_params(dim2); - exp = isl_parameter_alignment_reordering(dim1, dim2); - exp = isl_reordering_extend_space(exp, dim1); - isl_space_free(dim2); - if (!exp) - return NULL; - dim1 = isl_space_copy(exp->dim); + exp = isl_parameter_alignment_reordering(space1, space2); + exp = isl_reordering_extend_space(exp, space1); + isl_space_free(space2); + space1 = isl_reordering_get_space(exp); isl_reordering_free(exp); - return dim1; + return space1; error: - isl_space_free(dim1); - isl_space_free(dim2); + isl_space_free(space1); + isl_space_free(space2); return NULL; } @@ -2562,12 +3104,16 @@ __isl_give isl_space *isl_space_extend_domain_with_range( __isl_take isl_space *space, __isl_take isl_space *model) { + isl_size n_out; + if (!model) goto error; space = isl_space_from_domain(space); - space = isl_space_add_dims(space, isl_dim_out, - isl_space_dim(model, isl_dim_out)); + n_out = isl_space_dim(model, isl_dim_out); + if (n_out < 0) + goto error; + space = isl_space_add_dims(space, isl_dim_out, n_out); if (isl_space_has_tuple_id(model, isl_dim_out)) space = isl_space_set_tuple_id(space, isl_dim_out, isl_space_get_tuple_id(model, isl_dim_out)); @@ -2575,10 +3121,12 @@ goto error; if (model->nested[1]) { isl_space *nested = isl_space_copy(model->nested[1]); - int n_nested, n_space; + isl_size n_nested, n_space; nested = isl_space_align_params(nested, isl_space_copy(space)); n_nested = isl_space_dim(nested, isl_dim_param); n_space = isl_space_dim(space, isl_dim_param); + if (n_nested < 0 || n_space < 0) + goto error; if (n_nested > n_space) nested = isl_space_drop_dims(nested, isl_dim_param, n_space, n_nested - n_space); @@ -2602,11 +3150,15 @@ __isl_keep isl_space *space2, enum isl_dim_type type) { int cmp; + isl_size dim1, dim2; isl_space *nested1, *nested2; - if (isl_space_dim(space1, type) != isl_space_dim(space2, type)) - return isl_space_dim(space1, type) - - isl_space_dim(space2, type); + dim1 = isl_space_dim(space1, type); + dim2 = isl_space_dim(space2, type); + if (dim1 < 0 || dim2 < 0) + return 0; + if (dim1 != dim2) + return dim1 - dim2; cmp = isl_id_cmp(tuple_id(space1, type), tuple_id(space2, type)); if (cmp != 0) diff --git a/gcc/isl/isl_space_private.h b/gcc/isl/isl_space_private.h index 0912302..e6712d1 100644 --- a/gcc/isl/isl_space_private.h +++ a/gcc/isl/isl_space_private.h @@ -1,9 +1,9 @@ #ifndef ISL_SPACE_PRIVATE #define ISL_SPACE_PRIVATE #include #include -#include +#include struct isl_name; struct isl_space { @@ -22,22 +22,35 @@ isl_id **ids; }; -__isl_give isl_space *isl_space_cow(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_cow(__isl_take isl_space *space); -__isl_give isl_space *isl_space_underlying(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_underlying(__isl_take isl_space *space, unsigned n_div); uint32_t isl_space_get_tuple_hash(__isl_keep isl_space *space); uint32_t isl_space_get_hash(__isl_keep isl_space *space); uint32_t isl_space_get_domain_hash(__isl_keep isl_space *space); +isl_bool isl_space_has_domain_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2); +isl_bool isl_space_has_range_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2); +isl_stat isl_space_check_domain_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2); isl_bool isl_space_is_domain_internal(__isl_keep isl_space *space1, __isl_keep isl_space *space2); isl_bool isl_space_is_range_internal(__isl_keep isl_space *space1, __isl_keep isl_space *space2); - +isl_stat isl_space_check_domain_wrapped_domain_tuples( + __isl_keep isl_space *space1, __isl_keep isl_space *space2); + +isl_size isl_space_wrapped_dim(__isl_keep isl_space *space, + enum isl_dim_type outer, enum isl_dim_type inner); unsigned isl_space_offset(__isl_keep isl_space *dim, enum isl_dim_type type); +isl_stat isl_space_check_range(__isl_keep isl_space *space, + enum isl_dim_type type, unsigned first, unsigned n); +isl_stat isl_space_check_is_set(__isl_keep isl_space *space); isl_bool isl_space_may_be_set(__isl_keep isl_space *space); isl_bool isl_space_is_named_or_nested(__isl_keep isl_space *space, enum isl_dim_type type); @@ -47,17 +60,30 @@ isl_stat isl_space_check_named_params(__isl_keep isl_space *space); isl_stat isl_space_check_equal_params(__isl_keep isl_space *space1, __isl_keep isl_space *space2); -__isl_give isl_space *isl_space_reset(__isl_take isl_space *dim, +isl_stat isl_space_check_equal_tuples(__isl_keep isl_space *space1, + __isl_keep isl_space *space2); +__isl_give isl_space *isl_space_reset(__isl_take isl_space *space, enum isl_dim_type type); -__isl_give isl_space *isl_space_flatten(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_flatten(__isl_take isl_space *space); + +isl_stat isl_space_check_range_is_wrapping(__isl_keep isl_space *space); __isl_give isl_space *isl_space_replace_params(__isl_take isl_space *dst, __isl_keep isl_space *src); -__isl_give isl_space *isl_space_lift(__isl_take isl_space *dim, unsigned n_local); +__isl_give isl_space *isl_space_lift(__isl_take isl_space *space, + unsigned n_local); __isl_give isl_space *isl_space_extend_domain_with_range( __isl_take isl_space *domain, __isl_take isl_space *model); +__isl_give isl_space *isl_space_bind_set(__isl_take isl_space *space, + __isl_keep isl_multi_id *tuple); +__isl_give isl_space *isl_space_bind_map_domain(__isl_take isl_space *space, + __isl_keep isl_multi_id *tuple); +__isl_give isl_space *isl_space_bind_domain_wrapped_domain( + __isl_take isl_space *space, __isl_keep isl_multi_id *tuple); +__isl_give isl_space *isl_space_unbind_params_insert_domain( + __isl_take isl_space *space, __isl_keep isl_multi_id *tuple); int isl_space_cmp(__isl_keep isl_space *space1, __isl_keep isl_space *space2); diff --git a/gcc/isl/isl_srcdir.c.in b/gcc/isl/isl_srcdir.c.in index 38e30c5..7f39904 100644 --- a/gcc/isl/isl_srcdir.c.in +++ a/gcc/isl/isl_srcdir.c.in @@ -1,1 +1,1 @@ -static const char *srcdir = "@srcdir@"; +static const char *srcdir = "@OS_SRCDIR@"; diff --git a/gcc/isl/isl_stream.c b/gcc/isl/isl_stream.c index beb06a6..faa4051 100644 --- a/gcc/isl/isl_stream.c +++ a/gcc/isl/isl_stream.c @@ -20,11 +20,11 @@ enum isl_token_type type; }; -static int same_name(const void *entry, const void *val) +static isl_bool same_name(const void *entry, const void *val) { const struct isl_keyword *keyword = (const struct isl_keyword *)entry; - return !strcmp(keyword->name, val); + return isl_bool_ok(!strcmp(keyword->name, val)); } enum isl_token_type isl_stream_register_keyword(__isl_keep isl_stream *s, @@ -345,7 +345,9 @@ name_hash = isl_hash_string(isl_hash_init(), s->buffer); entry = isl_hash_table_find(s->ctx, s->keywords, name_hash, same_name, s->buffer, 0); - if (entry) { + if (!entry) + return ISL_TOKEN_ERROR; + if (entry != isl_hash_table_entry_none) { keyword = entry->data; return keyword->type; } diff --git a/gcc/isl/isl_stride.c b/gcc/isl/isl_stride.c index 8e96064..2d1c027 100644 --- a/gcc/isl/isl_stride.c +++ a/gcc/isl/isl_stride.c @@ -8,7 +8,8 @@ */ #include -#include +#include +#include #include #include @@ -21,6 +22,16 @@ isl_aff *offset; }; +/* Return the ctx to which "si" belongs. + */ +isl_ctx *isl_stride_info_get_ctx(__isl_keep isl_stride_info *si) +{ + if (!si) + return NULL; + + return isl_val_get_ctx(si->stride); +} + /* Free "si" and return NULL. */ __isl_null isl_stride_info *isl_stride_info_free( @@ -53,6 +64,18 @@ isl_val_free(stride); isl_aff_free(offset); return NULL; +} + +/* Make a copy of "si" and return it. + */ +__isl_give isl_stride_info *isl_stride_info_copy( + __isl_keep isl_stride_info *si) +{ + if (!si) + return NULL; + + return isl_stride_info_alloc(isl_val_copy(si->stride), + isl_aff_copy(si->offset)); } /* Return the stride of "si". @@ -204,20 +227,27 @@ static isl_stat detect_stride(__isl_take isl_constraint *c, void *user) { struct isl_detect_stride_data *data = user; - int i, n_div; + int i; + isl_size n_div; isl_ctx *ctx; isl_stat r = isl_stat_ok; isl_val *v, *stride, *m; - - if (!isl_constraint_is_equality(c) || - !isl_constraint_involves_dims(c, isl_dim_set, data->pos, 1)) { + isl_bool is_eq, relevant, has_stride; + + is_eq = isl_constraint_is_equality(c); + relevant = isl_constraint_involves_dims(c, isl_dim_set, data->pos, 1); + if (is_eq < 0 || relevant < 0) + goto error; + if (!is_eq || !relevant) { isl_constraint_free(c); return isl_stat_ok; } + n_div = isl_constraint_dim(c, isl_dim_div); + if (n_div < 0) + goto error; ctx = isl_constraint_get_ctx(c); stride = isl_val_zero(ctx); - n_div = isl_constraint_dim(c, isl_dim_div); for (i = 0; i < n_div; ++i) { v = isl_constraint_get_coefficient_val(c, isl_dim_div, i); stride = isl_val_gcd(stride, v); @@ -228,7 +258,8 @@ stride = isl_val_div(stride, isl_val_copy(m)); v = isl_val_div(v, isl_val_copy(m)); - if (!isl_val_is_zero(stride) && !isl_val_is_one(stride)) { + has_stride = isl_val_gt_si(stride, 1); + if (has_stride >= 0 && has_stride) { isl_aff *aff; isl_val *gcd, *a, *b; @@ -241,6 +272,7 @@ aff = isl_aff_set_coefficient_si(aff, isl_dim_div, i, 0); aff = isl_aff_set_coefficient_si(aff, isl_dim_in, data->pos, 0); + aff = isl_aff_remove_unused_divs(aff); a = isl_val_neg(a); aff = isl_aff_scale_val(aff, a); aff = isl_aff_scale_down_val(aff, m); @@ -252,7 +284,12 @@ } isl_constraint_free(c); + if (has_stride < 0) + return isl_stat_error; return r; +error: + isl_constraint_free(c); + return isl_stat_error; } /* Check if the constraints in "set" imply any stride on set dimension "pos" and @@ -321,4 +358,36 @@ set_detect_stride(set, pos, &data); return data.stride; +} + +/* Check if the constraints in "map" imply any stride on output dimension "pos", + * independently of any other output dimensions, and + * return the results in the form of an offset and a stride. + * + * Convert the input to a set with only the input dimensions and + * the single output dimension such that it be passed to + * isl_set_get_stride_info and convert the result back to + * an expression defined over the domain of "map". + */ +__isl_give isl_stride_info *isl_map_get_range_stride_info( + __isl_keep isl_map *map, int pos) +{ + isl_stride_info *si; + isl_set *set; + isl_size n_in; + + n_in = isl_map_dim(map, isl_dim_in); + if (n_in < 0) + return NULL; + map = isl_map_copy(map); + map = isl_map_project_onto(map, isl_dim_out, pos, 1); + set = isl_map_wrap(map); + si = isl_set_get_stride_info(set, n_in); + isl_set_free(set); + if (!si) + return NULL; + si->offset = isl_aff_domain_factor_domain(si->offset); + if (!si->offset) + return isl_stride_info_free(si); + return si; } diff --git a/gcc/isl/isl_tab.c b/gcc/isl/isl_tab.c index 4a81b24..1cb016a 100644 --- a/gcc/isl/isl_tab.c +++ a/gcc/isl/isl_tab.c @@ -2116,7 +2116,7 @@ * one more element in the constraint array are available in the tableau. * If tab->bmap is set, then two rows are needed instead of one. */ -int isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) +isl_stat isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) { struct isl_tab_undo *snap = NULL; struct isl_tab_var *var; @@ -2126,8 +2126,8 @@ isl_int cst; if (!tab) - return -1; - isl_assert(tab->mat->ctx, !tab->M, return -1); + return isl_stat_error; + isl_assert(tab->mat->ctx, !tab->M, return isl_stat_error); if (tab->need_undo) snap = isl_tab_snap(tab); @@ -2143,7 +2143,7 @@ isl_int_clear(cst); } if (r < 0) - return -1; + return isl_stat_error; var = &tab->con[r]; row = var->index; @@ -2156,16 +2156,16 @@ if (tab->bmap) { tab->bmap = isl_basic_map_add_ineq(tab->bmap, eq); if (isl_tab_push(tab, isl_tab_undo_bmap_ineq) < 0) - return -1; + return isl_stat_error; isl_seq_neg(eq, eq, 1 + tab->n_var); tab->bmap = isl_basic_map_add_ineq(tab->bmap, eq); isl_seq_neg(eq, eq, 1 + tab->n_var); if (isl_tab_push(tab, isl_tab_undo_bmap_ineq) < 0) - return -1; + return isl_stat_error; if (!tab->bmap) - return -1; + return isl_stat_error; if (add_zero_row(tab) < 0) - return -1; + return isl_stat_error; } sgn = isl_int_sgn(tab->mat->row[row][1]); @@ -2180,22 +2180,22 @@ if (sgn < 0) { sgn = sign_of_max(tab, var); if (sgn < -1) - return -1; + return isl_stat_error; if (sgn < 0) { if (isl_tab_mark_empty(tab) < 0) - return -1; - return 0; + return isl_stat_error; + return isl_stat_ok; } } var->is_nonneg = 1; if (to_col(tab, var) < 0) - return -1; + return isl_stat_error; var->is_nonneg = 0; if (isl_tab_kill_col(tab, var->index) < 0) - return -1; + return isl_stat_error; - return 0; + return isl_stat_ok; } /* Construct and return an inequality that expresses an upper bound @@ -2208,16 +2208,17 @@ * * m d <= e */ -static struct isl_vec *ineq_for_div(struct isl_basic_map *bmap, unsigned div) +static __isl_give isl_vec *ineq_for_div(__isl_keep isl_basic_map *bmap, + unsigned div) { - unsigned total; + isl_size total; unsigned div_pos; struct isl_vec *ineq; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return NULL; - total = isl_basic_map_total_dim(bmap); div_pos = 1 + total - bmap->n_div + div; ineq = isl_vec_alloc(bmap->ctx, 1 + total); @@ -2247,11 +2248,13 @@ static isl_stat add_div_constraints(struct isl_tab *tab, unsigned div, isl_stat (*add_ineq)(void *user, isl_int *), void *user) { - unsigned total; + isl_size total; unsigned div_pos; struct isl_vec *ineq; - total = isl_basic_map_total_dim(tab->bmap); + total = isl_basic_map_dim(tab->bmap, isl_dim_all); + if (total < 0) + return isl_stat_error; div_pos = 1 + total - tab->bmap->n_div + div; ineq = ineq_for_div(tab->bmap, div); @@ -2281,10 +2284,10 @@ isl_vec_free(ineq); - return 0; + return isl_stat_ok; error: isl_vec_free(ineq); - return -1; + return isl_stat_error; } /* Check whether the div described by "div" is obviously non-negative. @@ -2331,7 +2334,8 @@ { int r; int nonneg; - int n_div, o_div; + isl_size n_div; + int o_div; if (!tab || !div) return -1; @@ -2340,8 +2344,9 @@ isl_die(isl_tab_get_ctx(tab), isl_error_invalid, "unexpected size", return -1); - isl_assert(tab->mat->ctx, tab->bmap, return -1); n_div = isl_basic_map_dim(tab->bmap, isl_dim_div); + if (n_div < 0) + return -1; o_div = tab->n_var - n_div; if (pos < o_div || pos > tab->n_var) isl_die(isl_tab_get_ctx(tab), isl_error_invalid, @@ -2392,12 +2397,12 @@ { int i; struct isl_tab *tab; + isl_size total; - if (!bmap) + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) return NULL; - tab = isl_tab_alloc(bmap->ctx, - isl_basic_map_total_dim(bmap) + bmap->n_ineq + 1, - isl_basic_map_total_dim(bmap), 0); + tab = isl_tab_alloc(bmap->ctx, total + bmap->n_ineq + 1, total, 0); if (!tab) return NULL; tab->preserve = track; @@ -2441,14 +2446,16 @@ isl_int cst; int i; struct isl_tab *tab; - unsigned offset = 0; + isl_size offset = 0; + isl_size total; - if (!bset) - return NULL; + total = isl_basic_set_dim(bset, isl_dim_all); if (parametric) offset = isl_basic_set_dim(bset, isl_dim_param); + if (total < 0 || offset < 0) + return NULL; tab = isl_tab_alloc(bset->ctx, bset->n_eq + bset->n_ineq, - isl_basic_set_total_dim(bset) - offset, 0); + total - offset, 0); if (!tab) return NULL; tab->rational = ISL_F_ISSET(bset, ISL_BASIC_SET_RATIONAL); @@ -2747,6 +2754,18 @@ if (drop_last_con_in_row(tab, r) < 0) return isl_stat_error; + return isl_stat_ok; +} + +/* Check that "con" is a valid constraint position for "tab". + */ +static isl_stat isl_tab_check_con(struct isl_tab *tab, int con) +{ + if (!tab) + return isl_stat_error; + if (con < 0 || con >= tab->n_con) + isl_die(isl_tab_get_ctx(tab), isl_error_invalid, + "position out of bounds", return isl_stat_error); return isl_stat_ok; } @@ -3035,6 +3054,30 @@ p[index] = ~i; return 0; +} + +/* Interchange constraints "con1" and "con2" in "tab". + * In particular, interchange the contents of these entries in tab->con. + * Since tab->col_var and tab->row_var point back into this array, + * they need to be updated accordingly. + */ +isl_stat isl_tab_swap_constraints(struct isl_tab *tab, int con1, int con2) +{ + struct isl_tab_var var; + + if (isl_tab_check_con(tab, con1) < 0 || + isl_tab_check_con(tab, con2) < 0) + return isl_stat_error; + + var = tab->con[con1]; + tab->con[con1] = tab->con[con2]; + if (update_con_after_move(tab, con1, con2) < 0) + return isl_stat_error; + tab->con[con2] = var; + if (update_con_after_move(tab, con2, con1) < 0) + return isl_stat_error; + + return isl_stat_ok; } /* Rotate the "n" constraints starting at "first" to the right, @@ -3060,6 +3103,77 @@ return -1; return 0; +} + +/* Drop the "n" entries starting at position "first" in tab->con, moving all + * subsequent entries down. + * Since some of the entries of tab->row_var and tab->col_var contain + * indices into this array, they have to be updated accordingly. + */ +static isl_stat con_drop_entries(struct isl_tab *tab, + unsigned first, unsigned n) +{ + int i; + + if (first + n > tab->n_con || first + n < first) + isl_die(isl_tab_get_ctx(tab), isl_error_internal, + "invalid range", return isl_stat_error); + + tab->n_con -= n; + + for (i = first; i < tab->n_con; ++i) { + tab->con[i] = tab->con[i + n]; + if (update_con_after_move(tab, i, i + n) < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* isl_basic_map_gauss5 callback that gets called when + * two (equality) constraints "a" and "b" get interchanged + * in the basic map. Perform the same interchange in "tab". + */ +static isl_stat swap_eq(unsigned a, unsigned b, void *user) +{ + struct isl_tab *tab = user; + + return isl_tab_swap_constraints(tab, a, b); +} + +/* isl_basic_map_gauss5 callback that gets called when + * the final "n" equality constraints get removed. + * As a special case, if "n" is equal to the total number + * of equality constraints, then this means the basic map + * turned out to be empty. + * Drop the same number of equality constraints from "tab" or + * mark it empty in the special case. + */ +static isl_stat drop_eq(unsigned n, void *user) +{ + struct isl_tab *tab = user; + + if (tab->n_eq == n) + return isl_tab_mark_empty(tab); + + tab->n_eq -= n; + return con_drop_entries(tab, tab->n_eq, n); +} + +/* If "bmap" has more than a single reference, then call + * isl_basic_map_gauss on it, updating "tab" accordingly. + */ +static __isl_give isl_basic_map *gauss_if_shared(__isl_take isl_basic_map *bmap, + struct isl_tab *tab) +{ + isl_bool single; + + single = isl_basic_map_has_single_reference(bmap); + if (single < 0) + return isl_basic_map_free(bmap); + if (single) + return bmap; + return isl_basic_map_gauss5(bmap, NULL, &swap_eq, &drop_eq, tab); } /* Make the equalities that are implicit in "bmap" but that have been @@ -3088,20 +3202,25 @@ * If "tab" contains any constraints that are not in "bmap" then they * appear after those in "bmap" and they should be left untouched. * - * Note that this function leaves "bmap" in a temporary state - * as it does not call isl_basic_map_gauss. Calling this function - * is the responsibility of the caller. + * Note that this function only calls isl_basic_map_gauss + * (in case some equality constraints got detected) + * if "bmap" has more than one reference. + * If it only has a single reference, then it is left in a temporary state, + * because the caller may require this state. + * Calling isl_basic_map_gauss is then the responsibility of the caller. */ __isl_give isl_basic_map *isl_tab_make_equalities_explicit(struct isl_tab *tab, __isl_take isl_basic_map *bmap) { int i; + unsigned n_eq; if (!tab || !bmap) return isl_basic_map_free(bmap); if (tab->empty) return bmap; + n_eq = tab->n_eq; for (i = bmap->n_ineq - 1; i >= 0; --i) { if (!isl_tab_is_equality(tab, bmap->n_eq + i)) continue; @@ -3114,6 +3233,9 @@ tab->n_eq++; } + if (n_eq != tab->n_eq) + bmap = gauss_if_shared(bmap, tab); + return bmap; } @@ -3313,11 +3435,8 @@ */ int isl_tab_is_redundant(struct isl_tab *tab, int con) { - if (!tab) + if (isl_tab_check_con(tab, con) < 0) return -1; - if (con < 0 || con >= tab->n_con) - isl_die(isl_tab_get_ctx(tab), isl_error_invalid, - "position out of bounds", return -1); if (tab->con[con].is_zero) return 0; if (tab->con[con].is_redundant) @@ -3579,7 +3698,7 @@ if (!tab) return isl_bool_error; - return tab->need_undo; + return isl_bool_ok(tab->need_undo); } /* Remove all tracking of undo information from "tab", invalidating @@ -3681,7 +3800,8 @@ case isl_tab_undo_redundant: if (!var->is_row || var->index != tab->n_redundant - 1) isl_die(isl_tab_get_ctx(tab), isl_error_internal, - "not undoing last redundant row", return -1); + "not undoing last redundant row", + return isl_stat_error); return restore_last_redundant(tab); case isl_tab_undo_freeze: var->frozen = 0; @@ -3758,8 +3878,12 @@ static isl_stat drop_bmap_div(struct isl_tab *tab, int pos) { int off; + isl_size n_div; - off = tab->n_var - isl_basic_map_dim(tab->bmap, isl_dim_div); + n_div = isl_basic_map_dim(tab->bmap, isl_dim_div); + if (n_div < 0) + return isl_stat_error; + off = tab->n_var - n_div; if (isl_basic_map_drop_div(tab->bmap, pos - off) < 0) return isl_stat_error; if (tab->samples) { @@ -3869,9 +3993,11 @@ case isl_tab_undo_unrestrict: return perform_undo_var(tab, undo); case isl_tab_undo_bmap_eq: - return isl_basic_map_free_equality(tab->bmap, 1); + tab->bmap = isl_basic_map_free_equality(tab->bmap, 1); + return tab->bmap ? isl_stat_ok : isl_stat_error; case isl_tab_undo_bmap_ineq: - return isl_basic_map_free_inequality(tab->bmap, 1); + tab->bmap = isl_basic_map_free_inequality(tab->bmap, 1); + return tab->bmap ? isl_stat_ok : isl_stat_error; case isl_tab_undo_bmap_div: return drop_bmap_div(tab, undo->u.var_index); case isl_tab_undo_saved_basis: @@ -3895,12 +4021,12 @@ /* Return the tableau to the state it was in when the snapshot "snap" * was taken. */ -int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap) +isl_stat isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap) { struct isl_tab_undo *undo, *next; if (!tab) - return -1; + return isl_stat_error; tab->in_undo = 1; for (undo = tab->top; undo && undo != &tab->bottom; undo = next) { @@ -3911,15 +4037,15 @@ tab->top = undo; free_undo(tab); tab->in_undo = 0; - return -1; + return isl_stat_error; } free_undo_record(undo); } tab->in_undo = 0; tab->top = undo; if (!undo) - return -1; - return 0; + return isl_stat_error; + return isl_stat_ok; } /* The given row "row" represents an inequality violated by all diff --git a/gcc/isl/isl_tab.h b/gcc/isl/isl_tab.h index f3a4dfb..8b15cb0 100644 --- a/gcc/isl/isl_tab.h +++ a/gcc/isl/isl_tab.h @@ -208,7 +208,7 @@ unsigned flags) WARN_UNUSED; isl_stat isl_tab_add_ineq(struct isl_tab *tab, isl_int *ineq) WARN_UNUSED; -int isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED; +isl_stat isl_tab_add_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED; int isl_tab_add_valid_eq(struct isl_tab *tab, isl_int *eq) WARN_UNUSED; int isl_tab_freeze_constraint(struct isl_tab *tab, int con) WARN_UNUSED; @@ -237,7 +237,7 @@ enum isl_ineq_type isl_tab_ineq_type(struct isl_tab *tab, isl_int *ineq); struct isl_tab_undo *isl_tab_snap(struct isl_tab *tab); -int isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap) WARN_UNUSED; +isl_stat isl_tab_rollback(struct isl_tab *tab, struct isl_tab_undo *snap) WARN_UNUSED; isl_bool isl_tab_need_undo(struct isl_tab *tab); void isl_tab_clear_undo(struct isl_tab *tab); @@ -333,5 +333,7 @@ int isl_tab_add_div(struct isl_tab *tab, __isl_keep isl_vec *div); int isl_tab_shift_var(struct isl_tab *tab, int pos, isl_int shift) WARN_UNUSED; + +isl_stat isl_tab_swap_constraints(struct isl_tab *tab, int con1, int con2); #endif diff --git a/gcc/isl/isl_tab_lexopt_templ.c b/gcc/isl/isl_tab_lexopt_templ.c index 751e7bf..45eba10 100644 --- a/gcc/isl/isl_tab_lexopt_templ.c +++ a/gcc/isl/isl_tab_lexopt_templ.c @@ -52,6 +52,7 @@ { int i, n, k; int *list = NULL; + isl_size bmap_in, bmap_param, bmap_all; unsigned n_in, n_out, n_div; isl_ctx *ctx; isl_vec *var = NULL; @@ -61,9 +62,13 @@ map_space = isl_basic_map_get_space(bmap); set_space = empty ? isl_basic_set_get_space(dom) : NULL; - n_in = isl_basic_map_dim(bmap, isl_dim_param) + - isl_basic_map_dim(bmap, isl_dim_in); - n_out = isl_basic_map_dim(bmap, isl_dim_all) - n_in; + bmap_in = isl_basic_map_dim(bmap, isl_dim_in); + bmap_param = isl_basic_map_dim(bmap, isl_dim_param); + bmap_all = isl_basic_map_dim(bmap, isl_dim_all); + if (bmap_in < 0 || bmap_param < 0 || bmap_all < 0) + goto error; + n_in = bmap_param + bmap_in; + n_out = bmap_all - n_in; ctx = isl_basic_map_get_ctx(bmap); list = isl_alloc_array(ctx, int, bmap->n_ineq); diff --git a/gcc/isl/isl_tab_pip.c b/gcc/isl/isl_tab_pip.c index c501034..bb3f049 100644 --- a/gcc/isl/isl_tab_pip.c +++ a/gcc/isl/isl_tab_pip.c @@ -184,7 +184,7 @@ int rational; int level; int max; - int n_out; + isl_size n_out; isl_space *space; struct isl_context *context; struct isl_partial_sol *partial; @@ -250,12 +250,13 @@ unsigned first) { int i; - unsigned rows, cols, n; + isl_size rows, cols; + unsigned n; - if (!M) - return isl_stat_error; rows = isl_mat_rows(M); cols = isl_mat_cols(M); + if (rows < 0 || cols < 0) + return isl_stat_error; n = cols - first; for (i = 0; i < rows; ++i) if (isl_seq_first_non_zero(M->row[i] + first, n) != -1) @@ -274,13 +275,14 @@ __isl_take isl_multi_aff *ma, __isl_take isl_local_space *ls, __isl_take isl_mat *M) { - int i, dim; + int i; + isl_size dim; isl_aff *aff; - if (!ma || !ls || !M) + dim = isl_local_space_dim(ls, isl_dim_all); + if (!ma || dim < 0 || !M) goto error; - dim = isl_local_space_dim(ls, isl_dim_all); if (check_final_columns_are_zero(M, 1 + dim) < 0) goto error; for (i = 1; i < M->n_row; ++i) { @@ -328,9 +330,12 @@ { isl_local_space *ls; isl_multi_aff *ma; - int n_div, n_known; + isl_size n_div; + int n_known; n_div = isl_basic_set_dim(dom, isl_dim_div); + if (n_div < 0) + goto error; n_known = n_div - sol->context->n_unknown; ma = isl_multi_aff_alloc(isl_space_copy(sol->space)); @@ -342,6 +347,11 @@ if (!ma) dom = isl_basic_set_free(dom); sol_push_sol(sol, dom, ma); + return; +error: + isl_basic_set_free(dom); + isl_mat_free(M); + sol_push_sol(sol, NULL, NULL); } /* Pop one partial solution from the partial solution stack and @@ -999,14 +1009,14 @@ static __isl_give isl_vec *ineq_for_div(__isl_keep isl_basic_set *bset, unsigned div) { - unsigned total; + isl_size total; unsigned div_pos; struct isl_vec *ineq; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; - total = isl_basic_set_total_dim(bset); div_pos = 1 + total - bset->n_div + div; ineq = isl_vec_alloc(bset->ctx, 1 + total); @@ -2063,7 +2073,7 @@ if (!tab->samples) return isl_bool_error; - return nonneg; + return isl_bool_ok(nonneg); } /* Add a div specified by "div" to both the main tableau and @@ -2112,19 +2122,26 @@ return -1; } +/* Return the position of the integer division that is equal to div/denom + * if there is one. Otherwise, return a position beyond the integer divisions. + */ static int find_div(struct isl_tab *tab, isl_int *div, isl_int denom) { int i; - unsigned total = isl_basic_map_total_dim(tab->bmap); - - for (i = 0; i < tab->bmap->n_div; ++i) { + isl_size total = isl_basic_map_dim(tab->bmap, isl_dim_all); + isl_size n_div; + + n_div = isl_basic_map_dim(tab->bmap, isl_dim_div); + if (total < 0 || n_div < 0) + return -1; + for (i = 0; i < n_div; ++i) { if (isl_int_ne(tab->bmap->div[i][0], denom)) continue; if (!isl_seq_eq(tab->bmap->div[i] + 1, div, 1 + total)) continue; return i; } - return -1; + return n_div; } /* Return the index of a div that corresponds to "div". @@ -2135,12 +2152,16 @@ { int d; struct isl_tab *context_tab = context->op->peek_tab(context); + unsigned n_div; if (!context_tab) return -1; + n_div = isl_basic_map_dim(context_tab->bmap, isl_dim_div); d = find_div(context_tab, div->el + 1, div->el[0]); - if (d != -1) + if (d < 0) + return -1; + if (d < n_div) return d; return add_div(tab, context, div); @@ -2283,15 +2304,23 @@ struct isl_tab *tab; unsigned n_var; unsigned o_var; + isl_size total; + total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return NULL; tab = isl_tab_alloc(bmap->ctx, 2 * bmap->n_eq + bmap->n_ineq + 1, - isl_basic_map_total_dim(bmap), M); + total, M); if (!tab) return NULL; tab->rational = ISL_F_ISSET(bmap, ISL_BASIC_MAP_RATIONAL); if (dom) { - tab->n_param = isl_basic_set_total_dim(dom) - dom->n_div; + isl_size dom_total; + dom_total = isl_basic_set_dim(dom, isl_dim_all); + if (dom_total < 0) + goto error; + tab->n_param = dom_total - dom->n_div; tab->n_div = dom->n_div; tab->row_sign = isl_calloc_array(bmap->ctx, enum isl_tab_row_sign, tab->mat->n_row); @@ -2890,8 +2919,10 @@ int i, j; struct isl_vec *cst; struct isl_basic_set *bset = isl_tab_peek_bset(cgbr->tab); - unsigned dim = isl_basic_set_total_dim(bset); + isl_size dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + return; cst = isl_vec_alloc(cgbr->tab->mat->ctx, bset->n_ineq); if (!cst) return; @@ -3131,8 +3162,10 @@ if (cgbr->shifted && !cgbr->shifted->empty && use_shifted(cgbr)) { int i; - unsigned dim; - dim = isl_basic_map_total_dim(cgbr->tab->bmap); + isl_size dim; + dim = isl_basic_map_dim(cgbr->tab->bmap, isl_dim_all); + if (dim < 0) + goto error; if (isl_tab_extend_cons(cgbr->shifted, 1) < 0) goto error; @@ -3402,9 +3435,12 @@ { struct isl_context_gbr *cgbr = (struct isl_context_gbr *)context; if (cgbr->cone) { - int r, n_div, o_div; + int r, o_div; + isl_size n_div; n_div = isl_basic_map_dim(cgbr->cone->bmap, isl_dim_div); + if (n_div < 0) + return isl_bool_error; o_div = cgbr->cone->n_var - n_div; if (isl_tab_extend_cons(cgbr->cone, 3) < 0) @@ -3611,6 +3647,7 @@ { struct isl_context *context; int first; + isl_size n_div; if (!dom) return NULL; @@ -3624,9 +3661,10 @@ return NULL; first = isl_basic_set_first_unknown_div(dom); - if (first < 0) + n_div = isl_basic_set_dim(dom, isl_dim_div); + if (first < 0 || n_div < 0) return context->op->free(context); - context->n_unknown = isl_basic_set_dim(dom, isl_dim_div) - first; + context->n_unknown = n_div - first; return context; } @@ -3649,7 +3687,7 @@ sol->space = isl_basic_map_get_space(bmap); sol->context = isl_context_alloc(dom); - if (!sol->space || !sol->context) + if (sol->n_out < 0 || !sol->space || !sol->context) return isl_stat_error; return isl_stat_ok; @@ -4273,30 +4311,37 @@ /* Check if integer division "div" of "dom" also occurs in "bmap". * If so, return its position within the divs. - * If not, return -1. + * Otherwise, return a position beyond the integer divisions. */ -static int find_context_div(struct isl_basic_map *bmap, - struct isl_basic_set *dom, unsigned div) +static int find_context_div(__isl_keep isl_basic_map *bmap, + __isl_keep isl_basic_set *dom, unsigned div) { int i; - unsigned b_dim = isl_space_dim(bmap->dim, isl_dim_all); - unsigned d_dim = isl_space_dim(dom->dim, isl_dim_all); - - if (isl_int_is_zero(dom->div[div][0])) - return -1; - if (isl_seq_first_non_zero(dom->div[div] + 2 + d_dim, dom->n_div) != -1) + isl_size b_v_div, d_v_div; + isl_size n_div; + + b_v_div = isl_basic_map_var_offset(bmap, isl_dim_div); + d_v_div = isl_basic_set_var_offset(dom, isl_dim_div); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (b_v_div < 0 || d_v_div < 0 || n_div < 0) return -1; - for (i = 0; i < bmap->n_div; ++i) { + if (isl_int_is_zero(dom->div[div][0])) + return n_div; + if (isl_seq_first_non_zero(dom->div[div] + 2 + d_v_div, + dom->n_div) != -1) + return n_div; + + for (i = 0; i < n_div; ++i) { if (isl_int_is_zero(bmap->div[i][0])) continue; - if (isl_seq_first_non_zero(bmap->div[i] + 2 + d_dim, - (b_dim - d_dim) + bmap->n_div) != -1) + if (isl_seq_first_non_zero(bmap->div[i] + 2 + d_v_div, + (b_v_div - d_v_div) + n_div) != -1) continue; - if (isl_seq_eq(bmap->div[i], dom->div[div], 2 + d_dim)) + if (isl_seq_eq(bmap->div[i], dom->div[div], 2 + d_v_div)) return i; } - return -1; + return n_div; } /* The correspondence between the variables in the main tableau, @@ -4319,11 +4364,20 @@ int i; int common = 0; int other; + unsigned bmap_n_div; - for (i = 0; i < dom->n_div; ++i) - if (find_context_div(bmap, dom, i) != -1) + bmap_n_div = isl_basic_map_dim(bmap, isl_dim_div); + + for (i = 0; i < dom->n_div; ++i) { + int pos; + + pos = find_context_div(bmap, dom, i); + if (pos < 0) + return isl_basic_map_free(bmap); + if (pos < bmap_n_div) common++; - other = bmap->n_div - common; + } + other = bmap_n_div - common; if (dom->n_div - common > 0) { bmap = isl_basic_map_extend_space(bmap, isl_space_copy(bmap->dim), dom->n_div - common, 0, 0); @@ -4332,14 +4386,17 @@ } for (i = 0; i < dom->n_div; ++i) { int pos = find_context_div(bmap, dom, i); - if (pos < 0) { + if (pos < 0) + bmap = isl_basic_map_free(bmap); + if (pos >= bmap_n_div) { pos = isl_basic_map_alloc_div(bmap); if (pos < 0) goto error; isl_int_set_si(bmap->div[pos][0], 0); + bmap_n_div++; } if (pos != other + i) - isl_basic_map_swap_div(bmap, pos, other + i); + bmap = isl_basic_map_swap_div(bmap, pos, other + i); } return bmap; error: @@ -4509,12 +4566,14 @@ /* Check whether the coefficients of the output variables * of the constraint in "entry" are equal to info->val. */ -static int constraint_equal(const void *entry, const void *val) +static isl_bool constraint_equal(const void *entry, const void *val) { isl_int **row = (isl_int **)entry; const struct isl_constraint_equal_info *info = val; + int eq; - return isl_seq_eq((*row) + 1 + info->n_in, info->val, info->n_out); + eq = isl_seq_eq((*row) + 1 + info->n_in, info->val, info->n_out); + return isl_bool_ok(eq); } /* Check whether "bmap" has a pair of constraints that have @@ -4536,21 +4595,23 @@ struct isl_hash_table *table = NULL; struct isl_hash_table_entry *entry; struct isl_constraint_equal_info info; - unsigned n_out; - unsigned n_div; + isl_size nparam, n_in, n_out, n_div; ctx = isl_basic_map_get_ctx(bmap); table = isl_hash_table_alloc(ctx, bmap->n_ineq); if (!table) goto error; - info.n_in = isl_basic_map_dim(bmap, isl_dim_param) + - isl_basic_map_dim(bmap, isl_dim_in); + nparam = isl_basic_map_dim(bmap, isl_dim_param); + n_in = isl_basic_map_dim(bmap, isl_dim_in); + n_out = isl_basic_map_dim(bmap, isl_dim_out); + n_div = isl_basic_map_dim(bmap, isl_dim_div); + if (nparam < 0 || n_in < 0 || n_out < 0 || n_div < 0) + goto error; + info.n_in = nparam + n_in; occurrences = count_occurrences(bmap, info.n_in); if (info.n_in && !occurrences) goto error; - n_out = isl_basic_map_dim(bmap, isl_dim_out); - n_div = isl_basic_map_dim(bmap, isl_dim_div); info.n_out = n_out + n_div; for (i = 0; i < bmap->n_ineq; ++i) { uint32_t hash; @@ -4581,7 +4642,7 @@ isl_hash_table_free(ctx, table); free(occurrences); - return i < bmap->n_ineq; + return isl_bool_ok(i < bmap->n_ineq); error: isl_hash_table_free(ctx, table); free(occurrences); @@ -4638,21 +4699,21 @@ * b_i <= b_j for j > i * b_i < b_j for j < i */ -static __isl_give isl_set *set_minimum(__isl_take isl_space *dim, +static __isl_give isl_set *set_minimum(__isl_take isl_space *space, __isl_take isl_mat *var) { int i, k; isl_basic_set *bset = NULL; isl_set *set = NULL; - if (!dim || !var) + if (!space || !var) goto error; - set = isl_set_alloc_space(isl_space_copy(dim), + set = isl_set_alloc_space(isl_space_copy(space), var->n_row, ISL_SET_DISJOINT); for (i = 0; i < var->n_row; ++i) { - bset = isl_basic_set_alloc_space(isl_space_copy(dim), 0, + bset = isl_basic_set_alloc_space(isl_space_copy(space), 0, 1, var->n_row - 1); k = isl_basic_set_alloc_equality(bset); if (k < 0) @@ -4663,13 +4724,13 @@ set = isl_set_add_basic_set(set, bset); } - isl_space_free(dim); + isl_space_free(space); isl_mat_free(var); return set; error: isl_basic_set_free(bset); isl_set_free(set); - isl_space_free(dim); + isl_space_free(space); isl_mat_free(var); return NULL; } @@ -4687,11 +4748,13 @@ __isl_keep isl_mat *cst) { int i, j; - unsigned total; + isl_size total; unsigned pos; pos = cst->n_col - 1; total = isl_basic_map_dim(bmap, isl_dim_all); + if (total < 0) + return isl_bool_error; for (i = 0; i < bmap->n_div; ++i) if (!isl_int_is_zero(bmap->div[i][2 + pos])) @@ -4753,7 +4816,7 @@ return isl_bool_false; } -/* Given a set of which the last set variable is the minimum +/* Given a map of which the last input variable is the minimum * of the bounds in "cst", split each basic set in the set * in pieces where one of the bounds is (strictly) smaller than the others. * This subdivision is given in "min_expr". @@ -4765,72 +4828,22 @@ * i.e., l <= m = min(a,b), then we can simply project out m * to obtain l <= a and l <= b, without having to split on whether * m is equal to a or b. - */ -static __isl_give isl_set *split(__isl_take isl_set *empty, - __isl_take isl_set *min_expr, __isl_take isl_mat *cst) -{ - int n_in; - int i; - isl_space *dim; - isl_set *res; - - if (!empty || !min_expr || !cst) - goto error; - - n_in = isl_set_dim(empty, isl_dim_set); - dim = isl_set_get_space(empty); - dim = isl_space_drop_dims(dim, isl_dim_set, n_in - 1, 1); - res = isl_set_empty(dim); - - for (i = 0; i < empty->n; ++i) { - isl_bool split; - isl_set *set; - - set = isl_set_from_basic_set(isl_basic_set_copy(empty->p[i])); - split = need_split_basic_set(empty->p[i], cst); - if (split < 0) - set = isl_set_free(set); - else if (split) - set = isl_set_intersect(set, isl_set_copy(min_expr)); - set = isl_set_remove_dims(set, isl_dim_set, n_in - 1, 1); - - res = isl_set_union_disjoint(res, set); - } - - isl_set_free(empty); - isl_set_free(min_expr); - isl_mat_free(cst); - return res; -error: - isl_set_free(empty); - isl_set_free(min_expr); - isl_mat_free(cst); - return NULL; -} - -/* Given a map of which the last input variable is the minimum - * of the bounds in "cst", split each basic set in the set - * in pieces where one of the bounds is (strictly) smaller than the others. - * This subdivision is given in "min_expr". - * The variable is subsequently projected out. - * - * The implementation is essentially the same as that of "split". */ static __isl_give isl_map *split_domain(__isl_take isl_map *opt, __isl_take isl_set *min_expr, __isl_take isl_mat *cst) { - int n_in; + isl_size n_in; int i; - isl_space *dim; + isl_space *space; isl_map *res; - if (!opt || !min_expr || !cst) + n_in = isl_map_dim(opt, isl_dim_in); + if (n_in < 0 || !min_expr || !cst) goto error; - n_in = isl_map_dim(opt, isl_dim_in); - dim = isl_map_get_space(opt); - dim = isl_space_drop_dims(dim, isl_dim_in, n_in - 1, 1); - res = isl_map_empty(dim); + space = isl_map_get_space(opt); + space = isl_space_drop_dims(space, isl_dim_in, n_in - 1, 1); + res = isl_map_empty(space); for (i = 0; i < opt->n; ++i) { isl_map *map; @@ -4857,6 +4870,24 @@ isl_set_free(min_expr); isl_mat_free(cst); return NULL; +} + +/* Given a set of which the last set variable is the minimum + * of the bounds in "cst", split each basic set in the set + * in pieces where one of the bounds is (strictly) smaller than the others. + * This subdivision is given in "min_expr". + * The variable is subsequently projected out. + */ +static __isl_give isl_set *split(__isl_take isl_set *empty, + __isl_take isl_set *min_expr, __isl_take isl_mat *cst) +{ + isl_map *map; + + map = isl_map_from_domain(empty); + map = split_domain(map, min_expr, cst); + empty = isl_map_domain(map); + + return empty; } static __isl_give isl_map *basic_map_partial_lexopt( @@ -4921,11 +4952,13 @@ static __isl_give isl_basic_set *extract_domain(__isl_keep isl_basic_map *bmap, unsigned flags) { - int n_div; - int n_out; + isl_size n_div; + isl_size n_out; n_div = isl_basic_map_dim(bmap, isl_dim_div); n_out = isl_basic_map_dim(bmap, isl_dim_out); + if (n_div < 0 || n_out < 0) + return NULL; bmap = isl_basic_map_copy(bmap); if (ISL_FL_ISSET(flags, ISL_OPT_QE)) { bmap = isl_basic_map_drop_constraints_involving_dims(bmap, @@ -4979,18 +5012,20 @@ static isl_bool region_is_trivial(struct isl_tab *tab, int pos, __isl_keep isl_mat *trivial) { - int n, len; + isl_size n, len; isl_vec *v; isl_bool is_trivial; - if (!trivial) + n = isl_mat_rows(trivial); + if (n < 0) return isl_bool_error; - n = isl_mat_rows(trivial); if (n == 0) return isl_bool_false; len = isl_mat_cols(trivial); + if (len < 0) + return isl_bool_error; v = extract_sample_sequence(tab, pos, len); v = isl_mat_vec_product(isl_mat_copy(trivial), v); is_trivial = isl_vec_is_zero(v); @@ -5123,12 +5158,14 @@ static isl_stat fix_zero(struct isl_tab *tab, struct isl_trivial_region *region, int dir, struct isl_lexmin_data *data) { - int len; + isl_size len; data->v = isl_vec_clr(data->v); if (!data->v) return isl_stat_error; len = isl_mat_cols(region->trivial); + if (len < 0) + return isl_stat_error; isl_seq_cpy(data->v->el + 1 + region->pos, region->trivial->row[dir], len); if (add_lexmin_eq(tab, data->v->el) < 0) @@ -5149,13 +5186,15 @@ struct isl_trivial_region *region, int side, struct isl_lexmin_data *data) { - int len; + isl_size len; data->v = isl_vec_clr(data->v); if (!data->v) goto error; isl_int_set_si(data->v->el[0], -1); len = isl_mat_cols(region->trivial); + if (len < 0) + goto error; if (side % 2 == 0) isl_seq_cpy(data->v->el + 1 + region->pos, region->trivial->row[side / 2], len); @@ -5232,14 +5271,20 @@ /* Initialize "local" to refer to region "region" and * to initiate processing at this level. */ -static void init_local_region(struct isl_local_region *local, int region, +static isl_stat init_local_region(struct isl_local_region *local, int region, struct isl_lexmin_data *data) { - local->n = isl_mat_rows(data->region[region].trivial); + isl_size n = isl_mat_rows(data->region[region].trivial); + + if (n < 0) + return isl_stat_error; + local->n = n; local->region = region; local->side = 0; local->update = 0; local->n_zero = 0; + + return isl_stat_ok; } /* What to do next after entering a level of the backtracking procedure. @@ -5322,7 +5367,8 @@ isl_die(isl_vec_get_ctx(data->v), isl_error_internal, "nesting level too deep", return isl_next_error); - init_local_region(local, r, data); + if (init_local_region(local, r, data) < 0) + return isl_next_error; if (isl_tab_extend_cons(data->tab, 2 * local->n + 2 * data->n_op) < 0) return isl_next_error; @@ -5757,18 +5803,27 @@ * In particular, check if the last input variable appears in any * of the expressions in "maff". */ -static int need_substitution(__isl_keep isl_multi_aff *maff) +static isl_bool need_substitution(__isl_keep isl_multi_aff *maff) { int i; + isl_size n_in; unsigned pos; + + n_in = isl_multi_aff_dim(maff, isl_dim_in); + if (n_in < 0) + return isl_bool_error; + pos = n_in - 1; - pos = isl_multi_aff_dim(maff, isl_dim_in) - 1; + for (i = 0; i < maff->n; ++i) { + isl_bool involves; - for (i = 0; i < maff->n; ++i) - if (isl_aff_involves_dims(maff->p[i], isl_dim_in, pos, 1)) - return 1; + involves = isl_aff_involves_dims(maff->u.p[i], + isl_dim_in, pos, 1); + if (involves < 0 || involves) + return involves; + } - return 0; + return isl_bool_false; } /* Given a set of upper bounds on the last "input" variable m, @@ -5853,7 +5908,7 @@ __isl_take isl_pw_multi_aff *opt, __isl_take isl_pw_aff *min_expr_pa, __isl_take isl_set *min_expr, __isl_take isl_mat *cst) { - int n_in; + isl_size n_in; int i; isl_space *space; isl_pw_multi_aff *res; @@ -5862,19 +5917,25 @@ goto error; n_in = isl_pw_multi_aff_dim(opt, isl_dim_in); + if (n_in < 0) + goto error; space = isl_pw_multi_aff_get_space(opt); space = isl_space_drop_dims(space, isl_dim_in, n_in - 1, 1); res = isl_pw_multi_aff_empty(space); for (i = 0; i < opt->n; ++i) { + isl_bool subs; isl_pw_multi_aff *pma; pma = isl_pw_multi_aff_alloc(isl_set_copy(opt->p[i].set), isl_multi_aff_copy(opt->p[i].maff)); - if (need_substitution(opt->p[i].maff)) + subs = need_substitution(opt->p[i].maff); + if (subs < 0) { + pma = isl_pw_multi_aff_free(pma); + } else if (subs) { pma = isl_pw_multi_aff_substitute(pma, isl_dim_in, n_in - 1, min_expr_pa); - else { + } else { isl_bool split; split = need_split_set(opt->p[i].set, cst); if (split < 0) diff --git a/gcc/isl/isl_test.c b/gcc/isl/isl_test.c index 0306347..2914cdf 100644 --- a/gcc/isl/isl_test.c +++ a/gcc/isl/isl_test.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -119,6 +120,195 @@ return mv ? 0 : -1; } +/* String descriptions of multi piecewise affine expressions + * that are used for testing printing and parsing. + */ +static const char *reparse_multi_pw_aff_tests[] = { + "{ A[x, y] -> [] : x + y >= 0 }", + "{ A[x, y] -> B[] : x + y >= 0 }", + "{ A[x, y] -> [x] : x + y >= 0 }", + "[N] -> { A[x, y] -> [x] : x + y <= N }", + "{ A[x, y] -> [x, y] : x + y >= 0 }", + "{ A[x, y] -> [(x : x >= 0), (y : y >= 0)] : x + y >= 0 }", + "[N] -> { [] : N >= 0 }", + "[N] -> { [] : N >= 0 }", + "[N] -> { [N] : N >= 0 }", + "[N] -> { [N, N + 1] : N >= 0 }", + "[N, M] -> { [(N : N >= 0), (M : M >= 0)] : N + M >= 0 }", +}; + +#undef BASE +#define BASE multi_pw_aff + +#include "check_reparse_templ.c" +#include "check_reparse_test_templ.c" + +/* String descriptions of piecewise multi affine expressions + * that are used for testing printing and parsing. + */ +static const char *reparse_pw_multi_aff_tests[] = { + "{ [x] -> [x] }", + "{ [x] -> [x % 4] }", + "{ [x] -> [x % 4] : x mod 3 = 1 }", + "{ [x, x] -> [x % 4] }", + "{ [x, x + 1] -> [x % 4] : x mod 3 = 1 }", + "{ [x, x mod 2] -> [x % 4] }", +}; + +#undef BASE +#define BASE pw_multi_aff + +#include "check_reparse_templ.c" +#include "check_reparse_test_templ.c" + +/* Test parsing of piecewise multi affine expressions by printing + * the expressions and checking that parsing the output results + * in the same expression. + * Do this for an expression converted from a map with an output + * dimension name that is equal to an automatically generated name, and + * a set of expressions parsed from strings. + */ +static isl_stat test_parse_pma(isl_ctx *ctx) +{ + isl_map *map; + isl_pw_multi_aff *pma; + + map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }"); + pma = isl_pw_multi_aff_from_map(map); + if (check_reparse_pw_multi_aff(ctx, pma) < 0) + return isl_stat_error; + + if (check_reparse_pw_multi_aff_tests(ctx) < 0) + return isl_stat_error; + + return isl_stat_ok; +} + +/* Test parsing of multi piecewise affine expressions by printing + * the expressions and checking that parsing the output results + * in the same expression. + * Do this for a couple of manually constructed expressions, + * an expression converted from a map with an output dimension name + * that is equal to an automatically generated name, and + * a set of expressions parsed from strings. + */ +static int test_parse_mpa(isl_ctx *ctx) +{ + isl_space *space; + isl_set *dom; + isl_map *map; + isl_pw_multi_aff *pma; + isl_multi_pw_aff *mpa; + isl_stat r; + + space = isl_space_set_alloc(ctx, 0, 0); + space = isl_space_set_tuple_name(space, isl_dim_set, "A"); + mpa = isl_multi_pw_aff_zero(space); + r = check_reparse_multi_pw_aff(ctx, mpa); + if (r < 0) + return -1; + + space = isl_space_set_alloc(ctx, 1, 0); + space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); + space = isl_space_set_tuple_name(space, isl_dim_set, "A"); + dom = isl_set_universe(isl_space_params(isl_space_copy(space))); + dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); + mpa = isl_multi_pw_aff_zero(space); + mpa = isl_multi_pw_aff_intersect_domain(mpa, dom); + r = check_reparse_multi_pw_aff(ctx, mpa); + if (r < 0) + return -1; + + map = isl_map_read_from_str(ctx, "{ [a, a] -> [i1 = a + 1] }"); + pma = isl_pw_multi_aff_from_map(map); + mpa = isl_multi_pw_aff_from_pw_multi_aff(pma); + if (check_reparse_multi_pw_aff(ctx, mpa) < 0) + return -1; + + if (check_reparse_multi_pw_aff_tests(ctx) < 0) + return -1; + + return 0; +} + +/* String descriptions of multi union piecewise affine expressions + * that are used for testing printing and parsing. + */ +static const char *reparse_multi_union_pw_aff_tests[] = { + "[]", + "A[]", + "A[B[] -> C[]]", + "(A[] : { S[x] : x > 0; T[y] : y >= 0 })", + "(A[] : { })", + "[N] -> (A[] : { })", + "[N] -> (A[] : { : N >= 0 })", + "[N] -> (A[] : { S[x] : x > N; T[y] : y >= 0 })", + "(A[] : [N] -> { S[x] : x > N; T[y] : y >= 0 })", + "A[{ S[x] -> [x + 1]; T[x] -> [x] }]", + "(A[{ S[x] -> [x + 1]; T[x] -> [x] }] : " + "{ S[x] : x > 0; T[y] : y >= 0 })", +}; + +#undef BASE +#define BASE multi_union_pw_aff + +#include "check_reparse_templ.c" +#include "check_reparse_test_templ.c" + +/* Test parsing of multi union piecewise affine expressions by printing + * the expressions and checking that parsing the output results + * in the same expression. + * Do this for a couple of manually constructed expressions and + * a set of expressions parsed from strings. + */ +static int test_parse_mupa(isl_ctx *ctx) +{ + isl_space *space; + isl_multi_union_pw_aff *mupa; + isl_set *dom; + isl_union_set *uset; + isl_stat r; + + space = isl_space_set_alloc(ctx, 0, 0); + space = isl_space_set_tuple_name(space, isl_dim_set, "A"); + mupa = isl_multi_union_pw_aff_zero(space); + r = check_reparse_multi_union_pw_aff(ctx, mupa); + if (r < 0) + return -1; + + space = isl_space_set_alloc(ctx, 1, 0); + space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); + space = isl_space_set_tuple_name(space, isl_dim_set, "A"); + dom = isl_set_universe(space); + dom = isl_set_lower_bound_si(dom, isl_dim_param, 0, 5); + uset = isl_union_set_from_set(dom); + space = isl_space_set_alloc(ctx, 1, 0); + space = isl_space_set_dim_name(space, isl_dim_param, 0, "N"); + space = isl_space_set_tuple_name(space, isl_dim_set, "B"); + mupa = isl_multi_union_pw_aff_zero(space); + mupa = isl_multi_union_pw_aff_intersect_domain(mupa, uset); + r = check_reparse_multi_union_pw_aff(ctx, mupa); + if (r < 0) + return -1; + + if (check_reparse_multi_union_pw_aff_tests(ctx) < 0) + return -1; + + return 0; +} + +/* Test parsing of multi expressions. + */ +static int test_parse_multi(isl_ctx *ctx) +{ + if (test_parse_mpa(ctx) < 0) + return -1; + if (test_parse_mupa(ctx) < 0) + return -1; + + return 0; +} + /* Pairs of binary relation representations that should represent * the same binary relations. */ @@ -192,6 +382,12 @@ "{ [x] -> [] : 0 <= x <= 15 }" }, { "{ [x] -> [x] : }", "{ [x] -> [x] }" }, + { "{ [x=4:5] -> [x + 1] }", + "{ [x] -> [x + 1] : 4 <= x <= 5 }" }, + { "{ [x=4:5] -> [x + 1 : x + 1] }", + "{ [x=4:5] -> [x + 1] }" }, + { "{ [x] -> [x - 1 : x + 1] }", + "{ [x] -> [y] : x - 1 <= y <= x + 1 }" }, }; int test_parse(struct isl_ctx *ctx) @@ -205,6 +401,10 @@ if (test_parse_multi_val(ctx, "[n] -> { [2] }") < 0) return -1; if (test_parse_multi_val(ctx, "{ A[4, infty, NaN, -1/2, 2/3] }") < 0) + return -1; + if (test_parse_multi(ctx) < 0) + return -1; + if (test_parse_pma(ctx) < 0) return -1; str = "{ [i] -> [-i] }"; @@ -443,6 +643,36 @@ "unexpected result", return -1); return 0; +} + +/* Check that "val" is equal to the value described by "str". + * If "str" is "NaN", then check for a NaN value explicitly. + */ +static isl_stat val_check_equal(__isl_keep isl_val *val, const char *str) +{ + isl_bool ok, is_nan; + isl_ctx *ctx; + isl_val *res; + + if (!val) + return isl_stat_error; + + ctx = isl_val_get_ctx(val); + res = isl_val_read_from_str(ctx, str); + is_nan = isl_val_is_nan(res); + if (is_nan < 0) + ok = isl_bool_error; + else if (is_nan) + ok = isl_val_is_nan(val); + else + ok = isl_val_eq(val, res); + isl_val_free(res); + if (ok < 0) + return isl_stat_error; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return isl_stat_error); + return isl_stat_ok; } struct { @@ -452,7 +682,7 @@ } val_un_tests[] = { { &isl_val_neg, "0", "0" }, { &isl_val_abs, "0", "0" }, - { &isl_val_2exp, "0", "1" }, + { &isl_val_pow2, "0", "1" }, { &isl_val_floor, "0", "0" }, { &isl_val_ceil, "0", "0" }, { &isl_val_neg, "1", "-1" }, @@ -483,11 +713,11 @@ { &isl_val_ceil, "infty", "infty" }, { &isl_val_ceil, "-infty", "-infty" }, { &isl_val_ceil, "NaN", "NaN" }, - { &isl_val_2exp, "-3", "1/8" }, - { &isl_val_2exp, "-1", "1/2" }, - { &isl_val_2exp, "1", "2" }, - { &isl_val_2exp, "2", "4" }, - { &isl_val_2exp, "3", "8" }, + { &isl_val_pow2, "-3", "1/8" }, + { &isl_val_pow2, "-1", "1/2" }, + { &isl_val_pow2, "1", "2" }, + { &isl_val_pow2, "2", "4" }, + { &isl_val_pow2, "3", "8" }, { &isl_val_inv, "1", "1" }, { &isl_val_inv, "2", "1/2" }, { &isl_val_inv, "1/2", "2" }, @@ -504,29 +734,19 @@ static int test_un_val(isl_ctx *ctx) { int i; - isl_val *v, *res; + isl_val *v; __isl_give isl_val *(*fn)(__isl_take isl_val *v); - isl_bool ok, is_nan; for (i = 0; i < ARRAY_SIZE(val_un_tests); ++i) { + isl_stat r; + v = isl_val_read_from_str(ctx, val_un_tests[i].arg); - res = isl_val_read_from_str(ctx, val_un_tests[i].res); fn = val_un_tests[i].op; v = fn(v); - is_nan = isl_val_is_nan(res); - if (is_nan < 0) - ok = isl_bool_error; - else if (is_nan) - ok = isl_val_is_nan(v); - else - ok = isl_val_eq(v, res); + r = val_check_equal(v, val_un_tests[i].res); isl_val_free(v); - isl_val_free(res); - if (ok < 0) + if (r < 0) return -1; - if (!ok) - isl_die(ctx, isl_error_unknown, - "unexpected result", return -1); } return 0; @@ -687,14 +907,14 @@ static int test_elimination(isl_ctx *ctx) { int i; - unsigned n; + isl_size n; isl_basic_set *bset; for (i = 0; i < ARRAY_SIZE(elimination_tests); ++i) { bset = isl_basic_set_read_from_str(ctx, elimination_tests[i]); n = isl_basic_set_dim(bset, isl_dim_div); isl_basic_set_free(bset); - if (!bset) + if (n < 0) return -1; if (n != 0) isl_die(ctx, isl_error_unknown, @@ -1033,6 +1253,49 @@ free(filename); fclose(input); +} + +/* Pairs of sets and the corresponding expected results of + * isl_basic_set_recession_cone. + */ +struct { + const char *set; + const char *cone; +} recession_cone_tests[] = { + { "{ [i] : 0 <= i <= 10 }", "{ [0] }" }, + { "{ [i] : 0 <= i }", "{ [i] : 0 <= i }" }, + { "{ [i] : i <= 10 }", "{ [i] : i <= 0 }" }, + { "{ [i] : false }", "{ [i] : false }" }, +}; + +/* Perform some basic isl_basic_set_recession_cone tests. + */ +static int test_recession_cone(struct isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(recession_cone_tests); ++i) { + const char *str; + isl_basic_set *bset; + isl_basic_set *cone, *expected; + isl_bool equal; + + str = recession_cone_tests[i].set; + bset = isl_basic_set_read_from_str(ctx, str); + str = recession_cone_tests[i].cone; + expected = isl_basic_set_read_from_str(ctx, str); + cone = isl_basic_set_recession_cone(bset); + equal = isl_basic_set_is_equal(cone, expected); + isl_basic_set_free(cone); + isl_basic_set_free(expected); + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, "unexpected cone", + return -1); + } + + return 0; } int test_affine_hull(struct isl_ctx *ctx) @@ -1040,8 +1303,8 @@ const char *str; isl_set *set; isl_basic_set *bset, *bset2; - int n; - int subset; + isl_size n; + isl_bool subset; test_affine_hull_case(ctx, "affine2"); test_affine_hull_case(ctx, "affine"); @@ -1055,6 +1318,8 @@ bset = isl_set_affine_hull(set); n = isl_basic_set_dim(bset, isl_dim_div); isl_basic_set_free(bset); + if (n < 0) + return -1; if (n != 0) isl_die(ctx, isl_error_unknown, "not expecting any divs", return -1); @@ -1249,6 +1514,11 @@ { "{ [x, y, z] : 0 <= x, y, z <= 10; [x, y, 0] : x >= 0 and y > 0; " "[x, y, 0] : x >= 0 and y < 0 }", "{ [x, y, z] : x >= 0 and 0 <= z <= 10 }" }, + { "{ [a, b, c] : a <= 1 and -a < b <= 1 and 0 <= c <= 2 - a - b and " + "c <= a; " + "[0, 2, 0]; [3, 1, 0] }", + "{ [a, b, c] : b > -a and 2b >= -1 + a and 0 <= c <= a and " + "5c <= 6 - a - 3b }" }, }; static int test_convex_hull_algo(isl_ctx *ctx, int convex) @@ -1380,6 +1650,49 @@ } return 0; +} + +/* Inputs for isl_basic_set_gist tests that are expected to fail. + */ +struct { + const char *set; + const char *context; +} gist_fail_tests[] = { + { "{ [i] : exists (e0, e1: 3e1 >= 1 + 2e0 and " + "8e1 <= -1 + 5i - 5e0 and 2e1 >= 1 + 2i - 5e0) }", + "{ [i] : i >= 0 }" }, +}; + +/* Check that isl_basic_set_gist fails (gracefully) when expected. + * In particular, the user should be able to recover from the failure. + */ +static isl_stat test_gist_fail(struct isl_ctx *ctx) +{ + int i, n; + int on_error; + + on_error = isl_options_get_on_error(ctx); + isl_options_set_on_error(ctx, ISL_ON_ERROR_CONTINUE); + n = ARRAY_SIZE(gist_fail_tests); + for (i = 0; i < n; ++i) { + const char *str; + isl_basic_set *bset, *context; + + bset = isl_basic_set_read_from_str(ctx, gist_fail_tests[i].set); + str = gist_fail_tests[i].context; + context = isl_basic_set_read_from_str(ctx, str); + bset = isl_basic_set_gist(bset, context); + isl_basic_set_free(bset); + if (bset) + break; + } + isl_options_set_on_error(ctx, on_error); + if (i < n) + isl_die(ctx, isl_error_unknown, + "operation not expected to succeed", + return isl_stat_error); + + return isl_stat_ok; } struct { @@ -1473,10 +1786,11 @@ const char *str; isl_basic_set *bset1, *bset2; isl_map *map1, *map2; - int equal; + isl_bool equal; + isl_size n_div; for (i = 0; i < ARRAY_SIZE(gist_tests); ++i) { - int equal_input, equal_intersection; + isl_bool equal_input, equal_intersection; isl_set *set1, *set2, *copy, *context; set1 = isl_set_read_from_str(ctx, gist_tests[i].set); @@ -1506,6 +1820,9 @@ isl_die(ctx, isl_error_unknown, "inconsistent gist test case", return -1); } + + if (test_gist_fail(ctx) < 0) + return -1; test_gist_case(ctx, "gist1"); @@ -1550,11 +1867,14 @@ return -1; if (map1->n != 1) isl_die(ctx, isl_error_unknown, "expecting single disjunct", - isl_map_free(map1); return -1); - if (isl_basic_map_dim(map1->p[0], isl_dim_div) != 1) - isl_die(ctx, isl_error_unknown, "expecting single div", isl_map_free(map1); return -1); + n_div = isl_basic_map_dim(map1->p[0], isl_dim_div); isl_map_free(map1); + if (n_div < 0) + return -1; + if (n_div != 1) + isl_die(ctx, isl_error_unknown, "expecting single div", + return -1); if (test_plain_gist(ctx) < 0) return -1; @@ -1606,6 +1926,8 @@ { 1, "{ [x,0,0] : -5 <= x <= 5; [0,y,1] : -5 <= y <= 5 }" }, { 1, "{ [x,y] : 0 <= x <= 10 and 0 >= y >= -1 and x+y >= 0; [0,1] }" }, { 1, "{ [x,y] : (0 <= x,y <= 4) or (2 <= x,y <= 5 and x + y <= 9) }" }, + { 0, "{ [x, y, z] : 0 <= x,y,z <= 100 and 0 < z <= 2 + 2x + 2y; " + "[x, y, 0] : x,y <= 100 and y <= 9 + 11x and x <= 9 + 11y }" }, }; /* Test the functionality of isl_set_coalesce with the bounded wrapping @@ -1891,6 +2213,14 @@ { 0, "{ [a, b] : a >= 0 and 0 <= b <= 1 - a; [-1, 3] }" }, { 1, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [1, 1] }" }, { 0, "{ [a, b] : a, b >= 0 and a + 2b <= 2; [2, 1] }" }, + { 0, "{ [a, c] : (2 + a) mod 4 = 0 or " + "(c = 4 + a and 4 * floor((a)/4) = a and a >= 0 and a <= 4) or " + "(c = 3 + a and 4 * floor((-1 + a)/4) = -1 + a and " + "a > 0 and a <= 5) }" }, + { 1, "{ [1, 0, 0]; [a, b, c] : -1 <= -a < b <= 0 and 2c > b }" }, + { 0, "{ [j, a, l] : a mod 2 = 0 and j <= 29 and a >= 2 and " + "2a <= -5 + j and 32j + 2a + 2 <= 4l < 33j; " + "[j, 0, l] : 4 <= j <= 29 and -3 + 33j <= 4l <= 33j }" }, }; /* A specialized coalescing test case that would result @@ -1994,6 +2324,77 @@ return -1; return 0; +} + +/* Check that calling isl_set_coalesce on the intersection of + * the sets described by "s1" and "s2" does not leave other sets + * that may share some information with the input to isl_set_coalesce + * in an inconsistent state. + * In particular, when isl_set_coalesce detects equality constraints, + * it does not immediately perform Gaussian elimination on them, + * but then it needs to ensure that it is performed at some point. + * The input set has implicit equality constraints in the first disjunct. + * It is constructed as an intersection, because otherwise + * those equality constraints would already be detected during parsing. + */ +static isl_stat test_coalesce_intersection(isl_ctx *ctx, + const char *s1, const char *s2) +{ + isl_set *set1, *set2; + + set1 = isl_set_read_from_str(ctx, s1); + set2 = isl_set_read_from_str(ctx, s2); + set1 = isl_set_intersect(set1, set2); + isl_set_free(isl_set_coalesce(isl_set_copy(set1))); + set1 = isl_set_coalesce(set1); + isl_set_free(set1); + + if (!set1) + return isl_stat_error; + + return isl_stat_ok; +} + +/* Check that calling isl_set_coalesce does not leave other sets + * that may share some information with the input to isl_set_coalesce + * in an inconsistent state, for the case where one disjunct + * is a subset of the other. + */ +static isl_stat test_coalesce_special4(isl_ctx *ctx) +{ + const char *s1, *s2; + + s1 = "{ [a, b] : b <= 0 or a <= 1 }"; + s2 = "{ [a, b] : -1 <= -a < b }"; + return test_coalesce_intersection(ctx, s1, s2); +} + +/* Check that calling isl_set_coalesce does not leave other sets + * that may share some information with the input to isl_set_coalesce + * in an inconsistent state, for the case where two disjuncts + * can be fused. + */ +static isl_stat test_coalesce_special5(isl_ctx *ctx) +{ + const char *s1, *s2; + + s1 = "{ [a, b, c] : b <= 0 }"; + s2 = "{ [a, b, c] : -1 <= -a < b and (c >= 0 or c < 0) }"; + return test_coalesce_intersection(ctx, s1, s2); +} + +/* Check that calling isl_set_coalesce does not leave other sets + * that may share some information with the input to isl_set_coalesce + * in an inconsistent state, for the case where two disjuncts + * can be fused and where both disjuncts have implicit equality constraints. + */ +static isl_stat test_coalesce_special6(isl_ctx *ctx) +{ + const char *s1, *s2; + + s1 = "{ [a, b, c] : c <= 0 }"; + s2 = "{ [a, b, c] : 0 <= a <= b <= c or (0 <= b <= c and a > 0) }"; + return test_coalesce_intersection(ctx, s1, s2); } /* Test the functionality of isl_set_coalesce. @@ -2018,7 +2419,14 @@ if (test_coalesce_special2(ctx) < 0) return -1; if (test_coalesce_special3(ctx) < 0) + return -1; + if (test_coalesce_special4(ctx) < 0) + return -1; + if (test_coalesce_special5(ctx) < 0) return -1; + if (test_coalesce_special6(ctx) < 0) + return -1; + return 0; } @@ -2071,7 +2479,7 @@ { const char *str; isl_map *map, *map2; - int exact, equal; + isl_bool exact, equal; /* COCOA example 1 */ map = isl_map_read_from_str(ctx, @@ -2301,6 +2709,46 @@ map = isl_map_transitive_closure(map, NULL); assert(map); isl_map_free(map); + + return 0; +} + +/* Check that the actual result of a boolean operation is equal + * to the expected result. + */ +static isl_stat check_bool(isl_ctx *ctx, isl_bool actual, isl_bool expected) +{ + if (actual != expected) + isl_die(ctx, isl_error_unknown, + "incorrect boolean operation", return isl_stat_error); + return isl_stat_ok; +} + +/* Test operations on isl_bool values. + * + * This tests: + * + * isl_bool_not + * isl_bool_ok + */ +static int test_isl_bool(isl_ctx *ctx) +{ + if (check_bool(ctx, isl_bool_not(isl_bool_true), isl_bool_false) < 0) + return -1; + if (check_bool(ctx, isl_bool_not(isl_bool_false), isl_bool_true) < 0) + return -1; + if (check_bool(ctx, isl_bool_not(isl_bool_error), isl_bool_error) < 0) + return -1; + if (check_bool(ctx, isl_bool_ok(0), isl_bool_false) < 0) + return -1; + if (check_bool(ctx, isl_bool_ok(1), isl_bool_true) < 0) + return -1; + if (check_bool(ctx, isl_bool_ok(-1), isl_bool_true) < 0) + return -1; + if (check_bool(ctx, isl_bool_ok(2), isl_bool_true) < 0) + return -1; + if (check_bool(ctx, isl_bool_ok(-2), isl_bool_true) < 0) + return -1; return 0; } @@ -2399,6 +2847,8 @@ map = isl_map_read_from_str(ctx, str); map = isl_map_lexmin(map); isl_map_free(map); + if (!map) + return -1; str = "[C] -> { [obj,a,b,c] : obj <= 38 a + 7 b + 10 c and " "a + b <= 1 and c <= 10 b and c <= C and a,b,c,C >= 0 }"; @@ -2622,35 +3072,100 @@ return 0; } -static int test_dep(struct isl_ctx *ctx) +/* Is "set" equal to the set described by "str"? + */ +static isl_bool set_is_equal(__isl_keep isl_set *set, const char *str) { - const char *str; - isl_space *dim; - isl_map *map; - isl_access_info *ai; - isl_flow *flow; - int depth; - struct must_may mm; - - depth = 3; + isl_set *set2; + isl_bool equal; - str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; - map = isl_map_read_from_str(ctx, str); - ai = isl_access_info_alloc(map, &depth, &common_space, 2); + if (!set) + return isl_bool_error; - str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; - map = isl_map_read_from_str(ctx, str); - ai = isl_access_info_add_source(ai, map, 1, &depth); + set2 = isl_set_read_from_str(isl_set_get_ctx(set), str); + equal = isl_set_is_equal(set, set2); + isl_set_free(set2); - str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; - map = isl_map_read_from_str(ctx, str); - ai = isl_access_info_add_source(ai, map, 1, &depth); + return equal; +} - flow = isl_access_info_compute_flow(ai); - dim = isl_space_alloc(ctx, 0, 3, 3); - mm.must = isl_map_empty(isl_space_copy(dim)); - mm.may = isl_map_empty(dim); +/* Check that "set" is equal to the set described by "str". + */ +static isl_stat set_check_equal(__isl_keep isl_set *set, const char *str) +{ + isl_bool equal; + equal = set_is_equal(set, str); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(isl_set_get_ctx(set), isl_error_unknown, + "result not as expected", return isl_stat_error); + return isl_stat_ok; +} + +/* Is "uset" equal to the union set described by "str"? + */ +static isl_bool uset_is_equal(__isl_keep isl_union_set *uset, const char *str) +{ + isl_union_set *uset2; + isl_bool equal; + + if (!uset) + return isl_bool_error; + + uset2 = isl_union_set_read_from_str(isl_union_set_get_ctx(uset), str); + equal = isl_union_set_is_equal(uset, uset2); + isl_union_set_free(uset2); + + return equal; +} + +/* Check that "uset" is equal to the union set described by "str". + */ +static isl_stat uset_check_equal(__isl_keep isl_union_set *uset, + const char *str) +{ + isl_bool equal; + + equal = uset_is_equal(uset, str); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(isl_union_set_get_ctx(uset), isl_error_unknown, + "result not as expected", return isl_stat_error); + return isl_stat_ok; +} + +static int test_dep(struct isl_ctx *ctx) +{ + const char *str; + isl_space *dim; + isl_map *map; + isl_access_info *ai; + isl_flow *flow; + int depth; + struct must_may mm; + + depth = 3; + + str = "{ [2,i,0] -> [i] : 0 <= i <= 10 }"; + map = isl_map_read_from_str(ctx, str); + ai = isl_access_info_alloc(map, &depth, &common_space, 2); + + str = "{ [0,i,0] -> [i] : 0 <= i <= 10 }"; + map = isl_map_read_from_str(ctx, str); + ai = isl_access_info_add_source(ai, map, 1, &depth); + + str = "{ [1,i,0] -> [5] : 0 <= i <= 10 }"; + map = isl_map_read_from_str(ctx, str); + ai = isl_access_info_add_source(ai, map, 1, &depth); + + flow = isl_access_info_compute_flow(ai); + dim = isl_space_alloc(ctx, 0, 3, 3); + mm.must = isl_map_empty(isl_space_copy(dim)); + mm.may = isl_map_empty(dim); + isl_flow_foreach(flow, collect_must_may, &mm); str = "{ [0,i,0] -> [2,i,0] : (0 <= i <= 4) or (6 <= i <= 10); " @@ -3135,7 +3650,7 @@ static int test_bound(isl_ctx *ctx) { const char *str; - unsigned dim; + isl_size dim; isl_pw_qpolynomial *pwqp; isl_pw_qpolynomial_fold *pwf; @@ -3147,6 +3662,8 @@ pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL); dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); isl_pw_qpolynomial_fold_free(pwf); + if (dim < 0) + return -1; if (dim != 4) isl_die(ctx, isl_error_unknown, "unexpected input dimension", return -1); @@ -3156,9 +3673,64 @@ pwf = isl_pw_qpolynomial_bound(pwqp, isl_fold_max, NULL); dim = isl_pw_qpolynomial_fold_dim(pwf, isl_dim_in); isl_pw_qpolynomial_fold_free(pwf); + if (dim < 0) + return -1; if (dim != 1) isl_die(ctx, isl_error_unknown, "unexpected input dimension", return -1); + + return 0; +} + +/* isl_set is defined to isl_map internally, so the corresponding elements + * are isl_basic_map objects. + */ +#undef EL_BASE +#undef SET_BASE +#define EL_BASE basic_map +#define SET_BASE set +#include "isl_test_list_templ.c" + +#undef EL_BASE +#undef SET_BASE +#define EL_BASE basic_set +#define SET_BASE union_set +#include "isl_test_list_templ.c" + +#undef EL_BASE +#undef SET_BASE +#define EL_BASE set +#define SET_BASE union_set +#include "isl_test_list_templ.c" + +#undef EL_BASE +#undef SET_BASE +#define EL_BASE basic_map +#define SET_BASE map +#include "isl_test_list_templ.c" + +#undef EL_BASE +#undef SET_BASE +#define EL_BASE map +#define SET_BASE union_map +#include "isl_test_list_templ.c" + +/* Check that the conversion from isl objects to lists works as expected. + */ +static int test_get_list(isl_ctx *ctx) +{ + if (test_get_list_basic_map_from_set(ctx, "{ [0]; [2]; [3] }")) + return -1; + if (test_get_list_basic_set_from_union_set(ctx, "{ A[0]; B[2]; B[3] }")) + return -1; + if (test_get_list_set_from_union_set(ctx, "{ A[0]; A[2]; B[3] }")) + return -1; + if (test_get_list_basic_map_from_map(ctx, + "{ [0] -> [0]; [2] -> [0]; [3] -> [0] }")) + return -1; + if (test_get_list_map_from_union_map(ctx, + "{ A[0] -> [0]; A[2] -> [0]; B[3] -> [0] }")) + return -1; return 0; } @@ -3177,6 +3749,44 @@ isl_basic_set_free(bset); return 0; +} + +/* Check that isl_set_is_subset is not confused by identical + * integer divisions. + * The call to isl_set_normalize ensures that the equality constraints + * a = b = 0 are discovered, turning e0 and e1 into identical + * integer divisions. Any further simplification would remove + * the duplicate integer divisions. + */ +static isl_stat test_subset_duplicate_integer_divisions(isl_ctx *ctx) +{ + const char *str; + isl_bool is_subset; + isl_set *set1, *set2; + + str = "{ [a, b, c, d] : " + "exists (e0 = floor((a + d)/4), e1 = floor((d)/4), " + "e2 = floor((-a - d + 4 *floor((a + d)/4))/10), " + "e3 = floor((-d + 4*floor((d)/4))/10): " + "10e2 = -a - 2c - d + 4e0 and 10e3 = -2c - d + 4e1 and " + "b >= 0 and a <= 0 and b <= a) }"; + set1 = isl_set_read_from_str(ctx, str); + set2 = isl_set_read_from_str(ctx, str); + set2 = isl_set_normalize(set2); + + is_subset = isl_set_is_subset(set1, set2); + + isl_set_free(set1); + isl_set_free(set2); + + if (is_subset < 0) + return isl_stat_error; + if (!is_subset) + isl_die(ctx, isl_error_unknown, + "set is not considered to be a subset of itself", + return isl_stat_error); + + return isl_stat_ok; } struct { @@ -3222,6 +3832,9 @@ int i; isl_set *set1, *set2; int subset; + + if (test_subset_duplicate_integer_divisions(ctx) < 0) + return -1; for (i = 0; i < ARRAY_SIZE(subset_tests); ++i) { set1 = isl_set_read_from_str(ctx, subset_tests[i].set1); @@ -3300,9 +3913,9 @@ * does not increase the number of constraints. In particular, * the empty basic set should maintain its canonical representation. */ -static int test_intersect(isl_ctx *ctx) +static int test_intersect_1(isl_ctx *ctx) { - int n1, n2; + isl_size n1, n2; isl_basic_set *bset1, *bset2; bset1 = isl_basic_set_read_from_str(ctx, "{ [a,b,c] : 1 = 0 }"); @@ -3311,12 +3924,41 @@ bset1 = isl_basic_set_intersect(bset1, bset2); n2 = isl_basic_set_n_constraint(bset1); isl_basic_set_free(bset1); - if (!bset1) + if (n1 < 0 || n2 < 0) return -1; if (n1 != n2) isl_die(ctx, isl_error_unknown, "number of constraints of empty set changed", return -1); + + return 0; +} + +/* Check that intersecting a set with itself does not cause + * an explosion in the number of disjuncts. + */ +static isl_stat test_intersect_2(isl_ctx *ctx) +{ + int i; + isl_set *set; + + set = isl_set_read_from_str(ctx, "{ [x,y] : x >= 0 or y >= 0 }"); + for (i = 0; i < 100; ++i) + set = isl_set_intersect(set, isl_set_copy(set)); + isl_set_free(set); + if (!set) + return isl_stat_error; + return isl_stat_ok; +} + +/* Perform some intersection tests. + */ +static int test_intersect(isl_ctx *ctx) +{ + if (test_intersect_1(ctx) < 0) + return -1; + if (test_intersect_2(ctx) < 0) + return -1; return 0; } @@ -3395,6 +4037,7 @@ isl_schedule_constraints *sc; isl_schedule *sched; int is_nonneg, is_parallel, is_tilable, is_injection, is_complete; + isl_size n; D = isl_union_set_read_from_str(ctx, d); W = isl_union_map_read_from_str(ctx, w); @@ -3445,12 +4088,19 @@ test = isl_union_map_apply_range(test, schedule); delta = isl_union_map_deltas(test); - if (isl_union_set_n_set(delta) == 0) { + n = isl_union_set_n_set(delta); + if (n < 0) { + isl_union_set_free(delta); + return -1; + } + if (n == 0) { is_tilable = 1; is_parallel = 1; is_nonneg = 1; isl_union_set_free(delta); } else { + isl_size dim; + delta_set = isl_set_from_union_set(delta); slice = isl_set_universe(isl_set_get_space(delta_set)); @@ -3466,7 +4116,10 @@ isl_set_free(slice); origin = isl_set_universe(isl_set_get_space(delta_set)); - for (i = 0; i < isl_set_dim(origin, isl_dim_set); ++i) + dim = isl_set_dim(origin, isl_dim_set); + if (dim < 0) + origin = isl_set_free(origin); + for (i = 0; i < dim; ++i) origin = isl_set_fix_si(origin, isl_dim_set, i, 0); delta_set = isl_set_union(delta_set, isl_set_copy(origin)); @@ -3844,7 +4497,7 @@ isl_schedule_constraints *sc; isl_schedule *schedule; isl_schedule_node *node; - int n_member; + isl_size n_member; if (test_special_conditional_schedule_constraints(ctx) < 0) return -1; @@ -3875,7 +4528,7 @@ isl_schedule_node_free(node); isl_schedule_free(schedule); - if (!schedule) + if (!schedule || n_member < 0) return -1; if (n_member != live_range_tests[i].outer_band_n) isl_die(ctx, isl_error_unknown, @@ -3938,110 +4591,7 @@ isl_union_map_free(schedule); if (!schedule) - return -1; - - return 0; -} - -/* Check that the dependence carrying step is not confused by - * a bound on the coefficient size. - * In particular, force the scheduler to move to a dependence carrying - * step by demanding outer coincidence and bound the size of - * the coefficients. Earlier versions of isl would take this - * bound into account while carrying dependences, breaking - * fundamental assumptions. - * On the other hand, the dependence carrying step now tries - * to prevent loop coalescing by default, so check that indeed - * no loop coalescing occurs by comparing the computed schedule - * to the expected non-coalescing schedule. - */ -static int test_bounded_coefficients_schedule(isl_ctx *ctx) -{ - const char *domain, *dep; - isl_union_set *I; - isl_union_map *D; - isl_schedule_constraints *sc; - isl_schedule *schedule; - isl_union_map *sched1, *sched2; - isl_bool equal; - - domain = "{ C[i0, i1] : 2 <= i0 <= 3999 and 0 <= i1 <= -1 + i0 }"; - dep = "{ C[i0, i1] -> C[i0, 1 + i1] : i0 <= 3999 and i1 >= 0 and " - "i1 <= -2 + i0; " - "C[i0, -1 + i0] -> C[1 + i0, 0] : i0 <= 3998 and i0 >= 1 }"; - I = isl_union_set_read_from_str(ctx, domain); - D = isl_union_map_read_from_str(ctx, dep); - sc = isl_schedule_constraints_on_domain(I); - sc = isl_schedule_constraints_set_validity(sc, isl_union_map_copy(D)); - sc = isl_schedule_constraints_set_coincidence(sc, D); - isl_options_set_schedule_outer_coincidence(ctx, 1); - isl_options_set_schedule_max_coefficient(ctx, 20); - schedule = isl_schedule_constraints_compute_schedule(sc); - isl_options_set_schedule_max_coefficient(ctx, -1); - isl_options_set_schedule_outer_coincidence(ctx, 0); - sched1 = isl_schedule_get_map(schedule); - isl_schedule_free(schedule); - - sched2 = isl_union_map_read_from_str(ctx, "{ C[x,y] -> [x,y] }"); - equal = isl_union_map_is_equal(sched1, sched2); - isl_union_map_free(sched1); - isl_union_map_free(sched2); - - if (equal < 0) - return -1; - if (!equal) - isl_die(ctx, isl_error_unknown, - "unexpected schedule", return -1); - - return 0; -} - -/* Check that the bounds on the coefficients are respected. - * This function checks for a particular output schedule, - * but the exact output is not important, only that it does - * not contain any coefficients greater than 4. - * It is, however, easier to check for a particular output. - * This test is only run for the whole component scheduler - * because the incremental scheduler produces a slightly different schedule. - */ -static int test_bounded_coefficients_schedule_whole(isl_ctx *ctx) -{ - const char *domain, *dep, *str; - isl_union_set *I; - isl_union_map *D; - isl_schedule_constraints *sc; - isl_schedule *schedule; - isl_union_map *sched1, *sched2; - isl_bool equal; - - domain = "{ S_4[i, j, k] : 0 <= i < j <= 10 and 0 <= k <= 100; " - "S_2[i, j] : 0 <= i < j <= 10; S_6[i, j] : 0 <= i < j <= 10 }"; - dep = "{ S_2[0, j] -> S_4[0, j, 0] : 0 < j <= 10; " - "S_4[0, j, 100] -> S_6[0, j] : 0 < j <= 10 }"; - I = isl_union_set_read_from_str(ctx, domain); - D = isl_union_map_read_from_str(ctx, dep); - sc = isl_schedule_constraints_on_domain(I); - sc = isl_schedule_constraints_set_validity(sc, D); - isl_options_set_schedule_max_constant_term(ctx, 10); - isl_options_set_schedule_max_coefficient(ctx, 4); - schedule = isl_schedule_constraints_compute_schedule(sc); - isl_options_set_schedule_max_coefficient(ctx, -1); - isl_options_set_schedule_max_constant_term(ctx, -1); - sched1 = isl_schedule_get_map(schedule); - isl_schedule_free(schedule); - - str = "{ S_4[i, j, k] -> [i, j, 10 - k]; " - "S_2[i, j] -> [0, i, j]; S_6[i, j] -> [0, 10 + i, j] }"; - sched2 = isl_union_map_read_from_str(ctx, str); - equal = isl_union_map_is_equal(sched1, sched2); - isl_union_map_free(sched1); - isl_union_map_free(sched2); - - if (equal < 0) return -1; - if (!equal) - isl_die(ctx, isl_error_unknown, - "unexpected schedule", return -1); return 0; } @@ -4401,8 +4951,6 @@ if (test_conflicting_context_schedule(ctx) < 0) return -1; - if (test_bounded_coefficients_schedule(ctx) < 0) - return -1; if (test_coalescing_schedule(ctx) < 0) return -1; if (test_skewing_schedule(ctx) < 0) @@ -4421,8 +4969,6 @@ whole = isl_options_get_schedule_whole_component(ctx); isl_options_set_schedule_whole_component(ctx, 1); r = test_schedule(ctx); - if (r >= 0) - r = test_bounded_coefficients_schedule_whole(ctx); isl_options_set_schedule_whole_component(ctx, whole); return r; @@ -4518,6 +5064,43 @@ return -1; if (!equal) isl_die(isl_aff_get_ctx(aff), isl_error_unknown, + "result not as expected", return -1); + return 0; +} + +/* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"? + */ +static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma, + const char *str) +{ + isl_ctx *ctx; + isl_pw_multi_aff *pma2; + int equal; + + if (!pma) + return -1; + + ctx = isl_pw_multi_aff_get_ctx(pma); + pma2 = isl_pw_multi_aff_read_from_str(ctx, str); + equal = isl_pw_multi_aff_plain_is_equal(pma, pma2); + isl_pw_multi_aff_free(pma2); + + return equal; +} + +/* Check that "pma" is obviously equal to the isl_pw_multi_aff + * represented by "str". + */ +static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma, + const char *str) +{ + int equal; + + equal = pw_multi_aff_plain_is_equal(pma, str); + if (equal < 0) + return -1; + if (!equal) + isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown, "result not as expected", return -1); return 0; } @@ -4843,45 +5426,134 @@ } /* Inputs for basic tests of binary operations on - * pairs of isl_multi_union_pw_aff and isl_union_set objects. - * "fn" is the function that is tested. + * pairs of isl_union_pw_multi_aff and isl_union_set objects. + * "fn" is the function that is being tested. * "arg1" and "arg2" are string descriptions of the inputs. * "res" is a string description of the expected result. */ struct { - __isl_give isl_multi_union_pw_aff *(*fn)( - __isl_take isl_multi_union_pw_aff *mupa, + __isl_give isl_union_pw_multi_aff *(*fn)( + __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_union_set *uset); const char *arg1; const char *arg2; const char *res; -} mupa_uset_tests[] = { - { &isl_multi_union_pw_aff_intersect_domain, - "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }", - "C[{ B[i,i] -> [3i] }]" }, +} upma_uset_tests[] = { + { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, + "{ A[i] -> B[i] }", "{ B[0] }", + "{ }" }, + { &isl_union_pw_multi_aff_intersect_domain_wrapped_domain, + "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }", + "{ [A[1] -> B[1]] -> C[2] }" }, + { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, + "{ [A[i] -> B[i]] -> C[i + 1] }", "{ A[1]; B[0] }", + "{ [A[0] -> B[0]] -> C[1] }" }, + { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, + "{ [A[i] -> B[i]] -> C[i + 1] }", "[N] -> { B[N] }", + "[N] -> { [A[N] -> B[N]] -> C[N + 1] }" }, + { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, + "[M] -> { [A[M] -> B[M]] -> C[M + 1] }", "[N] -> { B[N] }", + "[N, M] -> { [A[N] -> B[N]] -> C[N + 1] : N = M }" }, + { &isl_union_pw_multi_aff_intersect_domain_wrapped_range, + "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[]; [B[] -> A[]] -> E[] }", + "{ B[] }", + "{ [A[] -> B[]] -> C[]; N[A[] -> B[]] -> D[] }" }, }; /* Perform some basic tests of binary operations on - * pairs of isl_multi_union_pw_aff and isl_union_set objects. + * pairs of isl_union_pw_multi_aff and isl_union_set objects. */ -static int test_mupa_uset(isl_ctx *ctx) +static isl_stat test_upma_uset(isl_ctx *ctx) { int i; isl_bool ok; - isl_multi_union_pw_aff *mupa, *res; + isl_union_pw_multi_aff *upma, *res; isl_union_set *uset; - for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) { - mupa = isl_multi_union_pw_aff_read_from_str(ctx, - mupa_uset_tests[i].arg1); + for (i = 0; i < ARRAY_SIZE(upma_uset_tests); ++i) { + upma = isl_union_pw_multi_aff_read_from_str(ctx, + upma_uset_tests[i].arg1); uset = isl_union_set_read_from_str(ctx, - mupa_uset_tests[i].arg2); - res = isl_multi_union_pw_aff_read_from_str(ctx, - mupa_uset_tests[i].res); - mupa = mupa_uset_tests[i].fn(mupa, uset); - ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); - isl_multi_union_pw_aff_free(mupa); - isl_multi_union_pw_aff_free(res); + upma_uset_tests[i].arg2); + res = isl_union_pw_multi_aff_read_from_str(ctx, + upma_uset_tests[i].res); + upma = upma_uset_tests[i].fn(upma, uset); + ok = isl_union_pw_multi_aff_plain_is_equal(upma, res); + isl_union_pw_multi_aff_free(upma); + isl_union_pw_multi_aff_free(res); + if (ok < 0) + return isl_stat_error; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return isl_stat_error); + } + + return isl_stat_ok; +} + +/* Inputs for basic tests of unary operations on isl_multi_pw_aff objects. + * "fn" is the function that is tested. + * "arg" is a string description of the input. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_pw_aff *(*fn)(__isl_take isl_multi_pw_aff *mpa); + const char *arg; + const char *res; +} mpa_un_tests[] = { + { &isl_multi_pw_aff_range_factor_domain, + "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", + "{ A[x] -> B[(1 : x >= 5)] }" }, + { &isl_multi_pw_aff_range_factor_range, + "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }", + "{ A[y] -> C[(2 : y <= 10)] }" }, + { &isl_multi_pw_aff_range_factor_domain, + "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", + "{ A[x] -> B[(1 : x >= 5)] }" }, + { &isl_multi_pw_aff_range_factor_range, + "{ A[x] -> [B[(1 : x >= 5)] -> C[]] }", + "{ A[y] -> C[] }" }, + { &isl_multi_pw_aff_range_factor_domain, + "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", + "{ A[x] -> B[] }" }, + { &isl_multi_pw_aff_range_factor_range, + "{ A[x] -> [B[] -> C[(2 : x <= 10)]] }", + "{ A[y] -> C[(2 : y <= 10)] }" }, + { &isl_multi_pw_aff_range_factor_domain, + "{ A[x] -> [B[] -> C[]] }", + "{ A[x] -> B[] }" }, + { &isl_multi_pw_aff_range_factor_range, + "{ A[x] -> [B[] -> C[]] }", + "{ A[y] -> C[] }" }, + { &isl_multi_pw_aff_factor_range, + "{ [B[] -> C[]] }", + "{ C[] }" }, + { &isl_multi_pw_aff_range_factor_domain, + "{ A[x] -> [B[] -> C[]] : x >= 0 }", + "{ A[x] -> B[] : x >= 0 }" }, + { &isl_multi_pw_aff_range_factor_range, + "{ A[x] -> [B[] -> C[]] : x >= 0 }", + "{ A[y] -> C[] : y >= 0 }" }, + { &isl_multi_pw_aff_factor_range, + "[N] -> { [B[] -> C[]] : N >= 0 }", + "[N] -> { C[] : N >= 0 }" }, +}; + +/* Perform some basic tests of unary operations on isl_multi_pw_aff objects. + */ +static int test_un_mpa(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_pw_aff *mpa, *res; + + for (i = 0; i < ARRAY_SIZE(mpa_un_tests); ++i) { + mpa = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].arg); + res = isl_multi_pw_aff_read_from_str(ctx, mpa_un_tests[i].res); + mpa = mpa_un_tests[i].fn(mpa); + ok = isl_multi_pw_aff_plain_is_equal(mpa, res); + isl_multi_pw_aff_free(mpa); + isl_multi_pw_aff_free(res); if (ok < 0) return -1; if (!ok) @@ -4892,6 +5564,909 @@ return 0; } +/* Inputs for basic tests of binary operations on isl_multi_pw_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_pw_aff *(*fn)( + __isl_take isl_multi_pw_aff *mpa1, + __isl_take isl_multi_pw_aff *mpa2); + const char *arg1; + const char *arg2; + const char *res; +} mpa_bin_tests[] = { + { &isl_multi_pw_aff_add, "{ A[] -> [1] }", "{ A[] -> [2] }", + "{ A[] -> [3] }" }, + { &isl_multi_pw_aff_add, "{ A[x] -> [(1 : x >= 5)] }", + "{ A[x] -> [(x : x <= 10)] }", + "{ A[x] -> [(1 + x : 5 <= x <= 10)] }" }, + { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }", + "{ A[x] -> [] : x <= 10 }", + "{ A[x] -> [] : 5 <= x <= 10 }" }, + { &isl_multi_pw_aff_add, "{ A[x] -> [] : x >= 5 }", + "[N] -> { A[x] -> [] : x <= N }", + "[N] -> { A[x] -> [] : 5 <= x <= N }" }, + { &isl_multi_pw_aff_add, + "[N] -> { A[x] -> [] : x <= N }", + "{ A[x] -> [] : x >= 5 }", + "[N] -> { A[x] -> [] : 5 <= x <= N }" }, + { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }", + "{ A[y] -> C[(2 : y <= 10)] }", + "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" }, + { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }", + "{ A[y] -> C[2] : y <= 10 }", + "{ A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= 10)]] }" }, + { &isl_multi_pw_aff_range_product, "{ A[x] -> B[1] : x >= 5 }", + "[N] -> { A[y] -> C[2] : y <= N }", + "[N] -> { A[x] -> [B[(1 : x >= 5)] -> C[(2 : x <= N)]] }" }, + { &isl_multi_pw_aff_range_product, "[N] -> { A[x] -> B[1] : x >= N }", + "{ A[y] -> C[2] : y <= 10 }", + "[N] -> { A[x] -> [B[(1 : x >= N)] -> C[(2 : x <= 10)]] }" }, + { &isl_multi_pw_aff_range_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }", + "{ A[] -> [B[1] -> C[2]] }" }, + { &isl_multi_pw_aff_range_product, "{ A[] -> B[] }", "{ A[] -> C[] }", + "{ A[] -> [B[] -> C[]] }" }, + { &isl_multi_pw_aff_range_product, "{ A[x] -> B[(1 : x >= 5)] }", + "{ A[y] -> C[] : y <= 10 }", + "{ A[x] -> [B[(1 : x >= 5)] -> C[]] : x <= 10 }" }, + { &isl_multi_pw_aff_range_product, "{ A[y] -> C[] : y <= 10 }", + "{ A[x] -> B[(1 : x >= 5)] }", + "{ A[x] -> [C[] -> B[(1 : x >= 5)]] : x <= 10 }" }, + { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", + "{ A[y] -> C[(2 : y <= 10)] }", + "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[(2 : y <= 10)]] }" }, + { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", + "{ A[y] -> C[] : y <= 10 }", + "{ [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= 10 }" }, + { &isl_multi_pw_aff_product, "{ A[y] -> C[] : y <= 10 }", + "{ A[x] -> B[(1 : x >= 5)] }", + "{ [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= 10 }" }, + { &isl_multi_pw_aff_product, "{ A[x] -> B[(1 : x >= 5)] }", + "[N] -> { A[y] -> C[] : y <= N }", + "[N] -> { [A[x] -> A[y]] -> [B[(1 : x >= 5)] -> C[]] : y <= N }" }, + { &isl_multi_pw_aff_product, "[N] -> { A[y] -> C[] : y <= N }", + "{ A[x] -> B[(1 : x >= 5)] }", + "[N] -> { [A[y] -> A[x]] -> [C[] -> B[(1 : x >= 5)]] : y <= N }" }, + { &isl_multi_pw_aff_product, "{ A[x] -> B[] : x >= 5 }", + "{ A[y] -> C[] : y <= 10 }", + "{ [A[x] -> A[y]] -> [B[] -> C[]] : x >= 5 and y <= 10 }" }, + { &isl_multi_pw_aff_product, "{ A[] -> B[1] }", "{ A[] -> C[2] }", + "{ [A[] -> A[]] -> [B[1] -> C[2]] }" }, + { &isl_multi_pw_aff_product, "{ A[] -> B[] }", "{ A[] -> C[] }", + "{ [A[] -> A[]] -> [B[] -> C[]] }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[i + 2j] }", "{ A[a,b] -> B[b,a] }", + "{ A[a,b] -> C[b + 2a] }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[i + 2j] }", + "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", + "{ A[a,b] -> C[(b + 2a : b > a)] }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[(i + 2j : j > 4)] }", + "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", + "{ A[a,b] -> C[(b + 2a : b > a > 4)] }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[] }", + "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", + "{ A[a,b] -> C[] }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[] : i > j }", + "{ A[a,b] -> B[b,a] }", + "{ A[a,b] -> C[] : b > a }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "{ B[i,j] -> C[] : j > 5 }", + "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", + "{ A[a,b] -> C[] : b > a > 5 }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "[N] -> { B[i,j] -> C[] : j > N }", + "{ A[a,b] -> B[(b : b > a),(a : b > a)] }", + "[N] -> { A[a,b] -> C[] : b > a > N }" }, + { &isl_multi_pw_aff_pullback_multi_pw_aff, + "[M,N] -> { B[] -> C[] : N > 5 }", + "[M,N] -> { A[] -> B[] : M > N }", + "[M,N] -> { A[] -> C[] : M > N > 5 }" }, +}; + +/* Perform some basic tests of binary operations on isl_multi_pw_aff objects. + */ +static int test_bin_mpa(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_pw_aff *mpa1, *mpa2, *res; + + for (i = 0; i < ARRAY_SIZE(mpa_bin_tests); ++i) { + mpa1 = isl_multi_pw_aff_read_from_str(ctx, + mpa_bin_tests[i].arg1); + mpa2 = isl_multi_pw_aff_read_from_str(ctx, + mpa_bin_tests[i].arg2); + res = isl_multi_pw_aff_read_from_str(ctx, + mpa_bin_tests[i].res); + mpa1 = mpa_bin_tests[i].fn(mpa1, mpa2); + ok = isl_multi_pw_aff_plain_is_equal(mpa1, res); + isl_multi_pw_aff_free(mpa1); + isl_multi_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of unary operations on + * isl_multi_union_pw_aff objects. + * "fn" is the function that is tested. + * "arg" is a string description of the input. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa); + const char *arg; + const char *res; +} mupa_un_tests[] = { + { &isl_multi_union_pw_aff_factor_range, + "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]", + "C[{ A[] -> [2] }]" }, + { &isl_multi_union_pw_aff_factor_range, + "[B[] -> C[{ A[] -> [2] }]]", + "C[{ A[] -> [2] }]" }, + { &isl_multi_union_pw_aff_factor_range, + "[B[{ A[] -> [1] }] -> C[]]", + "C[]" }, + { &isl_multi_union_pw_aff_factor_range, + "[B[] -> C[]]", + "C[]" }, + { &isl_multi_union_pw_aff_factor_range, + "([B[] -> C[]] : { A[x] : x >= 0 })", + "(C[] : { A[x] : x >= 0 })" }, + { &isl_multi_union_pw_aff_factor_range, + "[N] -> ([B[] -> C[]] : { A[x] : x <= N })", + "[N] -> (C[] : { A[x] : x <= N })" }, + { &isl_multi_union_pw_aff_factor_range, + "[N] -> ([B[] -> C[]] : { : N >= 0 })", + "[N] -> (C[] : { : N >= 0 })" }, +}; + +/* Perform some basic tests of unary operations on + * isl_multi_union_pw_aff objects. + */ +static int test_un_mupa(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + + for (i = 0; i < ARRAY_SIZE(mupa_un_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_un_tests[i].arg); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_un_tests[i].res); + mupa = mupa_un_tests[i].fn(mupa); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * isl_multi_union_pw_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa1, + __isl_take isl_multi_union_pw_aff *mupa2); + const char *arg1; + const char *arg2; + const char *res; +} mupa_bin_tests[] = { + { &isl_multi_union_pw_aff_add, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]", + "[{ A[] -> [3] }]" }, + { &isl_multi_union_pw_aff_sub, "[{ A[] -> [1] }]", "[{ A[] -> [2] }]", + "[{ A[] -> [-1] }]" }, + { &isl_multi_union_pw_aff_add, + "[{ A[] -> [1]; B[] -> [4] }]", + "[{ A[] -> [2]; C[] -> [5] }]", + "[{ A[] -> [3] }]" }, + { &isl_multi_union_pw_aff_union_add, + "[{ A[] -> [1]; B[] -> [4] }]", + "[{ A[] -> [2]; C[] -> [5] }]", + "[{ A[] -> [3]; B[] -> [4]; C[] -> [5] }]" }, + { &isl_multi_union_pw_aff_add, "[{ A[x] -> [(1)] : x >= 5 }]", + "[{ A[x] -> [(x)] : x <= 10 }]", + "[{ A[x] -> [(1 + x)] : 5 <= x <= 10 }]" }, + { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })", + "([] : { A[x] : x <= 10 })", + "([] : { A[x] : 5 <= x <= 10 })" }, + { &isl_multi_union_pw_aff_add, "([] : { A[x] : x >= 5 })", + "[N] -> ([] : { A[x] : x <= N })", + "[N] -> ([] : { A[x] : 5 <= x <= N })" }, + { &isl_multi_union_pw_aff_add, "[N] -> ([] : { A[x] : x >= N })", + "([] : { A[x] : x <= 10 })", + "[N] -> ([] : { A[x] : N <= x <= 10 })" }, + { &isl_multi_union_pw_aff_union_add, "[{ A[x] -> [(1)] : x >= 5 }]", + "[{ A[x] -> [(x)] : x <= 10 }]", + "[{ A[x] -> [(1 + x)] : 5 <= x <= 10; " + "A[x] -> [(1)] : x > 10; A[x] -> [(x)] : x < 5 }]" }, + { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 5 })", + "([] : { A[x] : x <= 10 })", + "([] : { A[x] })" }, + { &isl_multi_union_pw_aff_union_add, "([] : { A[x] : x >= 0 })", + "[N] -> ([] : { A[x] : x >= N })", + "[N] -> ([] : { A[x] : x >= 0 or x >= N })" }, + { &isl_multi_union_pw_aff_union_add, + "[N] -> ([] : { A[] : N >= 0})", + "[N] -> ([] : { A[] : N <= 0})", + "[N] -> ([] : { A[] })" }, + { &isl_multi_union_pw_aff_union_add, + "[N] -> ([] : { A[] })", + "[N] -> ([] : { : })", + "[N] -> ([] : { : })" }, + { &isl_multi_union_pw_aff_union_add, + "[N] -> ([] : { : })", + "[N] -> ([] : { A[] })", + "[N] -> ([] : { : })" }, + { &isl_multi_union_pw_aff_union_add, + "[N] -> ([] : { : N >= 0})", + "[N] -> ([] : { : N <= 0})", + "[N] -> ([] : { : })" }, + { &isl_multi_union_pw_aff_range_product, + "B[{ A[] -> [1] }]", + "C[{ A[] -> [2] }]", + "[B[{ A[] -> [1] }] -> C[{ A[] -> [2] }]]" }, + { &isl_multi_union_pw_aff_range_product, + "(B[] : { A[x] : x >= 5 })", + "(C[] : { A[x] : x <= 10 })", + "([B[] -> C[]] : { A[x] : 5 <= x <= 10 })" }, + { &isl_multi_union_pw_aff_range_product, + "B[{ A[x] -> [x + 1] : x >= 5 }]", + "(C[] : { A[x] : x <= 10 })", + "[B[{ A[x] -> [x + 1] : 5 <= x <= 10 }] -> C[]]" }, + { &isl_multi_union_pw_aff_range_product, + "(C[] : { A[x] : x <= 10 })", + "B[{ A[x] -> [x + 1] : x >= 5 }]", + "[C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= 10 }]]" }, + { &isl_multi_union_pw_aff_range_product, + "B[{ A[x] -> [x + 1] : x >= 5 }]", + "[N] -> (C[] : { A[x] : x <= N })", + "[N] -> [B[{ A[x] -> [x + 1] : 5 <= x <= N }] -> C[]]" }, + { &isl_multi_union_pw_aff_range_product, + "[N] -> (C[] : { A[x] : x <= N })", + "B[{ A[x] -> [x + 1] : x >= 5 }]", + "[N] -> [C[] -> B[{ A[x] -> [x + 1] : 5 <= x <= N }]]" }, + { &isl_multi_union_pw_aff_range_product, + "B[{ A[] -> [1]; D[] -> [3] }]", + "C[{ A[] -> [2] }]", + "[B[{ A[] -> [1]; D[] -> [3] }] -> C[{ A[] -> [2] }]]" }, + { &isl_multi_union_pw_aff_range_product, + "B[] }]", + "(C[] : { A[x] })", + "([B[] -> C[]] : { A[x] })" }, + { &isl_multi_union_pw_aff_range_product, + "(B[] : { A[x] })", + "C[] }]", + "([B[] -> C[]] : { A[x] })" }, +}; + +/* Perform some basic tests of binary operations on + * isl_multi_union_pw_aff objects. + */ +static int test_bin_mupa(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa1, *mupa2, *res; + + for (i = 0; i < ARRAY_SIZE(mupa_bin_tests); ++i) { + mupa1 = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_bin_tests[i].arg1); + mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_bin_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_bin_tests[i].res); + mupa1 = mupa_bin_tests[i].fn(mupa1, mupa2); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa1, res); + isl_multi_union_pw_aff_free(mupa1); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_set objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_set *set); + const char *arg1; + const char *arg2; + const char *res; +} mupa_set_tests[] = { + { &isl_multi_union_pw_aff_intersect_range, + "C[{ B[i,j] -> [i + 2j] }]", "{ C[1] }", + "C[{ B[i,j] -> [i + 2j] : i + 2j = 1 }]" }, + { &isl_multi_union_pw_aff_intersect_range, + "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[N] }", + "[N] -> C[{ B[i,j] -> [i + 2j] : i + 2j = N }]" }, + { &isl_multi_union_pw_aff_intersect_range, + "[N] -> C[{ B[i,j] -> [i + 2j + N] }]", "{ C[1] }", + "[N] -> C[{ B[i,j] -> [i + 2j + N] : i + 2j + N = 1 }]" }, + { &isl_multi_union_pw_aff_intersect_range, + "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { C[x] : N >= 0 }", + "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0 }]" }, + { &isl_multi_union_pw_aff_intersect_range, + "C[]", "{ C[] }", "C[]" }, + { &isl_multi_union_pw_aff_intersect_range, + "[N] -> (C[] : { : N >= 0 })", + "{ C[] }", + "[N] -> (C[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_intersect_range, + "(C[] : { A[a,b] })", + "{ C[] }", + "(C[] : { A[a,b] })" }, + { &isl_multi_union_pw_aff_intersect_range, + "[N] -> (C[] : { A[a,b] : a,b <= N })", + "{ C[] }", + "[N] -> (C[] : { A[a,b] : a,b <= N })" }, + { &isl_multi_union_pw_aff_intersect_range, + "C[]", + "[N] -> { C[] : N >= 0 }", + "[N] -> (C[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_intersect_range, + "(C[] : { A[a,b] })", + "[N] -> { C[] : N >= 0 }", + "[N] -> (C[] : { A[a,b] : N >= 0 })" }, + { &isl_multi_union_pw_aff_intersect_range, + "[N] -> (C[] : { : N >= 0 })", + "[N] -> { C[] : N < 1024 }", + "[N] -> (C[] : { : 0 <= N < 1024 })" }, + { &isl_multi_union_pw_aff_intersect_params, + "C[{ B[i,j] -> [i + 2j] }]", "[N] -> { : N >= 0 }", + "[N] -> C[{ B[i,j] -> [i + 2j] : N >= 0}]" }, + { &isl_multi_union_pw_aff_intersect_params, + "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "[N] -> { : N >= 0 }", + "[N] -> C[{ B[i,j] -> [i + 2j] : 0 <= N <= 256 }]" }, + { &isl_multi_union_pw_aff_intersect_params, + "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]", "{ : }", + "[N] -> C[{ B[i,j] -> [i + 2j] : N <= 256 }]" }, + { &isl_multi_union_pw_aff_intersect_params, + "C[]", "[N] -> { : N >= 0 }", + "[N] -> (C[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_intersect_params, + "(C[] : { A[a,b] })", "[N] -> { : N >= 0 }", + "[N] -> (C[] : { A[a,b] : N >= 0 })" }, + { &isl_multi_union_pw_aff_intersect_params, + "[N] -> (C[] : { A[a,N] })", "{ : }", + "[N] -> (C[] : { A[a,N] })" }, + { &isl_multi_union_pw_aff_intersect_params, + "[N] -> (C[] : { A[a,b] : N <= 256 })", "[N] -> { : N >= 0 }", + "[N] -> (C[] : { A[a,b] : 0 <= N <= 256 })" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_set objects. + */ +static int test_mupa_set(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + isl_set *set; + + for (i = 0; i < ARRAY_SIZE(mupa_set_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_set_tests[i].arg1); + set = isl_set_read_from_str(ctx, mupa_set_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_set_tests[i].res); + mupa = mupa_set_tests[i].fn(mupa, set); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_union_set objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_union_set *uset); + const char *arg1; + const char *arg2; + const char *res; +} mupa_uset_tests[] = { + { &isl_multi_union_pw_aff_intersect_domain, + "C[{ B[i,j] -> [i + 2j] }]", "{ B[i,i] }", + "C[{ B[i,i] -> [3i] }]" }, + { &isl_multi_union_pw_aff_intersect_domain, + "(C[] : { B[i,j] })", "{ B[i,i] }", + "(C[] : { B[i,i] })" }, + { &isl_multi_union_pw_aff_intersect_domain, + "(C[] : { B[i,j] })", "[N] -> { B[N,N] }", + "[N] -> (C[] : { B[N,N] })" }, + { &isl_multi_union_pw_aff_intersect_domain, + "C[]", "{ B[i,i] }", + "(C[] : { B[i,i] })" }, + { &isl_multi_union_pw_aff_intersect_domain, + "[N] -> (C[] : { : N >= 0 })", "{ B[i,i] }", + "[N] -> (C[] : { B[i,i] : N >= 0 })" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_union_set objects. + */ +static int test_mupa_uset(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + isl_union_set *uset; + + for (i = 0; i < ARRAY_SIZE(mupa_uset_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_uset_tests[i].arg1); + uset = isl_union_set_read_from_str(ctx, + mupa_uset_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_uset_tests[i].res); + mupa = mupa_uset_tests[i].fn(mupa, uset); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_multi_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_multi_aff *ma); + const char *arg1; + const char *arg2; + const char *res; +} mupa_ma_tests[] = { + { &isl_multi_union_pw_aff_apply_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " + "{ A[i,j] -> [j]; B[i,j] -> [i] }]", + "{ C[a,b] -> D[b,a] }", + "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, " + "{ A[i,j] -> [i]; B[i,j] -> [j] }]" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, " + "{ A[i,j] -> [j]; B[i,j] -> [i] }]", + "{ C[a,b] -> D[b,a] }", + "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, " + "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", + "[N] -> { C[a] -> D[a + N] }", + "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }] " }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "C[]", + "{ C[] -> D[] }", + "D[]" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "{ C[] -> D[] }", + "[N] -> (D[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "C[]", + "[N] -> { C[] -> D[N] }", + "[N] -> D[{ [N] }]" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "(C[] : { A[i,j] : i >= j })", + "{ C[] -> D[] }", + "(D[] : { A[i,j] : i >= j })" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "[N] -> (C[] : { A[i,j] : N >= 0 })", + "{ C[] -> D[] }", + "[N] -> (D[] : { A[i,j] : N >= 0 })" }, + { &isl_multi_union_pw_aff_apply_multi_aff, + "(C[] : { A[i,j] : i >= j })", + "[N] -> { C[] -> D[N] }", + "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_multi_aff objects. + */ +static int test_mupa_ma(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + isl_multi_aff *ma; + + for (i = 0; i < ARRAY_SIZE(mupa_ma_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_ma_tests[i].arg1); + ma = isl_multi_aff_read_from_str(ctx, mupa_ma_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_ma_tests[i].res); + mupa = mupa_ma_tests[i].fn(mupa, ma); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_pw_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_pw_aff *pa); + const char *arg1; + const char *arg2; + const char *res; +} mupa_pa_tests[] = { + { &isl_multi_union_pw_aff_apply_pw_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", + "[N] -> { C[a] -> [a + N] }", + "[N] -> { A[i,j] -> [i + N]; B[i,j] -> [j + N] }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", + "{ C[a] -> [a] : a >= 0; C[a] -> [-a] : a < 0 }", + "{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; " + "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "C[]", + "[N] -> { C[] -> [N] }", + "[N] -> { [N] }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "C[]", + "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }", + "[N] -> { [N] : N >= 0; [-N] : N < 0 }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "[N] -> (C[] : { : N >= 0 })", + "[N] -> { C[] -> [N] }", + "[N] -> { [N] : N >= 0 }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "[N] -> (C[] : { : N >= 0 })", + "[N] -> { C[] -> [N] : N >= 0; C[] -> [-N] : N < 0 }", + "[N] -> { [N] : N >= 0 }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "[N] -> (C[] : { : N >= 0 })", + "{ C[] -> [0] }", + "[N] -> { [0] : N >= 0 }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "(C[] : { A[i,j] : i >= j })", + "[N] -> { C[] -> [N] }", + "[N] -> { A[i,j] -> [N] : i >= j }" }, + { &isl_multi_union_pw_aff_apply_pw_aff, + "(C[] : { A[i,j] : i >= j })", + "[N] -> { C[] -> [N] : N >= 0 }", + "[N] -> { A[i,j] -> [N] : i >= j and N >= 0 }" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_pw_aff objects. + */ +static int test_mupa_pa(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa; + isl_union_pw_aff *upa, *res; + isl_pw_aff *pa; + + for (i = 0; i < ARRAY_SIZE(mupa_pa_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_pa_tests[i].arg1); + pa = isl_pw_aff_read_from_str(ctx, mupa_pa_tests[i].arg2); + res = isl_union_pw_aff_read_from_str(ctx, + mupa_pa_tests[i].res); + upa = mupa_pa_tests[i].fn(mupa, pa); + ok = isl_union_pw_aff_plain_is_equal(upa, res); + isl_union_pw_aff_free(upa); + isl_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_pw_multi_aff *pma); + const char *arg1; + const char *arg2; + const char *res; +} mupa_pma_tests[] = { + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " + "{ A[i,j] -> [j]; B[i,j] -> [i] }]", + "{ C[a,b] -> D[b,a] }", + "D[{ A[i,j] -> [j]; B[i,j] -> [i] }, " + "{ A[i,j] -> [i]; B[i,j] -> [j] }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }, " + "{ A[i,j] -> [j]; B[i,j] -> [i] }]", + "{ C[a,b] -> D[b,a] }", + "D[{ A[i,j] -> [j] : i >= 0; B[i,j] -> [i] }, " + "{ A[i,j] -> [i] : i >= 0; B[i,j] -> [j] }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", + "[N] -> { C[a] -> D[a + N] }", + "[N] -> D[{ A[i,j] -> [i + N]; B[i,j] -> [j + N] }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }]", + "{ C[a] -> D[a] : a >= 0; C[a] -> D[-a] : a < 0 }", + "D[{ A[i,j] -> [i] : i >= 0; A[i,j] -> [-i] : i < 0; " + "B[i,j] -> [j] : j >= 0; B[i,j] -> [-j] : j < 0 }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[{ A[i,j] -> [i]; B[i,j] -> [j] }, " + "{ A[i,j] -> [j]; B[i,j] -> [i] }]", + "{ C[a,b] -> D[a,b] : a >= b; C[a,b] -> D[b,a] : a < b }", + "D[{ A[i,j] -> [i] : i >= j; A[i,j] -> [j] : i < j; " + "B[i,j] -> [j] : i <= j; B[i,j] -> [i] : i > j }, " + "{ A[i,j] -> [j] : i >= j; A[i,j] -> [i] : i < j; " + "B[i,j] -> [i] : i <= j; B[i,j] -> [j] : i > j }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[]", + "{ C[] -> D[] }", + "D[]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "{ C[] -> D[] }", + "[N] -> (D[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[]", + "[N] -> { C[] -> D[N] }", + "[N] -> D[{ [N] }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "(C[] : { A[i,j] : i >= j })", + "{ C[] -> D[] }", + "(D[] : { A[i,j] : i >= j })" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "[N] -> (C[] : { A[i,j] : N >= 0 })", + "{ C[] -> D[] }", + "[N] -> (D[] : { A[i,j] : N >= 0 })" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "(C[] : { A[i,j] : i >= j })", + "[N] -> { C[] -> D[N] }", + "[N] -> (D[{ A[i,j] -> [N] : i >= j }])" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "C[]", + "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }", + "[N] -> D[{ [N] : N >= 0; [-N] : N < 0 }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "[N] -> { C[] -> D[N] }", + "[N] -> D[{ [N] : N >= 0 }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "[N] -> { C[] -> D[N] : N >= 0; C[] -> D[-N] : N < 0 }", + "[N] -> D[{ [N] : N >= 0 }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "{ C[] -> D[0] }", + "[N] -> D[{ [0] : N >= 0 }]" }, + { &isl_multi_union_pw_aff_apply_pw_multi_aff, + "(C[] : { A[i,j] : i >= j })", + "[N] -> { C[] -> D[N] : N >= 0 }", + "[N] -> D[{ A[i,j] -> [N] : i >= j and N >= 0 }]" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_pw_multi_aff objects. + */ +static int test_mupa_pma(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + isl_pw_multi_aff *pma; + + for (i = 0; i < ARRAY_SIZE(mupa_pma_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_pma_tests[i].arg1); + pma = isl_pw_multi_aff_read_from_str(ctx, + mupa_pma_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_pma_tests[i].res); + mupa = mupa_pma_tests[i].fn(mupa, pma); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_multi_union_pw_aff *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_union_pw_multi_aff *upma); + const char *arg1; + const char *arg2; + const char *res; +} mupa_upma_tests[] = { + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[{ B[i,j] -> [i + 2j] }]", "{ A[a,b] -> B[b,a] }", + "C[{ A[a,b] -> [b + 2a] }]" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[{ B[i,j] -> [i + 2j] }]", + "{ A[a,b] -> B[b,a] : b > a }", + "C[{ A[a,b] -> [b + 2a] : b > a }]" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[{ B[i,j] -> [i + 2j] : j > 4 }]", + "{ A[a,b] -> B[b,a] : b > a }", + "C[{ A[a,b] -> [b + 2a] : b > a > 4 }]" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[{ B[i,j] -> [i + 2j] }]", + "{ A[a,b] -> B[b,a] : a > b; A[a,b] -> B[a,b] : a <= b }", + "C[{ A[a,b] -> [b + 2a] : a > b; A[a,b] -> [a + 2b] : a <= b }]" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "(C[] : { B[a,b] })", + "{ A[a,b] -> B[b,a] }", + "(C[] : { A[a,b] })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "(C[] : { B[a,b] })", + "{ B[a,b] -> A[b,a] }", + "(C[] : { })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "(C[] : { B[a,b] })", + "{ A[a,b] -> B[b,a] : a > b }", + "(C[] : { A[a,b] : a > b })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "(C[] : { B[a,b] : a > b })", + "{ A[a,b] -> B[b,a] }", + "(C[] : { A[a,b] : b > a })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "[N] -> (C[] : { B[a,b] : a > N })", + "{ A[a,b] -> B[b,a] : a > b }", + "[N] -> (C[] : { A[a,b] : a > b > N })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "(C[] : { B[a,b] : a > b })", + "[N] -> { A[a,b] -> B[b,a] : a > N }", + "[N] -> (C[] : { A[a,b] : b > a > N })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[]", + "{ A[a,b] -> B[b,a] }", + "C[]" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "[N] -> (C[] : { : N >= 0 })", + "{ A[a,b] -> B[b,a] }", + "[N] -> (C[] : { : N >= 0 })" }, + { &isl_multi_union_pw_aff_pullback_union_pw_multi_aff, + "C[]", + "[N] -> { A[a,b] -> B[b,a] : N >= 0 }", + "[N] -> (C[] : { : N >= 0 })" }, +}; + +/* Perform some basic tests of binary operations on + * pairs of isl_multi_union_pw_aff and isl_union_pw_multi_aff objects. + */ +static int test_mupa_upma(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_multi_union_pw_aff *mupa, *res; + isl_union_pw_multi_aff *upma; + + for (i = 0; i < ARRAY_SIZE(mupa_upma_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_upma_tests[i].arg1); + upma = isl_union_pw_multi_aff_read_from_str(ctx, + mupa_upma_tests[i].arg2); + res = isl_multi_union_pw_aff_read_from_str(ctx, + mupa_upma_tests[i].res); + mupa = mupa_upma_tests[i].fn(mupa, upma); + ok = isl_multi_union_pw_aff_plain_is_equal(mupa, res); + isl_multi_union_pw_aff_free(mupa); + isl_multi_union_pw_aff_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Check that the input tuple of an isl_aff can be set properly. + */ +static isl_stat test_aff_set_tuple_id(isl_ctx *ctx) +{ + isl_id *id; + isl_aff *aff; + int equal; + + aff = isl_aff_read_from_str(ctx, "{ [x] -> [x + 1] }"); + id = isl_id_alloc(ctx, "A", NULL); + aff = isl_aff_set_tuple_id(aff, isl_dim_in, id); + equal = aff_check_plain_equal(aff, "{ A[x] -> [x + 1] }"); + isl_aff_free(aff); + if (equal < 0) + return isl_stat_error; + + return isl_stat_ok; +} + int test_aff(isl_ctx *ctx) { const char *str; @@ -4900,51 +6475,615 @@ isl_local_space *ls; isl_aff *aff; int zero, equal; + + if (test_upa(ctx) < 0) + return -1; + if (test_bin_aff(ctx) < 0) + return -1; + if (test_bin_pw_aff(ctx) < 0) + return -1; + if (test_bin_upma(ctx) < 0) + return -1; + if (test_bin_upma_fail(ctx) < 0) + return -1; + if (test_upma_uset(ctx) < 0) + return -1; + if (test_un_mpa(ctx) < 0) + return -1; + if (test_bin_mpa(ctx) < 0) + return -1; + if (test_un_mupa(ctx) < 0) + return -1; + if (test_bin_mupa(ctx) < 0) + return -1; + if (test_mupa_set(ctx) < 0) + return -1; + if (test_mupa_uset(ctx) < 0) + return -1; + if (test_mupa_ma(ctx) < 0) + return -1; + if (test_mupa_pa(ctx) < 0) + return -1; + if (test_mupa_pma(ctx) < 0) + return -1; + if (test_mupa_upma(ctx) < 0) + return -1; + + space = isl_space_set_alloc(ctx, 0, 1); + ls = isl_local_space_from_space(space); + aff = isl_aff_zero_on_domain(ls); + + aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); + aff = isl_aff_scale_down_ui(aff, 3); + aff = isl_aff_floor(aff); + aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); + aff = isl_aff_scale_down_ui(aff, 2); + aff = isl_aff_floor(aff); + aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); + + str = "{ [10] }"; + set = isl_set_read_from_str(ctx, str); + aff = isl_aff_gist(aff, set); + + aff = isl_aff_add_constant_si(aff, -16); + zero = isl_aff_plain_is_zero(aff); + isl_aff_free(aff); + + if (zero < 0) + return -1; + if (!zero) + isl_die(ctx, isl_error_unknown, "unexpected result", return -1); + + aff = isl_aff_read_from_str(ctx, "{ [-1] }"); + aff = isl_aff_scale_down_ui(aff, 64); + aff = isl_aff_floor(aff); + equal = aff_check_plain_equal(aff, "{ [-1] }"); + isl_aff_free(aff); + if (equal < 0) + return -1; + + if (test_aff_set_tuple_id(ctx) < 0) + return -1; + + return 0; +} + +/* Inputs for isl_set_bind tests. + * "set" is the input set. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +static +struct { + const char *set; + const char *tuple; + const char *res; +} bind_set_tests[] = { + { "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }", + "{ A[M, N] }", + "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" }, + { "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }", + "{ B[N, M] }", + "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" }, + { "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }", + "{ C[N] }", + "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }" }, + { "[M] -> { D[x, N] : x mod 2 = 0 and N mod 8 = 3 and M >= 0 }", + "{ D[M, N] }", + "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 and M >= 0 }" }, +}; + +/* Perform basic isl_set_bind tests. + */ +static isl_stat test_bind_set(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_set_tests); ++i) { + const char *str; + isl_set *set; + isl_multi_id *tuple; + isl_stat r; + + set = isl_set_read_from_str(ctx, bind_set_tests[i].set); + str = bind_set_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + set = isl_set_bind(set, tuple); + r = set_check_equal(set, bind_set_tests[i].res); + isl_set_free(set); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_map_bind_domain tests. + * "map" is the input map. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +struct { + const char *map; + const char *tuple; + const char *res; +} bind_map_domain_tests[] = { + { "{ A[M, N] -> [M + floor(N/2)] }", + "{ A[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "{ B[N, M] -> [M + floor(N/2)] }", + "{ B[N, M] }", + "[N, M] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[N] -> [M + floor(N/2)] }", + "{ C[N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[x, N] -> [x + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[x, N] -> [M + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }", + "{ C[N, M] }", + "[A, N, M] -> { [M + floor(N/2)] }" }, +}; + +/* Perform basic isl_map_bind_domain tests. + */ +static isl_stat test_bind_map_domain(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_map_domain_tests); ++i) { + const char *str; + isl_map *map; + isl_set *set; + isl_multi_id *tuple; + isl_stat r; + + str = bind_map_domain_tests[i].map; + map = isl_map_read_from_str(ctx, str); + str = bind_map_domain_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + set = isl_map_bind_domain(map, tuple); + str = bind_map_domain_tests[i].res; + r = set_check_equal(set, str); + isl_set_free(set); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_union_map_bind_range tests. + * "map" is the input union map. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +struct { + const char *map; + const char *tuple; + const char *res; +} bind_umap_range_tests[] = { + { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }", + "{ A[M, N] }", + "[M, N] -> { B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" }, + { "{ B[N, M] -> A[M, N] : M mod 2 = 0 and N mod 8 = 3 }", + "{ B[M, N] }", + "{ }" }, + { "{ A[] -> B[]; C[] -> D[]; E[] -> B[] }", + "{ B[] }", + "{ A[]; E[] }" }, +}; + +/* Perform basic isl_union_map_bind_range tests. + */ +static isl_stat test_bind_umap_range(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_umap_range_tests); ++i) { + const char *str; + isl_union_map *umap; + isl_union_set *uset; + isl_multi_id *tuple; + isl_stat r; + + str = bind_umap_range_tests[i].map; + umap = isl_union_map_read_from_str(ctx, str); + str = bind_umap_range_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + uset = isl_union_map_bind_range(umap, tuple); + str = bind_umap_range_tests[i].res; + r = uset_check_equal(uset, str); + isl_union_set_free(uset); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_pw_multi_aff_bind_domain tests. + * "pma" is the input expression. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +struct { + const char *pma; + const char *tuple; + const char *res; +} bind_pma_domain_tests[] = { + { "{ A[M, N] -> [M + floor(N/2)] }", + "{ A[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "{ B[N, M] -> [M + floor(N/2)] }", + "{ B[N, M] }", + "[N, M] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[N] -> [M + floor(N/2)] }", + "{ C[N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[x, N] -> [x + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[M] -> { C[x, N] -> [M + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { [M + floor(N/2)] }" }, + { "[A, M] -> { C[N, x] -> [x + floor(N/2)] }", + "{ C[N, M] }", + "[A, N, M] -> { [M + floor(N/2)] }" }, +}; + +/* Perform basic isl_pw_multi_aff_bind_domain tests. + */ +static isl_stat test_bind_pma_domain(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_pma_domain_tests); ++i) { + const char *str; + isl_pw_multi_aff *pma; + isl_multi_id *tuple; + isl_stat r; + + str = bind_pma_domain_tests[i].pma; + pma = isl_pw_multi_aff_read_from_str(ctx, str); + str = bind_pma_domain_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + pma = isl_pw_multi_aff_bind_domain(pma, tuple); + str = bind_pma_domain_tests[i].res; + r = pw_multi_aff_check_plain_equal(pma, str); + isl_pw_multi_aff_free(pma); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_pw_multi_aff_bind_domain_wrapped_domain tests. + * "pma" is the input expression. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +struct { + const char *pma; + const char *tuple; + const char *res; +} bind_pma_domain_wrapped_tests[] = { + { "{ [A[M, N] -> B[]] -> [M + floor(N/2)] }", + "{ A[M, N] }", + "[M, N] -> { B[] -> [M + floor(N/2)] }" }, + { "{ [B[N, M] -> D[]] -> [M + floor(N/2)] }", + "{ B[N, M] }", + "[N, M] -> { D[] -> [M + floor(N/2)] }" }, + { "[M] -> { [C[N] -> B[x]] -> [x + M + floor(N/2)] }", + "{ C[N] }", + "[M, N] -> { B[x] -> [x + M + floor(N/2)] }" }, + { "[M] -> { [C[x, N] -> B[]] -> [x + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { B[] -> [M + floor(N/2)] }" }, + { "[M] -> { [C[x, N] -> B[]] -> [M + floor(N/2)] }", + "{ C[M, N] }", + "[M, N] -> { B[] -> [M + floor(N/2)] }" }, + { "[A, M] -> { [C[N, x] -> B[]] -> [x + floor(N/2)] }", + "{ C[N, M] }", + "[A, N, M] -> { B[] -> [M + floor(N/2)] }" }, +}; + +/* Perform basic isl_pw_multi_aff_bind_domain_wrapped_domain tests. + */ +static isl_stat test_bind_pma_domain_wrapped(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_pma_domain_wrapped_tests); ++i) { + const char *str; + isl_pw_multi_aff *pma; + isl_multi_id *tuple; + isl_stat r; + + str = bind_pma_domain_wrapped_tests[i].pma; + pma = isl_pw_multi_aff_read_from_str(ctx, str); + str = bind_pma_domain_wrapped_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + pma = isl_pw_multi_aff_bind_domain_wrapped_domain(pma, tuple); + str = bind_pma_domain_wrapped_tests[i].res; + r = pw_multi_aff_check_plain_equal(pma, str); + isl_pw_multi_aff_free(pma); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_aff_bind_id tests. + * "aff" is the input expression. + * "id" is the binding id. + * "res" is the expected result. + */ +static +struct { + const char *aff; + const char *id; + const char *res; +} bind_aff_tests[] = { + { "{ [4] }", "M", "[M = 4] -> { : }" }, + { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" }, + { "[M] -> { [4] }", "M", "[M = 4] -> { : }" }, + { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" }, + { "{ [NaN] }", "M", "{ : false }" }, + { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" }, +}; + +/* Perform basic isl_aff_bind_id tests. + */ +static isl_stat test_bind_aff(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_aff_tests); ++i) { + isl_aff *aff; + isl_set *res; + isl_id *id; + isl_stat r; + + aff = isl_aff_read_from_str(ctx, bind_aff_tests[i].aff); + id = isl_id_read_from_str(ctx, bind_aff_tests[i].id); + res = isl_set_from_basic_set(isl_aff_bind_id(aff, id)); + r = set_check_equal(res, bind_aff_tests[i].res); + isl_set_free(res); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_pw_aff_bind_id tests. + * "pa" is the input expression. + * "id" is the binding id. + * "res" is the expected result. + */ +static +struct { + const char *pa; + const char *id; + const char *res; +} bind_pa_tests[] = { + { "{ [4] }", "M", "[M = 4] -> { : }" }, + { "{ B[x] -> [floor(x/2)] }", "M", "[M] -> { B[x] : M = floor(x/2) }" }, + { "[M] -> { [4] }", "M", "[M = 4] -> { : }" }, + { "[M] -> { [floor(M/2)] }", "M", "[M] -> { : floor(M/2) = M }" }, + { "[M] -> { [M] : M >= 0; [-M] : M < 0 }", "M", "[M] -> { : M >= 0 }" }, + { "{ [NaN] }", "M", "{ : false }" }, + { "{ A[x] -> [NaN] }", "M", "{ A[x] : false }" }, +}; + +/* Perform basic isl_pw_aff_bind_id tests. + */ +static isl_stat test_bind_pa(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(bind_pa_tests); ++i) { + isl_pw_aff *pa; + isl_set *res; + isl_id *id; + isl_stat r; + + pa = isl_pw_aff_read_from_str(ctx, bind_pa_tests[i].pa); + id = isl_id_read_from_str(ctx, bind_pa_tests[i].id); + res = isl_pw_aff_bind_id(pa, id); + r = set_check_equal(res, bind_pa_tests[i].res); + isl_set_free(res); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Inputs for isl_multi_union_pw_aff_bind tests. + * "mupa" is the input expression. + * "tuple" is the binding tuple. + * "res" is the expected result. + */ +static +struct { + const char *mupa; + const char *tuple; + const char *res; +} bind_mupa_tests[] = { + { "A[{ [4] }, { [5] }]", + "{ A[M, N] }", + "[M = 4, N = 5] -> { : }" }, + { "A[{ B[x] -> [floor(x/2)] }, { B[y] -> [y + 5] }]", + "{ A[M, N] }", + "[M, N] -> { B[x] : M = floor(x/2) and N = x + 5 }" }, + { "[M] -> A[{ [4] }, { [M + 1] }]", + "{ A[M, N] }", + "[M = 4, N = 5] -> { : }" }, +}; + +/* Perform basic isl_multi_union_pw_aff_bind tests. + */ +static isl_stat test_bind_mupa(isl_ctx *ctx) +{ + int i; - if (test_upa(ctx) < 0) + for (i = 0; i < ARRAY_SIZE(bind_mupa_tests); ++i) { + const char *str; + isl_multi_union_pw_aff *mupa; + isl_union_set *res; + isl_multi_id *tuple; + isl_stat r; + + str = bind_mupa_tests[i].mupa; + mupa = isl_multi_union_pw_aff_read_from_str(ctx, str); + str = bind_mupa_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + res = isl_multi_union_pw_aff_bind(mupa, tuple); + r = uset_check_equal(res, bind_mupa_tests[i].res); + isl_union_set_free(res); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Perform tests that reinterpret dimensions as parameters. + */ +static int test_bind(isl_ctx *ctx) +{ + if (test_bind_set(ctx) < 0) return -1; - if (test_bin_aff(ctx) < 0) + if (test_bind_map_domain(ctx) < 0) return -1; - if (test_bin_pw_aff(ctx) < 0) + if (test_bind_umap_range(ctx) < 0) return -1; - if (test_bin_upma(ctx) < 0) + if (test_bind_pma_domain(ctx) < 0) return -1; - if (test_bin_upma_fail(ctx) < 0) + if (test_bind_pma_domain_wrapped(ctx) < 0) return -1; - if (test_mupa_uset(ctx) < 0) + if (test_bind_aff(ctx) < 0) + return -1; + if (test_bind_pa(ctx) < 0) return -1; + if (test_bind_mupa(ctx) < 0) + return -1; - space = isl_space_set_alloc(ctx, 0, 1); - ls = isl_local_space_from_space(space); - aff = isl_aff_zero_on_domain(ls); + return 0; +} - aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); - aff = isl_aff_scale_down_ui(aff, 3); - aff = isl_aff_floor(aff); - aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); - aff = isl_aff_scale_down_ui(aff, 2); - aff = isl_aff_floor(aff); - aff = isl_aff_add_coefficient_si(aff, isl_dim_in, 0, 1); +/* Inputs for isl_set_unbind_params tests. + * "set" is the input parameter domain. + * "tuple" is the tuple of the constructed set. + * "res" is the expected result. + */ +struct { + const char *set; + const char *tuple; + const char *res; +} unbind_set_tests[] = { + { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }", + "{ A[M, N] }", + "{ A[M, N] : M mod 2 = 0 and N mod 8 = 3 }" }, + { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }", + "{ B[N, M] }", + "{ B[N, M] : M mod 2 = 0 and N mod 8 = 3 }" }, + { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }", + "{ C[N] }", + "[M] -> { C[N] : M mod 2 = 0 and N mod 8 = 3 }" }, + { "[M, N] -> { : M mod 2 = 0 and N mod 8 = 3 }", + "{ D[T, N] }", + "[M] -> { D[x, N] : M mod 2 = 0 and N mod 8 = 3 }" }, +}; - str = "{ [10] }"; - set = isl_set_read_from_str(ctx, str); - aff = isl_aff_gist(aff, set); +/* Perform basic isl_set_unbind_params tests. + */ +static isl_stat test_unbind_set(isl_ctx *ctx) +{ + int i; - aff = isl_aff_add_constant_si(aff, -16); - zero = isl_aff_plain_is_zero(aff); - isl_aff_free(aff); + for (i = 0; i < ARRAY_SIZE(unbind_set_tests); ++i) { + const char *str; + isl_set *set; + isl_multi_id *tuple; + isl_stat r; + + set = isl_set_read_from_str(ctx, unbind_set_tests[i].set); + str = unbind_set_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + set = isl_set_unbind_params(set, tuple); + r = set_check_equal(set, unbind_set_tests[i].res); + isl_set_free(set); + if (r < 0) + return isl_stat_error; + } - if (zero < 0) - return -1; - if (!zero) - isl_die(ctx, isl_error_unknown, "unexpected result", return -1); + return isl_stat_ok; +} - aff = isl_aff_read_from_str(ctx, "{ [-1] }"); - aff = isl_aff_scale_down_ui(aff, 64); - aff = isl_aff_floor(aff); - equal = aff_check_plain_equal(aff, "{ [-1] }"); - isl_aff_free(aff); - if (equal < 0) +/* Inputs for isl_aff_unbind_params_insert_domain tests. + * "aff" is the input affine expression defined over a parameter domain. + * "tuple" is the tuple of the domain that gets introduced. + * "res" is the expected result. + */ +struct { + const char *aff; + const char *tuple; + const char *res; +} unbind_aff_tests[] = { + { "[M, N] -> { [M + floor(N/2)] }", + "{ A[M, N] }", + "{ A[M, N] -> [M + floor(N/2)] }" }, + { "[M, N] -> { [M + floor(N/2)] }", + "{ B[N, M] }", + "{ B[N, M] -> [M + floor(N/2)] }" }, + { "[M, N] -> { [M + floor(N/2)] }", + "{ C[N] }", + "[M] -> { C[N] -> [M + floor(N/2)] }" }, + { "[M, N] -> { [M + floor(N/2)] }", + "{ D[A, B, C, N, Z] }", + "[M] -> { D[A, B, C, N, Z] -> [M + floor(N/2)] }" }, +}; + +/* Perform basic isl_aff_unbind_params_insert_domain tests. + */ +static isl_stat test_unbind_aff(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(unbind_aff_tests); ++i) { + const char *str; + isl_aff *aff; + isl_multi_id *tuple; + isl_stat r; + + aff = isl_aff_read_from_str(ctx, unbind_aff_tests[i].aff); + str = unbind_aff_tests[i].tuple; + tuple = isl_multi_id_read_from_str(ctx, str); + aff = isl_aff_unbind_params_insert_domain(aff, tuple); + r = aff_check_plain_equal(aff, unbind_aff_tests[i].res); + isl_aff_free(aff); + if (r < 0) + return isl_stat_error; + } + + return isl_stat_ok; +} + +/* Perform tests that reinterpret parameters. + */ +static int test_unbind(isl_ctx *ctx) +{ + if (test_unbind_set(ctx) < 0) + return -1; + if (test_unbind_aff(ctx) < 0) return -1; return 0; @@ -4954,12 +7093,12 @@ */ static int check_single_piece(isl_ctx *ctx, __isl_take isl_pw_aff *pa) { - int n; + isl_size n; n = isl_pw_aff_n_piece(pa); isl_pw_aff_free(pa); - if (!pa) + if (n < 0) return -1; if (n != 1) isl_die(ctx, isl_error_unknown, "expecting single expression", @@ -5127,44 +7266,7 @@ return -1; if (!equal) isl_die(ctx, isl_error_unknown, "unexpected result", return -1); - - return 0; -} - -/* Is "pma" obviously equal to the isl_pw_multi_aff represented by "str"? - */ -static int pw_multi_aff_plain_is_equal(__isl_keep isl_pw_multi_aff *pma, - const char *str) -{ - isl_ctx *ctx; - isl_pw_multi_aff *pma2; - int equal; - - if (!pma) - return -1; - ctx = isl_pw_multi_aff_get_ctx(pma); - pma2 = isl_pw_multi_aff_read_from_str(ctx, str); - equal = isl_pw_multi_aff_plain_is_equal(pma, pma2); - isl_pw_multi_aff_free(pma2); - - return equal; -} - -/* Check that "pma" is obviously equal to the isl_pw_multi_aff - * represented by "str". - */ -static int pw_multi_aff_check_plain_equal(__isl_keep isl_pw_multi_aff *pma, - const char *str) -{ - int equal; - - equal = pw_multi_aff_plain_is_equal(pma, str); - if (equal < 0) - return -1; - if (!equal) - isl_die(isl_pw_multi_aff_get_ctx(pma), isl_error_unknown, - "result not as expected", return -1); return 0; } @@ -5419,7 +7521,7 @@ isl_basic_set *bset; isl_vertices *vertices; int ok = 1; - int n; + isl_size n; bset = isl_basic_set_read_from_str(ctx, vertices_tests[i].set); vertices = isl_basic_set_compute_vertices(bset); @@ -5432,13 +7534,159 @@ isl_vertices_free(vertices); isl_basic_set_free(bset); - if (!vertices) + if (n < 0) return -1; if (!ok) isl_die(ctx, isl_error_unknown, "unexpected vertices", return -1); + } + + return 0; +} + +/* Inputs for basic tests of unary operations on isl_union_map. + * "fn" is the function that is being tested. + * "arg" is a string description of the input. + * "res" is a string description of the expected result. + */ +static struct { + __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap); + const char *arg; + const char *res; +} umap_un_tests[] = { + { &isl_union_map_range_reverse, + "{ A[] -> [B[] -> C[]]; A[] -> B[]; A[0] -> N[B[1] -> B[2]] }", + "{ A[] -> [C[] -> B[]]; A[0] -> N[B[2] -> B[1]] }" }, + { &isl_union_map_range_reverse, + "{ A[] -> N[B[] -> C[]] }", + "{ A[] -> [C[] -> B[]] }" }, + { &isl_union_map_range_reverse, + "{ A[] -> N[B[x] -> B[y]] }", + "{ A[] -> N[B[*] -> B[*]] }" }, +}; + +/* Perform basic tests of unary operations on isl_union_map. + */ +static isl_stat test_un_union_map(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(umap_un_tests); ++i) { + const char *str; + isl_union_map *umap, *res; + isl_bool equal; + + str = umap_un_tests[i].arg; + umap = isl_union_map_read_from_str(ctx, str); + str = umap_un_tests[i].res; + res = isl_union_map_read_from_str(ctx, str); + umap = umap_un_tests[i].fn(umap); + equal = isl_union_map_is_equal(umap, res); + isl_union_map_free(umap); + isl_union_map_free(res); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(ctx, isl_error_unknown, + "unexpected result", return isl_stat_error); + } + + return isl_stat_ok; +} + +/* Inputs for basic tests of binary operations on isl_union_map. + * "fn" is the function that is being tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +static struct { + __isl_give isl_union_map *(*fn)(__isl_take isl_union_map *umap1, + __isl_take isl_union_map *umap2); + const char *arg1; + const char *arg2; + const char *res; +} umap_bin_tests[] = { + { &isl_union_map_intersect, + "[n] -> { A[i] -> [] : 0 <= i <= n; B[] -> [] }", + "[m] -> { A[i] -> [] : 0 <= i <= m; C[] -> [] }", + "[m, n] -> { A[i] -> [] : 0 <= i <= n and i <= m }" }, + { &isl_union_map_intersect_domain_factor_range, + "{ [A[i] -> B[i + 1]] -> C[i + 2] }", + "[N] -> { B[i] -> C[N] }", + "[N] -> { [A[N - 2] -> B[N - 1]] -> C[N] }" }, + { &isl_union_map_intersect_domain_factor_range, + "{ T[A[i] -> B[i + 1]] -> C[i + 2] }", + "[N] -> { B[i] -> C[N] }", + "[N] -> { T[A[N - 2] -> B[N - 1]] -> C[N] }" }, + { &isl_union_map_intersect_domain_factor_range, + "{ [A[i] -> B[i + 1]] -> C[i + 2] }", + "[N] -> { A[i] -> C[N] }", + "{ }" }, + { &isl_union_map_intersect_range_factor_domain, + "{ A[i] -> [B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> B[N] }", + "[N] -> { A[N - 1] -> [B[N] -> C[N + 1]] }" }, + { &isl_union_map_intersect_range_factor_domain, + "{ A[i] -> T[B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> B[N] }", + "[N] -> { A[N - 1] -> T[B[N] -> C[N + 1]] }" }, + { &isl_union_map_intersect_range_factor_domain, + "{ A[i] -> [B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> C[N] }", + "{ }" }, + { &isl_union_map_intersect_range_factor_range, + "{ A[i] -> [B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> C[N] }", + "[N] -> { A[N - 2] -> [B[N - 1] -> C[N]] }" }, + { &isl_union_map_intersect_range_factor_range, + "{ A[i] -> T[B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> C[N] }", + "[N] -> { A[N - 2] -> T[B[N - 1] -> C[N]] }" }, + { &isl_union_map_intersect_range_factor_range, + "{ A[i] -> [B[i + 1] -> C[i + 2]] }", + "[N] -> { A[i] -> B[N] }", + "{ }" }, +}; + +/* Perform basic tests of binary operations on isl_union_map. + */ +static isl_stat test_bin_union_map(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(umap_bin_tests); ++i) { + const char *str; + isl_union_map *umap1, *umap2, *res; + isl_bool equal; + + str = umap_bin_tests[i].arg1; + umap1 = isl_union_map_read_from_str(ctx, str); + str = umap_bin_tests[i].arg2; + umap2 = isl_union_map_read_from_str(ctx, str); + str = umap_bin_tests[i].res; + res = isl_union_map_read_from_str(ctx, str); + umap1 = umap_bin_tests[i].fn(umap1, umap2); + equal = isl_union_map_is_equal(umap1, res); + isl_union_map_free(umap1); + isl_union_map_free(res); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(ctx, isl_error_unknown, + "unexpected result", return isl_stat_error); } + + return isl_stat_ok; +} +/* Perform basic tests of operations on isl_union_map. + */ +static int test_union_map(isl_ctx *ctx) +{ + if (test_un_union_map(ctx) < 0) + return -1; + if (test_bin_union_map(ctx) < 0) + return -1; return 0; } @@ -5462,7 +7710,168 @@ return -1; if (!equal) isl_die(ctx, isl_error_unknown, "unexpected result", return -1); + + return 0; +} + +/* Inputs for basic tests of functions that select + * subparts of the domain of an isl_multi_union_pw_aff. + * "fn" is the function that is tested. + * "arg" is a string description of the input. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_union_set *(*fn)( + __isl_take isl_multi_union_pw_aff *mupa); + const char *arg; + const char *res; +} un_locus_tests[] = { + { &isl_multi_union_pw_aff_zero_union_set, + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", + "{ A[0,j]; B[0,j] }" }, + { &isl_multi_union_pw_aff_zero_union_set, + "F[{ A[i,j] -> [i-j]; B[i,j] -> [i-j] : i >= 0 }]", + "{ A[i,i]; B[i,i] : i >= 0 }" }, + { &isl_multi_union_pw_aff_zero_union_set, + "(F[] : { A[i,j]; B[i,i] : i >= 0 })", + "{ A[i,j]; B[i,i] : i >= 0 }" }, +}; + +/* Perform some basic tests of functions that select + * subparts of the domain of an isl_multi_union_pw_aff. + */ +static int test_un_locus(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_union_set *uset, *res; + isl_multi_union_pw_aff *mupa; + + for (i = 0; i < ARRAY_SIZE(un_locus_tests); ++i) { + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + un_locus_tests[i].arg); + res = isl_union_set_read_from_str(ctx, un_locus_tests[i].res); + uset = un_locus_tests[i].fn(mupa); + ok = isl_union_set_is_equal(uset, res); + isl_union_set_free(uset); + isl_union_set_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} + +/* Inputs for basic tests of functions that select + * subparts of an isl_union_map based on a relation + * specified by an isl_multi_union_pw_aff. + * "fn" is the function that is tested. + * "arg1" and "arg2" are string descriptions of the inputs. + * "res" is a string description of the expected result. + */ +struct { + __isl_give isl_union_map *(*fn)( + __isl_take isl_union_map *umap, + __isl_take isl_multi_union_pw_aff *mupa); + const char *arg1; + const char *arg2; + const char *res; +} bin_locus_tests[] = { + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", + "{ A[i,j] -> B[i,j'] }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " + "{ A[i,j] -> [j]; B[i,j] -> [j] }]", + "{ A[i,j] -> B[i,j] }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }]", + "{ A[i,j] -> B[i,j'] }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i]; C[i,j] -> [0] }]", + "{ A[i,j] -> B[i,j']; A[0,j] -> C[i',j'] }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "F[{ A[i,j] -> [i] : i > j; B[i,j] -> [i] }]", + "{ A[i,j] -> B[i,j'] : i > j }" }, + { &isl_union_map_lex_lt_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " + "{ A[i,j] -> [j]; B[i,j] -> [j] }]", + "{ A[i,j] -> B[i',j'] : i,j << i',j' }" }, + { &isl_union_map_lex_gt_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "F[{ A[i,j] -> [i]; B[i,j] -> [i] }, " + "{ A[i,j] -> [j]; B[i,j] -> [j] }]", + "{ A[i,j] -> B[i',j'] : i,j >> i',j' }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j']; A[i,j] -> C[i',j'] }", + "(F[] : { A[i,j]; B[i,j] })", + "{ A[i,j] -> B[i',j'] }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "(F[] : { A[i,j] : i > j; B[i,j] : i < j })", + "{ A[i,j] -> B[i',j'] : i > j and i' < j' }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "[N] -> { A[i,j] -> B[i',j'] : i,i' <= N }", + "(F[] : { A[i,j] : i > j; B[i,j] : i < j })", + "[N] -> { A[i,j] -> B[i',j'] : i > j and i' < j' and i,i' <= N }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "[N] -> (F[] : { A[i,j] : i < N; B[i,j] : i < N })", + "[N] -> { A[i,j] -> B[i',j'] : i,i' < N }" }, + { &isl_union_map_eq_at_multi_union_pw_aff, + "{ A[i,j] -> B[i',j'] }", + "[N] -> (F[] : { : N >= 0 })", + "[N] -> { A[i,j] -> B[i',j'] : N >= 0 }" }, +}; + +/* Perform some basic tests of functions that select + * subparts of an isl_union_map based on a relation + * specified by an isl_multi_union_pw_aff. + */ +static int test_bin_locus(isl_ctx *ctx) +{ + int i; + isl_bool ok; + isl_union_map *umap, *res; + isl_multi_union_pw_aff *mupa; + + for (i = 0; i < ARRAY_SIZE(bin_locus_tests); ++i) { + umap = isl_union_map_read_from_str(ctx, + bin_locus_tests[i].arg1); + mupa = isl_multi_union_pw_aff_read_from_str(ctx, + bin_locus_tests[i].arg2); + res = isl_union_map_read_from_str(ctx, bin_locus_tests[i].res); + umap = bin_locus_tests[i].fn(umap, mupa); + ok = isl_union_map_is_equal(umap, res); + isl_union_map_free(umap); + isl_union_map_free(res); + if (ok < 0) + return -1; + if (!ok) + isl_die(ctx, isl_error_unknown, + "unexpected result", return -1); + } + + return 0; +} +/* Perform basic locus tests. + */ +static int test_locus(isl_ctx *ctx) +{ + if (test_un_locus(ctx) < 0) + return -1; + if (test_bin_locus(ctx) < 0) + return -1; return 0; } @@ -5519,17 +7928,102 @@ return -1; if (!ok) isl_die(ctx, isl_error_unknown, "expecting NaN", return -1); + + return 0; +} + +/* Check that a polynomial (without local variables) can be evaluated + * in a rational point. + */ +static isl_stat test_eval_3(isl_ctx *ctx) +{ + isl_pw_qpolynomial *pwqp; + isl_point *pnt; + isl_val *v; + isl_stat r; + + pwqp = isl_pw_qpolynomial_read_from_str(ctx, "{ [x] -> x^2 }"); + pnt = isl_point_zero(isl_pw_qpolynomial_get_domain_space(pwqp)); + v = isl_val_read_from_str(ctx, "1/2"); + pnt = isl_point_set_coordinate_val(pnt, isl_dim_set, 0, v); + v = isl_pw_qpolynomial_eval(pwqp, pnt); + r = val_check_equal(v, "1/4"); + isl_val_free(v); + return r; +} + +/* Inputs for isl_pw_aff_eval test. + * "f" is the affine function. + * "p" is the point where the function should be evaluated. + * "res" is the expected result. + */ +struct { + const char *f; + const char *p; + const char *res; +} aff_eval_tests[] = { + { "{ [i] -> [2 * i] }", "{ [4] }", "8" }, + { "{ [i] -> [2 * i] }", "{ [x] : false }", "NaN" }, + { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [0] }", "0" }, + { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [1] }", "1" }, + { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [2] }", "3" }, + { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [3] }", "5" }, + { "{ [i] -> [i + floor(i/2) + floor(i/3)] }", "{ [4] }", "7" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [0] }", "0" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [1] }", "0" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [2] }", "0" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [3] }", "0" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [4] }", "1" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [6] }", "1" }, + { "{ [i] -> [floor((3 * floor(i/2))/5)] }", "{ [8] }", "2" }, + { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [4] }", "4" }, + { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [-2] }", "2" }, + { "{ [i] -> [i] : i > 0; [i] -> [-i] : i < 0 }", "{ [0] }", "NaN" }, + { "[N] -> { [2 * N] }", "[N] -> { : N = 4 }", "8" }, + { "{ [i, j] -> [(i + j)/2] }", "{ [1, 1] }", "1" }, + { "{ [i, j] -> [(i + j)/2] }", "{ [1, 2] }", "3/2" }, + { "{ [i] -> [i] : i mod 2 = 0 }", "{ [4] }", "4" }, + { "{ [i] -> [i] : i mod 2 = 0 }", "{ [3] }", "NaN" }, + { "{ [i] -> [i] : i mod 2 = 0 }", "{ [x] : false }", "NaN" }, +}; + +/* Perform basic isl_pw_aff_eval tests. + */ +static int test_eval_aff(isl_ctx *ctx) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(aff_eval_tests); ++i) { + isl_stat r; + isl_pw_aff *pa; + isl_set *set; + isl_point *pnt; + isl_val *v; + + pa = isl_pw_aff_read_from_str(ctx, aff_eval_tests[i].f); + set = isl_set_read_from_str(ctx, aff_eval_tests[i].p); + pnt = isl_set_sample_point(set); + v = isl_pw_aff_eval(pa, pnt); + r = val_check_equal(v, aff_eval_tests[i].res); + isl_val_free(v); + if (r < 0) + return -1; + } return 0; } -/* Perform basic polynomial evaluation tests. +/* Perform basic evaluation tests. */ static int test_eval(isl_ctx *ctx) { if (test_eval_1(ctx) < 0) return -1; if (test_eval_2(ctx) < 0) + return -1; + if (test_eval_3(ctx) < 0) + return -1; + if (test_eval_aff(ctx) < 0) return -1; return 0; } @@ -5578,6 +8072,62 @@ return 0; } +/* Check that an isl_multi_aff is printed using a consistent space. + */ +static isl_stat test_output_ma(isl_ctx *ctx) +{ + char *str; + isl_bool equal; + isl_aff *aff; + isl_multi_aff *ma, *ma2; + + ma = isl_multi_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }"); + aff = isl_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }"); + ma = isl_multi_aff_set_aff(ma, 0, aff); + str = isl_multi_aff_to_str(ma); + ma2 = isl_multi_aff_read_from_str(ctx, str); + free(str); + equal = isl_multi_aff_plain_is_equal(ma, ma2); + isl_multi_aff_free(ma2); + isl_multi_aff_free(ma); + + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(ctx, isl_error_unknown, "bad conversion", + return isl_stat_error); + + return isl_stat_ok; +} + +/* Check that an isl_multi_pw_aff is printed using a consistent space. + */ +static isl_stat test_output_mpa(isl_ctx *ctx) +{ + char *str; + isl_bool equal; + isl_pw_aff *pa; + isl_multi_pw_aff *mpa, *mpa2; + + mpa = isl_multi_pw_aff_read_from_str(ctx, "{ [a, b] -> [a + b] }"); + pa = isl_pw_aff_read_from_str(ctx, "{ [c, d] -> [c + d] }"); + mpa = isl_multi_pw_aff_set_pw_aff(mpa, 0, pa); + str = isl_multi_pw_aff_to_str(mpa); + mpa2 = isl_multi_pw_aff_read_from_str(ctx, str); + free(str); + equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2); + isl_multi_pw_aff_free(mpa2); + isl_multi_pw_aff_free(mpa); + + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(ctx, isl_error_unknown, "bad conversion", + return isl_stat_error); + + return isl_stat_ok; +} + int test_output(isl_ctx *ctx) { char *s; @@ -5587,7 +8137,11 @@ int equal; if (test_output_set(ctx) < 0) + return -1; + if (test_output_ma(ctx) < 0) return -1; + if (test_output_mpa(ctx) < 0) + return -1; str = "[x] -> { [1] : x % 4 <= 2; [2] : x = 3 }"; pa = isl_pw_aff_read_from_str(ctx, str); @@ -5745,6 +8299,25 @@ map = isl_map_read_from_str(ctx, str); map = isl_map_eliminate(map, isl_dim_out, 0, 1); equal = map_check_equal(map, "{ [i] -> [j] : exists a : i = 2a }"); + isl_map_free(map); + if (equal < 0) + return -1; + + return 0; +} + +/* Check basic functionality of isl_map_deltas_map. + */ +static int test_deltas_map(isl_ctx *ctx) +{ + const char *str; + isl_map *map; + int equal; + + str = "{ A[i] -> A[i + 1] }"; + map = isl_map_read_from_str(ctx, str); + map = isl_map_deltas_map(map); + equal = map_check_equal(map, "{ [A[i] -> A[i + 1]] -> A[1] }"); isl_map_free(map); if (equal < 0) return -1; @@ -5780,7 +8353,7 @@ return res; } -int test_align_parameters(isl_ctx *ctx) +static int test_align_parameters_1(isl_ctx *ctx) { const char *str; isl_space *space; @@ -5801,7 +8374,102 @@ isl_multi_aff_free(ma1); isl_multi_aff_free(ma2); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "result not as expected", return -1); + + return 0; +} + +/* Check the isl_multi_*_from_*_list operation in case inputs + * have unaligned parameters. + * In particular, older versions of isl would simply fail + * (without printing any error message). + */ +static isl_stat test_align_parameters_2(isl_ctx *ctx) +{ + isl_space *space; + isl_map *map; + isl_aff *aff; + isl_multi_aff *ma; + + map = isl_map_read_from_str(ctx, "{ A[] -> M[x] }"); + space = isl_map_get_space(map); + isl_map_free(map); + + aff = isl_aff_read_from_str(ctx, "[N] -> { A[] -> [N] }"); + ma = isl_multi_aff_from_aff_list(space, isl_aff_list_from_aff(aff)); + isl_multi_aff_free(ma); + + if (!ma) + return isl_stat_error; + return isl_stat_ok; +} + +/* Perform basic parameter alignment tests. + */ +static int test_align_parameters(isl_ctx *ctx) +{ + if (test_align_parameters_1(ctx) < 0) + return -1; + if (test_align_parameters_2(ctx) < 0) + return -1; + + return 0; +} + +/* Check that isl_*_drop_unused_params actually drops the unused parameters + * by comparing the result using isl_*_plain_is_equal. + * Note that this assumes that isl_*_plain_is_equal does not consider + * objects that only differ by unused parameters to be equal. + */ +int test_drop_unused_parameters(isl_ctx *ctx) +{ + const char *str_with, *str_without; + isl_basic_set *bset1, *bset2; + isl_set *set1, *set2; + isl_pw_aff *pwa1, *pwa2; + int equal; + + str_with = "[n, m, o] -> { [m] }"; + str_without = "[m] -> { [m] }"; + + bset1 = isl_basic_set_read_from_str(ctx, str_with); + bset2 = isl_basic_set_read_from_str(ctx, str_without); + bset1 = isl_basic_set_drop_unused_params(bset1); + equal = isl_basic_set_plain_is_equal(bset1, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "result not as expected", return -1); + + set1 = isl_set_read_from_str(ctx, str_with); + set2 = isl_set_read_from_str(ctx, str_without); + set1 = isl_set_drop_unused_params(set1); + equal = isl_set_plain_is_equal(set1, set2); + isl_set_free(set1); + isl_set_free(set2); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "result not as expected", return -1); + pwa1 = isl_pw_aff_read_from_str(ctx, str_with); + pwa2 = isl_pw_aff_read_from_str(ctx, str_without); + pwa1 = isl_pw_aff_drop_unused_params(pwa1); + equal = isl_pw_aff_plain_is_equal(pwa1, pwa2); + isl_pw_aff_free(pwa1); + isl_pw_aff_free(pwa2); + if (equal < 0) return -1; if (!equal) @@ -5815,6 +8483,7 @@ { isl_id *a, *b, *c, *d, *id; isl_id_list *list; + isl_size n; int ok; a = isl_id_alloc(ctx, "a", NULL); @@ -5829,9 +8498,10 @@ list = isl_id_list_add(list, d); list = isl_id_list_drop(list, 1, 1); - if (!list) + n = isl_id_list_n_id(list); + if (n < 0) return -1; - if (isl_id_list_n_id(list) != 3) { + if (n != 3) { isl_id_list_free(list); isl_die(ctx, isl_error_unknown, "unexpected number of elements in list", return -1); @@ -5854,6 +8524,30 @@ "unexpected elements in list", return -1); return 0; +} + +/* Check the conversion from an isl_multi_aff to an isl_basic_set. + */ +static isl_stat test_ma_conversion(isl_ctx *ctx) +{ + const char *str; + isl_bool equal; + isl_multi_aff *ma; + isl_basic_set *bset1, *bset2; + + str = "[N] -> { A[0, N + 1] }"; + ma = isl_multi_aff_read_from_str(ctx, str); + bset1 = isl_basic_set_read_from_str(ctx, str); + bset2 = isl_basic_set_from_multi_aff(ma); + equal = isl_basic_set_is_equal(bset1, bset2); + isl_basic_set_free(bset1); + isl_basic_set_free(bset2); + if (equal < 0) + return isl_stat_error; + if (!equal) + isl_die(ctx, isl_error_unknown, "bad conversion", + return isl_stat_error); + return isl_stat_ok; } const char *set_conversion_tests[] = { @@ -5925,6 +8619,96 @@ equal = isl_map_is_equal(map1, map2); isl_map_free(map1); isl_map_free(map2); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, "bad conversion", + return -1); + } + + return 0; +} + +/* Descriptions of isl_pw_multi_aff objects for testing conversion + * to isl_multi_pw_aff and back. + */ +const char *mpa_conversion_tests[] = { + "{ [x] -> A[x] }", + "{ [x] -> A[x] : x >= 0 }", + "{ [x] -> A[x] : x >= 0; [x] -> A[-x] : x < 0 }", + "{ [x] -> A[x, x + 1] }", + "{ [x] -> A[] }", + "{ [x] -> A[] : x >= 0 }", +}; + +/* Check that conversion from isl_pw_multi_aff to isl_multi_pw_aff and + * back to isl_pw_multi_aff preserves the original meaning. + */ +static int test_mpa_conversion(isl_ctx *ctx) +{ + int i; + isl_pw_multi_aff *pma1, *pma2; + isl_multi_pw_aff *mpa; + int equal; + + for (i = 0; i < ARRAY_SIZE(mpa_conversion_tests); ++i) { + const char *str; + str = mpa_conversion_tests[i]; + pma1 = isl_pw_multi_aff_read_from_str(ctx, str); + pma2 = isl_pw_multi_aff_copy(pma1); + mpa = isl_multi_pw_aff_from_pw_multi_aff(pma1); + pma1 = isl_pw_multi_aff_from_multi_pw_aff(mpa); + equal = isl_pw_multi_aff_plain_is_equal(pma1, pma2); + isl_pw_multi_aff_free(pma1); + isl_pw_multi_aff_free(pma2); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, "bad conversion", + return -1); + } + + return 0; +} + +/* Descriptions of union maps that should be convertible + * to an isl_multi_union_pw_aff. + */ +const char *umap_mupa_conversion_tests[] = { + "{ [a, b, c, d] -> s0[a, b, e, f] : " + "exists (e0 = [(a - 2c)/3], e1 = [(-4 + b - 5d)/9], " + "e2 = [(-d + f)/9]: 3e0 = a - 2c and 9e1 = -4 + b - 5d and " + "9e2 = -d + f and f >= 0 and f <= 8 and 9e >= -5 - 2a and " + "9e <= -2 - 2a) }", + "{ [a, b] -> [c] : exists (e0 = floor((-a - b + c)/5): " + "5e0 = -a - b + c and c >= -a and c <= 4 - a) }", + "{ [a, b] -> [c] : exists d : 18 * d = -3 - a + 2c and 1 <= c <= 3 }", + "{ A[] -> B[0]; C[] -> B[1] }", + "{ A[] -> B[]; C[] -> B[] }", +}; + +/* Check that converting from isl_union_map to isl_multi_union_pw_aff and back + * to isl_union_map produces the original isl_union_map. + */ +static int test_union_map_mupa_conversion(isl_ctx *ctx) +{ + int i; + isl_union_map *umap1, *umap2; + isl_multi_union_pw_aff *mupa; + int equal; + + for (i = 0; i < ARRAY_SIZE(umap_mupa_conversion_tests); ++i) { + const char *str; + str = umap_mupa_conversion_tests[i]; + umap1 = isl_union_map_read_from_str(ctx, str); + umap2 = isl_union_map_copy(umap1); + mupa = isl_multi_union_pw_aff_from_union_map(umap2); + umap2 = isl_union_map_from_multi_union_pw_aff(mupa); + equal = isl_union_map_is_equal(umap1, umap2); + isl_union_map_free(umap1); + isl_union_map_free(umap2); if (equal < 0) return -1; @@ -5938,10 +8722,16 @@ static int test_conversion(isl_ctx *ctx) { + if (test_ma_conversion(ctx) < 0) + return -1; if (test_set_conversion(ctx) < 0) return -1; if (test_map_conversion(ctx) < 0) + return -1; + if (test_mpa_conversion(ctx) < 0) return -1; + if (test_union_map_mupa_conversion(ctx) < 0) + return -1; return 0; } @@ -6253,7 +9043,8 @@ isl_union_map *schedule; isl_union_set *uset; isl_set *set; - int empty; + isl_bool empty; + isl_size n; char name[] = "d0"; ctx = isl_ast_build_get_ctx(build); @@ -6271,10 +9062,11 @@ schedule = isl_ast_build_get_schedule(build); uset = isl_union_map_range(schedule); - if (!uset) - return NULL; - if (isl_union_set_n_set(uset) != 1) { + n = isl_union_set_n_set(uset); + if (n != 1) { isl_union_set_free(uset); + if (n < 0) + return NULL; isl_die(ctx, isl_error_unknown, "expecting single range space", return NULL); } @@ -6610,7 +9402,7 @@ build = isl_ast_build_alloc(ctx); expr = isl_ast_build_expr_from_pw_aff(build, pa); is_min = isl_ast_expr_get_type(expr) == isl_ast_expr_op && - isl_ast_expr_get_op_type(expr) == isl_ast_op_min; + isl_ast_expr_get_op_type(expr) == isl_ast_expr_op_min; isl_ast_build_free(build); isl_ast_expr_free(expr); @@ -6674,7 +9466,7 @@ /* Check that we can properly parse multi piecewise affine expressions * where the piecewise affine expressions have different domains. */ -static int test_multi_pw_aff(isl_ctx *ctx) +static int test_multi_pw_aff_1(isl_ctx *ctx) { const char *str; isl_set *dom, *dom2; @@ -6715,7 +9507,88 @@ if (equal_domain) isl_die(ctx, isl_error_unknown, "domains unexpectedly equal", return -1); + + return 0; +} + +/* Check that the dimensions in the explicit domain + * of a multi piecewise affine expression are properly + * taken into account. + */ +static int test_multi_pw_aff_2(isl_ctx *ctx) +{ + const char *str; + isl_bool involves1, involves2, involves3, equal; + isl_multi_pw_aff *mpa, *mpa1, *mpa2; + + str = "{ A[x,y] -> B[] : x >= y }"; + mpa = isl_multi_pw_aff_read_from_str(ctx, str); + involves1 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 2); + mpa1 = isl_multi_pw_aff_copy(mpa); + + mpa = isl_multi_pw_aff_insert_dims(mpa, isl_dim_in, 0, 1); + involves2 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 0, 1); + involves3 = isl_multi_pw_aff_involves_dims(mpa, isl_dim_in, 1, 2); + str = "{ [a,x,y] -> B[] : x >= y }"; + mpa2 = isl_multi_pw_aff_read_from_str(ctx, str); + equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa2); + isl_multi_pw_aff_free(mpa2); + mpa = isl_multi_pw_aff_drop_dims(mpa, isl_dim_in, 0, 1); + mpa = isl_multi_pw_aff_set_tuple_name(mpa, isl_dim_in, "A"); + if (equal >= 0 && equal) + equal = isl_multi_pw_aff_plain_is_equal(mpa, mpa1); + isl_multi_pw_aff_free(mpa1); + isl_multi_pw_aff_free(mpa); + + if (involves1 < 0 || involves2 < 0 || involves3 < 0 || equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, + "incorrect result of dimension insertion/removal", + return isl_stat_error); + if (!involves1 || involves2 || !involves3) + isl_die(ctx, isl_error_unknown, + "incorrect characterization of involved dimensions", + return isl_stat_error); + + return 0; +} + +/* Check that isl_multi_union_pw_aff_multi_val_on_domain + * sets the explicit domain of a zero-dimensional result, + * such that it can be converted to an isl_union_map. + */ +static isl_stat test_multi_pw_aff_3(isl_ctx *ctx) +{ + isl_space *space; + isl_union_set *dom; + isl_multi_val *mv; + isl_multi_union_pw_aff *mupa; + isl_union_map *umap; + + dom = isl_union_set_read_from_str(ctx, "{ A[]; B[] }"); + space = isl_union_set_get_space(dom); + mv = isl_multi_val_zero(isl_space_set_from_params(space)); + mupa = isl_multi_union_pw_aff_multi_val_on_domain(dom, mv); + umap = isl_union_map_from_multi_union_pw_aff(mupa); + isl_union_map_free(umap); + if (!umap) + return isl_stat_error; + + return isl_stat_ok; +} + +/* Perform some tests on multi piecewise affine expressions. + */ +static int test_multi_pw_aff(isl_ctx *ctx) +{ + if (test_multi_pw_aff_1(ctx) < 0) + return -1; + if (test_multi_pw_aff_2(ctx) < 0) + return -1; + if (test_multi_pw_aff_3(ctx) < 0) + return -1; return 0; } @@ -6861,6 +9734,50 @@ return 0; } +/* Check that a zero-dimensional prefix schedule keeps track + * of the domain and outer filters. + */ +static int test_schedule_tree_prefix(isl_ctx *ctx) +{ + const char *str; + isl_bool equal; + isl_union_set *uset; + isl_union_set_list *filters; + isl_multi_union_pw_aff *mupa, *mupa2; + isl_schedule_node *node; + + str = "{ S1[i,j] : 0 <= i,j < 10; S2[i,j] : 0 <= i,j < 10 }"; + uset = isl_union_set_read_from_str(ctx, str); + node = isl_schedule_node_from_domain(uset); + node = isl_schedule_node_child(node, 0); + + str = "{ S1[i,j] : i > j }"; + uset = isl_union_set_read_from_str(ctx, str); + filters = isl_union_set_list_from_union_set(uset); + str = "{ S1[i,j] : i <= j; S2[i,j] }"; + uset = isl_union_set_read_from_str(ctx, str); + filters = isl_union_set_list_add(filters, uset); + node = isl_schedule_node_insert_sequence(node, filters); + + node = isl_schedule_node_child(node, 0); + node = isl_schedule_node_child(node, 0); + mupa = isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(node); + str = "([] : { S1[i,j] : i > j })"; + mupa2 = isl_multi_union_pw_aff_read_from_str(ctx, str); + equal = isl_multi_union_pw_aff_plain_is_equal(mupa, mupa2); + isl_multi_union_pw_aff_free(mupa2); + isl_multi_union_pw_aff_free(mupa); + isl_schedule_node_free(node); + + if (equal < 0) + return -1; + if (!equal) + isl_die(ctx, isl_error_unknown, "unexpected prefix schedule", + return -1); + + return 0; +} + /* Check that the reaching domain elements and the prefix schedule * at a leaf node are the same before and after grouping. */ @@ -7277,12 +10194,13 @@ */ static isl_stat check_pairwise_disjoint(__isl_keep isl_basic_set_list *list) { - int i, j, n; + int i, j; + isl_size n; - if (!list) + n = isl_basic_set_list_n_basic_set(list); + if (n < 0) return isl_stat_error; - n = isl_basic_set_list_n_basic_set(list); for (i = 0; i < n; ++i) { isl_basic_set *bset_i; @@ -7358,12 +10276,14 @@ { "conversion", &test_conversion }, { "list", &test_list }, { "align parameters", &test_align_parameters }, + { "drop unused parameters", &test_drop_unused_parameters }, { "preimage", &test_preimage }, { "pullback", &test_pullback }, { "AST", &test_ast }, { "AST build", &test_ast_build }, { "AST generation", &test_ast_gen }, { "eliminate", &test_eliminate }, + { "deltas_map", &test_deltas_map }, { "residue class", &test_residue_class }, { "div", &test_div }, { "slice", &test_slice }, @@ -7382,12 +10302,16 @@ { "schedule (whole component)", &test_schedule_whole }, { "schedule (incremental)", &test_schedule_incremental }, { "schedule tree", &test_schedule_tree }, + { "schedule tree prefix", &test_schedule_tree_prefix }, { "schedule tree grouping", &test_schedule_tree_group }, { "tile", &test_tile }, + { "union map", &test_union_map }, { "union_pw", &test_union_pw }, + { "locus", &test_locus }, { "eval", &test_eval }, { "parse", &test_parse }, { "single-valued", &test_sv }, + { "recession cone", &test_recession_cone }, { "affine hull", &test_affine_hull }, { "simple_hull", &test_simple_hull }, { "coalesce", &test_coalesce }, @@ -7400,7 +10324,10 @@ { "gist", &test_gist }, { "piecewise quasi-polynomials", &test_pwqp }, { "lift", &test_lift }, + { "bind parameters", &test_bind }, + { "unbind parameters", &test_unbind }, { "bound", &test_bound }, + { "get lists", &test_get_list }, { "union", &test_union }, { "split periods", &test_split_periods }, { "lexicographic order", &test_lex }, @@ -7413,6 +10340,7 @@ { "map application", &test_application }, { "convex hull", &test_convex_hull }, { "transitive closure", &test_closure }, + { "isl_bool", &test_isl_bool}, }; int main(int argc, char **argv) diff --git a/gcc/isl/isl_transitive_closure.c b/gcc/isl/isl_transitive_closure.c index 6e1b4bb..f485680 100644 --- a/gcc/isl/isl_transitive_closure.c +++ a/gcc/isl/isl_transitive_closure.c @@ -20,10 +20,10 @@ #include #include -int isl_map_is_transitively_closed(__isl_keep isl_map *map) +isl_bool isl_map_is_transitively_closed(__isl_keep isl_map *map) { isl_map *map2; - int closed; + isl_bool closed; map2 = isl_map_apply_range(isl_map_copy(map), isl_map_copy(map)); closed = isl_map_is_subset(map2, map); @@ -32,10 +32,10 @@ return closed; } -int isl_union_map_is_transitively_closed(__isl_keep isl_union_map *umap) +isl_bool isl_union_map_is_transitively_closed(__isl_keep isl_union_map *umap) { isl_union_map *umap2; - int closed; + isl_bool closed; umap2 = isl_union_map_apply_range(isl_union_map_copy(umap), isl_union_map_copy(umap)); @@ -54,20 +54,24 @@ static __isl_give isl_map *set_path_length(__isl_take isl_map *map, int exactly, int length) { - isl_space *dim; + isl_space *space; struct isl_basic_map *bmap; - unsigned d; - unsigned nparam; + isl_size d; + isl_size nparam; + isl_size total; int k; isl_int *c; if (!map) return NULL; - dim = isl_map_get_space(map); - d = isl_space_dim(dim, isl_dim_in); - nparam = isl_space_dim(dim, isl_dim_param); - bmap = isl_basic_map_alloc_space(dim, 0, 1, 1); + space = isl_map_get_space(map); + d = isl_space_dim(space, isl_dim_in); + nparam = isl_space_dim(space, isl_dim_param); + total = isl_space_dim(space, isl_dim_all); + if (d < 0 || nparam < 0 || total < 0) + space = isl_space_free(space); + bmap = isl_basic_map_alloc_space(space, 0, 1, 1); if (exactly) { k = isl_basic_map_alloc_equality(bmap); if (k < 0) @@ -79,7 +83,7 @@ goto error; c = bmap->ineq[k]; } - isl_seq_clr(c, 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(c, 1 + total); isl_int_set_si(c[0], -length); isl_int_set_si(c[1 + nparam + d - 1], -1); isl_int_set_si(c[1 + nparam + d + d - 1], 1); @@ -111,10 +115,10 @@ * this coordinate to "map" and set the length of the path to * one. */ -static int check_power_exactness(__isl_take isl_map *map, +static isl_bool check_power_exactness(__isl_take isl_map *map, __isl_take isl_map *app) { - int exact; + isl_bool exact; isl_map *app_1; isl_map *app_2; @@ -166,17 +170,19 @@ * the length of the part. If we are only interested in the transitive * closure, then we can simply project out these coordinates first. */ -static int check_exactness(__isl_take isl_map *map, __isl_take isl_map *app, - int project) +static isl_bool check_exactness(__isl_take isl_map *map, + __isl_take isl_map *app, int project) { isl_map *test; - int exact; - unsigned d; + isl_bool exact; + isl_size d; if (!project) return check_power_exactness(map, app); d = isl_map_dim(map, isl_dim_in); + if (d < 0) + app = isl_map_free(app); app = set_path_length(app, 0, 1); app = isl_map_project_out(app, isl_dim_in, d, 1); app = isl_map_project_out(app, isl_dim_out, d, 1); @@ -215,23 +221,24 @@ * For any element in this relation, the number of steps taken * is equal to the difference in the final coordinates. */ -static __isl_give isl_map *path_along_steps(__isl_take isl_space *dim, +static __isl_give isl_map *path_along_steps(__isl_take isl_space *space, __isl_keep isl_mat *steps) { int i, j, k; struct isl_basic_map *path = NULL; - unsigned d; + isl_size d; unsigned n; - unsigned nparam; - - if (!dim || !steps) + isl_size nparam; + isl_size total; + + d = isl_space_dim(space, isl_dim_in); + nparam = isl_space_dim(space, isl_dim_param); + if (d < 0 || nparam < 0 || !steps) goto error; - d = isl_space_dim(dim, isl_dim_in); n = steps->n_row; - nparam = isl_space_dim(dim, isl_dim_param); - path = isl_basic_map_alloc_space(isl_space_copy(dim), n, d, n); + path = isl_basic_map_alloc_space(isl_space_copy(space), n, d, n); for (i = 0; i < n; ++i) { k = isl_basic_map_alloc_div(path); @@ -241,11 +248,14 @@ isl_int_set_si(path->div[k][0], 0); } + total = isl_basic_map_dim(path, isl_dim_all); + if (total < 0) + goto error; for (i = 0; i < d; ++i) { k = isl_basic_map_alloc_equality(path); if (k < 0) goto error; - isl_seq_clr(path->eq[k], 1 + isl_basic_map_total_dim(path)); + isl_seq_clr(path->eq[k], 1 + total); isl_int_set_si(path->eq[k][1 + nparam + i], 1); isl_int_set_si(path->eq[k][1 + nparam + d + i], -1); if (i == d - 1) @@ -261,17 +271,17 @@ k = isl_basic_map_alloc_inequality(path); if (k < 0) goto error; - isl_seq_clr(path->ineq[k], 1 + isl_basic_map_total_dim(path)); + isl_seq_clr(path->ineq[k], 1 + total); isl_int_set_si(path->ineq[k][1 + nparam + 2 * d + i], 1); } - isl_space_free(dim); + isl_space_free(space); path = isl_basic_map_simplify(path); path = isl_basic_map_finalize(path); return isl_map_from_basic_map(path); error: - isl_space_free(dim); + isl_space_free(space); isl_basic_map_free(path); return NULL; } @@ -287,9 +297,10 @@ static isl_bool parametric_constant_never_positive( __isl_keep isl_basic_set *bset, isl_int *c, int *div_purity) { - unsigned d; - unsigned n_div; - unsigned nparam; + isl_size d; + isl_size n_div; + isl_size nparam; + isl_size total; int i; int k; isl_bool empty; @@ -297,6 +308,9 @@ n_div = isl_basic_set_dim(bset, isl_dim_div); d = isl_basic_set_dim(bset, isl_dim_set); nparam = isl_basic_set_dim(bset, isl_dim_param); + total = isl_basic_set_dim(bset, isl_dim_all); + if (n_div < 0 || d < 0 || nparam < 0 || total < 0) + return isl_bool_error; bset = isl_basic_set_copy(bset); bset = isl_basic_set_cow(bset); @@ -304,7 +318,7 @@ k = isl_basic_set_alloc_inequality(bset); if (k < 0) goto error; - isl_seq_clr(bset->ineq[k], 1 + isl_basic_set_total_dim(bset)); + isl_seq_clr(bset->ineq[k], 1 + total); isl_seq_cpy(bset->ineq[k], c, 1 + nparam); for (i = 0; i < n_div; ++i) { if (div_purity[i] != PURE_PARAM) @@ -332,9 +346,9 @@ static int purity(__isl_keep isl_basic_set *bset, isl_int *c, int *div_purity, int eq) { - unsigned d; - unsigned n_div; - unsigned nparam; + isl_size d; + isl_size n_div; + isl_size nparam; isl_bool empty; int i; int p = 0, v = 0; @@ -342,6 +356,8 @@ n_div = isl_basic_set_dim(bset, isl_dim_div); d = isl_basic_set_dim(bset, isl_dim_set); nparam = isl_basic_set_dim(bset, isl_dim_param); + if (n_div < 0 || d < 0 || nparam < 0) + return -1; for (i = 0; i < n_div; ++i) { if (isl_int_is_zero(c[1 + nparam + d + i])) @@ -377,16 +393,15 @@ { int i, j; int *div_purity; - unsigned d; - unsigned n_div; - unsigned nparam; - - if (!bset) - return NULL; + isl_size d; + isl_size n_div; + isl_size nparam; n_div = isl_basic_set_dim(bset, isl_dim_div); d = isl_basic_set_dim(bset, isl_dim_set); nparam = isl_basic_set_dim(bset, isl_dim_param); + if (n_div < 0 || d < 0 || nparam < 0) + return NULL; div_purity = isl_alloc_array(bset->ctx, int, n_div); if (n_div && !div_purity) @@ -417,33 +432,24 @@ return div_purity; } -/* Given a path with the as yet unconstrained length at position "pos", +/* Given a path with the as yet unconstrained length at div position "pos", * check if setting the length to zero results in only the identity * mapping. */ -static int empty_path_is_identity(__isl_keep isl_basic_map *path, unsigned pos) +static isl_bool empty_path_is_identity(__isl_keep isl_basic_map *path, + unsigned pos) { isl_basic_map *test = NULL; isl_basic_map *id = NULL; - int k; - int is_id; + isl_bool is_id; test = isl_basic_map_copy(path); - test = isl_basic_map_extend_constraints(test, 1, 0); - k = isl_basic_map_alloc_equality(test); - if (k < 0) - goto error; - isl_seq_clr(test->eq[k], 1 + isl_basic_map_total_dim(test)); - isl_int_set_si(test->eq[k][pos], 1); - test = isl_basic_map_gauss(test, NULL); + test = isl_basic_map_fix_si(test, isl_dim_div, pos, 0); id = isl_basic_map_identity(isl_basic_map_get_space(path)); is_id = isl_basic_map_is_equal(test, id); isl_basic_map_free(test); isl_basic_map_free(id); return is_id; -error: - isl_basic_map_free(test); - return -1; } /* If any of the constraints is found to be impure then this function @@ -460,9 +466,12 @@ int i, k; int n = eq ? delta->n_eq : delta->n_ineq; isl_int **delta_c = eq ? delta->eq : delta->ineq; - unsigned n_div; + isl_size n_div, total; n_div = isl_basic_set_dim(delta, isl_dim_div); + total = isl_basic_map_dim(path, isl_dim_all); + if (n_div < 0 || total < 0) + return isl_basic_map_free(path); for (i = 0; i < n; ++i) { isl_int *path_c; @@ -486,7 +495,7 @@ goto error; path_c = path->ineq[k]; } - isl_seq_clr(path_c, 1 + isl_basic_map_total_dim(path)); + isl_seq_clr(path_c, 1 + total); if (p == PURE_VAR) { isl_seq_cpy(path_c + off, delta_c[i] + 1 + nparam, d); @@ -563,25 +572,26 @@ * * to the constructed relation. */ -static __isl_give isl_map *path_along_delta(__isl_take isl_space *dim, +static __isl_give isl_map *path_along_delta(__isl_take isl_space *space, __isl_take isl_basic_set *delta) { isl_basic_map *path = NULL; - unsigned d; - unsigned n_div; - unsigned nparam; + isl_size d; + isl_size n_div; + isl_size nparam; + isl_size total; unsigned off; int i, k; - int is_id; + isl_bool is_id; int *div_purity = NULL; int impurity = 0; - if (!delta) - goto error; n_div = isl_basic_set_dim(delta, isl_dim_div); d = isl_basic_set_dim(delta, isl_dim_set); nparam = isl_basic_set_dim(delta, isl_dim_param); - path = isl_basic_map_alloc_space(isl_space_copy(dim), n_div + d + 1, + if (n_div < 0 || d < 0 || nparam < 0) + goto error; + path = isl_basic_map_alloc_space(isl_space_copy(space), n_div + d + 1, d + 1 + delta->n_eq, delta->n_eq + delta->n_ineq + 1); off = 1 + nparam + 2 * (d + 1) + n_div; @@ -592,11 +602,14 @@ isl_int_set_si(path->div[k][0], 0); } + total = isl_basic_map_dim(path, isl_dim_all); + if (total < 0) + goto error; for (i = 0; i < d + 1; ++i) { k = isl_basic_map_alloc_equality(path); if (k < 0) goto error; - isl_seq_clr(path->eq[k], 1 + isl_basic_map_total_dim(path)); + isl_seq_clr(path->eq[k], 1 + total); isl_int_set_si(path->eq[k][1 + nparam + i], 1); isl_int_set_si(path->eq[k][1 + nparam + d + 1 + i], -1); isl_int_set_si(path->eq[k][off + i], 1); @@ -611,11 +624,11 @@ path = add_delta_constraints(path, delta, off, nparam, d, div_purity, 0, &impurity); if (impurity) { - isl_space *dim = isl_basic_set_get_space(delta); + isl_space *space = isl_basic_set_get_space(delta); delta = isl_basic_set_project_out(delta, isl_dim_param, 0, nparam); delta = isl_basic_set_add_dims(delta, isl_dim_param, nparam); - delta = isl_basic_set_reset_space(delta, dim); + delta = isl_basic_set_reset_space(delta, space); if (!delta) goto error; path = isl_basic_map_extend_constraints(path, delta->n_eq, @@ -627,14 +640,14 @@ path = isl_basic_map_gauss(path, NULL); } - is_id = empty_path_is_identity(path, off + d); + is_id = empty_path_is_identity(path, n_div + d); if (is_id < 0) goto error; k = isl_basic_map_alloc_inequality(path); if (k < 0) goto error; - isl_seq_clr(path->ineq[k], 1 + isl_basic_map_total_dim(path)); + isl_seq_clr(path->ineq[k], 1 + total); if (!is_id) isl_int_set_si(path->ineq[k][0], -1); isl_int_set_si(path->ineq[k][off + d], 1); @@ -643,13 +656,13 @@ isl_basic_set_free(delta); path = isl_basic_map_finalize(path); if (is_id) { - isl_space_free(dim); + isl_space_free(space); return isl_map_from_basic_map(path); } - return isl_basic_map_union(path, isl_basic_map_identity(dim)); + return isl_basic_map_union(path, isl_basic_map_identity(space)); error: free(div_purity); - isl_space_free(dim); + isl_space_free(space); isl_basic_set_free(delta); isl_basic_map_free(path); return NULL; @@ -662,21 +675,25 @@ * * { [x,x_s] -> [y,y_s] : k = y_s - x_s > 0 } */ -static __isl_give isl_map *equate_parameter_to_length(__isl_take isl_space *dim, - unsigned param) +static __isl_give isl_map *equate_parameter_to_length( + __isl_take isl_space *space, unsigned param) { struct isl_basic_map *bmap; - unsigned d; - unsigned nparam; + isl_size d; + isl_size nparam; + isl_size total; int k; - d = isl_space_dim(dim, isl_dim_in); - nparam = isl_space_dim(dim, isl_dim_param); - bmap = isl_basic_map_alloc_space(dim, 0, 1, 1); + d = isl_space_dim(space, isl_dim_in); + nparam = isl_space_dim(space, isl_dim_param); + total = isl_space_dim(space, isl_dim_all); + if (d < 0 || nparam < 0 || total < 0) + space = isl_space_free(space); + bmap = isl_basic_map_alloc_space(space, 0, 1, 1); k = isl_basic_map_alloc_equality(bmap); if (k < 0) goto error; - isl_seq_clr(bmap->eq[k], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->eq[k], 1 + total); isl_int_set_si(bmap->eq[k][1 + param], -1); isl_int_set_si(bmap->eq[k][1 + nparam + d - 1], -1); isl_int_set_si(bmap->eq[k][1 + nparam + d + d - 1], 1); @@ -684,7 +701,7 @@ k = isl_basic_map_alloc_inequality(bmap); if (k < 0) goto error; - isl_seq_clr(bmap->ineq[k], 1 + isl_basic_map_total_dim(bmap)); + isl_seq_clr(bmap->ineq[k], 1 + total); isl_int_set_si(bmap->ineq[k][1 + param], 1); isl_int_set_si(bmap->ineq[k][0], -1); @@ -704,15 +721,17 @@ * does not contain any element with positive last coordinate (positive length) * and zero remaining coordinates (cycle). */ -static int is_acyclic(__isl_take isl_map *path) +static isl_bool is_acyclic(__isl_take isl_map *path) { int i; - int acyclic; - unsigned dim; + isl_bool acyclic; + isl_size dim; struct isl_set *delta; delta = isl_map_deltas(path); dim = isl_set_dim(delta, isl_dim_set); + if (dim < 0) + delta = isl_set_free(delta); for (i = 0; i < dim; ++i) { if (i == dim -1) delta = isl_set_lower_bound_si(delta, isl_dim_set, i, 1); @@ -751,20 +770,19 @@ * Since each of these paths performs an addition, composition is * symmetric and we can simply compose all resulting paths in any order. */ -static __isl_give isl_map *construct_extended_path(__isl_take isl_space *dim, +static __isl_give isl_map *construct_extended_path(__isl_take isl_space *space, __isl_keep isl_map *map, int *project) { struct isl_mat *steps = NULL; struct isl_map *path = NULL; - unsigned d; + isl_size d; int i, j, n; - - if (!map) - goto error; d = isl_map_dim(map, isl_dim_in); + if (d < 0) + goto error; - path = isl_map_identity(isl_space_copy(dim)); + path = isl_map_identity(isl_space_copy(space)); steps = isl_mat_alloc(map->ctx, map->n, d); if (!steps) @@ -792,7 +810,7 @@ if (j < d) { path = isl_map_apply_range(path, - path_along_delta(isl_space_copy(dim), delta)); + path_along_delta(isl_space_copy(space), delta)); path = isl_map_coalesce(path); } else { isl_basic_set_free(delta); @@ -803,7 +821,7 @@ if (n > 0) { steps->n_row = n; path = isl_map_apply_range(path, - path_along_steps(isl_space_copy(dim), steps)); + path_along_steps(isl_space_copy(space), steps)); } if (project && *project) { @@ -812,11 +830,11 @@ goto error; } - isl_space_free(dim); + isl_space_free(space); isl_mat_free(steps); return path; error: - isl_space_free(dim); + isl_space_free(space); isl_mat_free(steps); isl_map_free(path); return NULL; @@ -825,21 +843,7 @@ static isl_bool isl_set_overlaps(__isl_keep isl_set *set1, __isl_keep isl_set *set2) { - isl_set *i; - isl_bool no_overlap; - - if (!set1 || !set2) - return isl_bool_error; - - if (!isl_space_tuple_is_equal(set1->dim, isl_dim_set, - set2->dim, isl_dim_set)) - return isl_bool_false; - - i = isl_set_intersect(isl_set_copy(set1), isl_set_copy(set2)); - no_overlap = isl_set_is_empty(i); - isl_set_free(i); - - return isl_bool_not(no_overlap); + return isl_bool_not(isl_set_is_disjoint(set1, set2)); } /* Given a union of basic maps R = \cup_i R_i \subseteq D \times D @@ -862,13 +866,14 @@ * \sum_i k_i >= 1 } */ static __isl_give isl_map *construct_component(__isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project) + __isl_keep isl_map *map, isl_bool *exact, int project) { struct isl_set *domain = NULL; struct isl_set *range = NULL; struct isl_map *app = NULL; struct isl_map *path = NULL; isl_bool overlaps; + int check; domain = isl_map_domain(isl_map_copy(map)); domain = isl_set_coalesce(domain); @@ -892,11 +897,12 @@ app = isl_map_add_dims(app, isl_dim_in, 1); app = isl_map_add_dims(app, isl_dim_out, 1); + check = exact && *exact == isl_bool_true; path = construct_extended_path(isl_space_copy(dim), map, - exact && *exact ? &project : NULL); + check ? &project : NULL); app = isl_map_intersect(app, path); - if (exact && *exact && + if (check && (*exact = check_exactness(isl_map_copy(map), isl_map_copy(app), project)) < 0) goto error; @@ -914,17 +920,17 @@ * the final coordinates. */ static __isl_give isl_map *construct_projected_component( - __isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project) + __isl_take isl_space *space, + __isl_keep isl_map *map, isl_bool *exact, int project) { isl_map *app; unsigned d; - if (!dim) + if (!space) return NULL; - d = isl_space_dim(dim, isl_dim_in); + d = isl_space_dim(space, isl_dim_in); - app = construct_component(dim, map, exact, project); + app = construct_component(space, map, exact, project); if (project) { app = isl_map_project_out(app, isl_dim_in, d - 1, 1); app = isl_map_project_out(app, isl_dim_out, d - 1, 1); @@ -938,7 +944,8 @@ * domain and range equal to "dom". */ static __isl_give isl_map *q_closure(__isl_take isl_space *dim, - __isl_take isl_set *dom, __isl_keep isl_basic_map *bmap, int *exact) + __isl_take isl_set *dom, __isl_keep isl_basic_map *bmap, + isl_bool *exact) { int project = 1; isl_map *path; @@ -963,17 +970,16 @@ /* Check whether qc has any elements of length at least one * with domain and/or range outside of dom and ran. */ -static int has_spurious_elements(__isl_keep isl_map *qc, +static isl_bool has_spurious_elements(__isl_keep isl_map *qc, __isl_keep isl_set *dom, __isl_keep isl_set *ran) { isl_set *s; - int subset; - unsigned d; - - if (!qc || !dom || !ran) - return -1; + isl_bool subset; + isl_size d; d = isl_map_dim(qc, isl_dim_in); + if (d < 0 || !dom || !ran) + return isl_bool_error; qc = isl_map_copy(qc); qc = set_path_length(qc, 0, 1); @@ -987,17 +993,17 @@ goto error; if (!subset) { isl_map_free(qc); - return 1; + return isl_bool_true; } s = isl_map_range(qc); subset = isl_set_is_subset(s, ran); isl_set_free(s); - return subset < 0 ? -1 : !subset; + return isl_bool_not(subset); error: isl_map_free(qc); - return -1; + return isl_bool_error; } #define LEFT 2 @@ -1152,8 +1158,8 @@ * depending on whether left or right are NULL. */ static __isl_give isl_map *compute_incremental( - __isl_take isl_space *dim, __isl_keep isl_map *map, - int i, __isl_take isl_map *qc, int *left, int *right, int *exact) + __isl_take isl_space *space, __isl_keep isl_map *map, + int i, __isl_take isl_map *qc, int *left, int *right, isl_bool *exact) { isl_map *map_i; isl_map *tc; @@ -1164,7 +1170,7 @@ isl_assert(map->ctx, left || right, goto error); map_i = isl_map_from_basic_map(isl_basic_map_copy(map->p[i])); - tc = construct_projected_component(isl_space_copy(dim), map_i, + tc = construct_projected_component(isl_space_copy(space), map_i, exact, 1); isl_map_free(map_i); @@ -1172,7 +1178,7 @@ qc = isl_map_transitive_closure(qc, exact); if (!*exact) { - isl_space_free(dim); + isl_space_free(space); isl_map_free(tc); isl_map_free(qc); return isl_map_universe(isl_map_get_space(map)); @@ -1187,11 +1193,11 @@ qc = isl_map_apply_range(qc, rtc); qc = isl_map_union(tc, qc); - isl_space_free(dim); + isl_space_free(space); return qc; error: - isl_space_free(dim); + isl_space_free(space); isl_map_free(qc); return NULL; } @@ -1211,38 +1217,41 @@ * after computing the integer divisions, is smaller than the number * of basic maps in the input map. */ -static int incemental_on_entire_domain(__isl_keep isl_space *dim, +static isl_bool incremental_on_entire_domain(__isl_keep isl_space *space, __isl_keep isl_map *map, isl_set **dom, isl_set **ran, int *left, int *right, __isl_give isl_map **res) { int i; isl_set *C; - unsigned d; + isl_size d; *res = NULL; + + d = isl_map_dim(map, isl_dim_in); + if (d < 0) + return isl_bool_error; C = isl_set_union(isl_map_domain(isl_map_copy(map)), isl_map_range(isl_map_copy(map))); C = isl_set_from_basic_set(isl_set_simple_hull(C)); if (!C) - return -1; + return isl_bool_error; if (C->n != 1) { isl_set_free(C); - return 0; + return isl_bool_false; } - d = isl_map_dim(map, isl_dim_in); - for (i = 0; i < map->n; ++i) { isl_map *qc; - int exact_i, spurious; + isl_bool exact_i; + isl_bool spurious; int j; dom[i] = isl_set_from_basic_set(isl_basic_map_domain( isl_basic_map_copy(map->p[i]))); ran[i] = isl_set_from_basic_set(isl_basic_map_range( isl_basic_map_copy(map->p[i]))); - qc = q_closure(isl_space_copy(dim), isl_set_copy(C), + qc = q_closure(isl_space_copy(space), isl_set_copy(C), map->p[i], &exact_i); if (!qc) goto error; @@ -1269,7 +1278,7 @@ isl_map_free(qc); continue; } - *res = compute_incremental(isl_space_copy(dim), map, i, qc, + *res = compute_incremental(isl_space_copy(space), map, i, qc, left, right, &exact_i); if (!*res) goto error; @@ -1281,10 +1290,10 @@ isl_set_free(C); - return *res != NULL; + return isl_bool_ok(*res != NULL); error: isl_set_free(C); - return -1; + return isl_bool_error; } /* Try and compute the transitive closure of "map" as @@ -1295,8 +1304,8 @@ * with C either the simple hull of the domain and range of the entire * map or the simple hull of domain and range of map_i. */ -static __isl_give isl_map *incremental_closure(__isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project) +static __isl_give isl_map *incremental_closure(__isl_take isl_space *space, + __isl_keep isl_map *map, isl_bool *exact, int project) { int i; isl_set **dom = NULL; @@ -1304,18 +1313,22 @@ int *left = NULL; int *right = NULL; isl_set *C; - unsigned d; + isl_size d; isl_map *res = NULL; if (!project) - return construct_projected_component(dim, map, exact, project); + return construct_projected_component(space, map, exact, + project); if (!map) goto error; if (map->n <= 1) - return construct_projected_component(dim, map, exact, project); + return construct_projected_component(space, map, exact, + project); d = isl_map_dim(map, isl_dim_in); + if (d < 0) + goto error; dom = isl_calloc_array(map->ctx, isl_set *, map->n); ran = isl_calloc_array(map->ctx, isl_set *, map->n); @@ -1324,12 +1337,14 @@ if (!ran || !dom || !left || !right) goto error; - if (incemental_on_entire_domain(dim, map, dom, ran, left, right, &res) < 0) + if (incremental_on_entire_domain(space, map, dom, ran, left, right, + &res) < 0) goto error; for (i = 0; !res && i < map->n; ++i) { isl_map *qc; - int exact_i, spurious, comp; + int comp; + isl_bool exact_i, spurious; if (!dom[i]) dom[i] = isl_set_from_basic_set( isl_basic_map_domain( @@ -1358,7 +1373,7 @@ goto error; continue; } - qc = q_closure(isl_space_copy(dim), C, map->p[i], &exact_i); + qc = q_closure(isl_space_copy(space), C, map->p[i], &exact_i); if (!qc) goto error; if (!exact_i) { @@ -1383,7 +1398,7 @@ isl_map_free(qc); continue; } - res = compute_incremental(isl_space_copy(dim), map, i, qc, + res = compute_incremental(isl_space_copy(space), map, i, qc, (comp & LEFT) ? left : NULL, (comp & RIGHT) ? right : NULL, &exact_i); if (!res) @@ -1404,11 +1419,11 @@ free(right); if (res) { - isl_space_free(dim); + isl_space_free(space); return res; } - return construct_projected_component(dim, map, exact, project); + return construct_projected_component(space, map, exact, project); error: if (dom) for (i = 0; i < map->n; ++i) @@ -1420,7 +1435,7 @@ free(ran); free(left); free(right); - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1465,40 +1480,48 @@ error: isl_set_free(dom); return -1; +} + +/* Construct a map [x] -> [x+1], with parameters prescribed by "space". + */ +static __isl_give isl_map *increment(__isl_take isl_space *space) +{ + int k; + isl_basic_map *bmap; + isl_size total; + + space = isl_space_set_from_params(space); + space = isl_space_add_dims(space, isl_dim_set, 1); + space = isl_space_map_from_set(space); + bmap = isl_basic_map_alloc_space(space, 0, 1, 0); + total = isl_basic_map_dim(bmap, isl_dim_all); + k = isl_basic_map_alloc_equality(bmap); + if (total < 0 || k < 0) + goto error; + isl_seq_clr(bmap->eq[k], 1 + total); + isl_int_set_si(bmap->eq[k][0], 1); + isl_int_set_si(bmap->eq[k][isl_basic_map_offset(bmap, isl_dim_in)], 1); + isl_int_set_si(bmap->eq[k][isl_basic_map_offset(bmap, isl_dim_out)], -1); + return isl_map_from_basic_map(bmap); +error: + isl_basic_map_free(bmap); + return NULL; } /* Replace each entry in the n by n grid of maps by the cross product * with the relation { [i] -> [i + 1] }. */ -static int add_length(__isl_keep isl_map *map, isl_map ***grid, int n) +static isl_stat add_length(__isl_keep isl_map *map, isl_map ***grid, int n) { - int i, j, k; - isl_space *dim; - isl_basic_map *bstep; + int i, j; + isl_space *space; isl_map *step; - unsigned nparam; - if (!map) - return -1; + space = isl_space_params(isl_map_get_space(map)); + step = increment(space); - dim = isl_map_get_space(map); - nparam = isl_space_dim(dim, isl_dim_param); - dim = isl_space_drop_dims(dim, isl_dim_in, 0, isl_space_dim(dim, isl_dim_in)); - dim = isl_space_drop_dims(dim, isl_dim_out, 0, isl_space_dim(dim, isl_dim_out)); - dim = isl_space_add_dims(dim, isl_dim_in, 1); - dim = isl_space_add_dims(dim, isl_dim_out, 1); - bstep = isl_basic_map_alloc_space(dim, 0, 1, 0); - k = isl_basic_map_alloc_equality(bstep); - if (k < 0) { - isl_basic_map_free(bstep); - return -1; - } - isl_seq_clr(bstep->eq[k], 1 + isl_basic_map_total_dim(bstep)); - isl_int_set_si(bstep->eq[k][0], 1); - isl_int_set_si(bstep->eq[k][1 + nparam], 1); - isl_int_set_si(bstep->eq[k][1 + nparam + 1], -1); - bstep = isl_basic_map_finalize(bstep); - step = isl_map_from_basic_map(bstep); + if (!step) + return isl_stat_error; for (i = 0; i < n; ++i) for (j = 0; j < n; ++j) @@ -1507,7 +1530,7 @@ isl_map_free(step); - return 0; + return isl_stat_ok; } /* The core of the Floyd-Warshall algorithm. @@ -1521,16 +1544,17 @@ * transitive closure to account for all indirect paths that stay * in the current vertex. */ -static void floyd_warshall_iterate(isl_map ***grid, int n, int *exact) +static void floyd_warshall_iterate(isl_map ***grid, int n, isl_bool *exact) { int r, p, q; for (r = 0; r < n; ++r) { - int r_exact; + isl_bool r_exact; + int check = exact && *exact == isl_bool_true; grid[r][r] = isl_map_transitive_closure(grid[r][r], - (exact && *exact) ? &r_exact : NULL); - if (exact && *exact && !r_exact) - *exact = 0; + check ? &r_exact : NULL); + if (check && !r_exact) + *exact = isl_bool_false; for (p = 0; p < n; ++p) for (q = 0; q < n; ++q) { @@ -1571,8 +1595,9 @@ * the input relation by the cross product with the unit length relation * { [i] -> [i + 1] }. */ -static __isl_give isl_map *floyd_warshall_with_groups(__isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project, int *group, int n) +static __isl_give isl_map *floyd_warshall_with_groups( + __isl_take isl_space *space, __isl_keep isl_map *map, + isl_bool *exact, int project, int *group, int n) { int i, j, k; isl_map ***grid = NULL; @@ -1583,7 +1608,7 @@ if (n == 1) { free(group); - return incremental_closure(dim, map, exact, project); + return incremental_closure(space, map, exact, project); } grid = isl_calloc_array(map->ctx, isl_map **, n); @@ -1620,7 +1645,7 @@ free(grid); free(group); - isl_space_free(dim); + isl_space_free(space); return app; error: @@ -1634,7 +1659,7 @@ } free(grid); free(group); - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1710,8 +1735,8 @@ * calls inside the Floyd-Warshall algorithm typically result in * non-linear path lengths quite quickly. */ -static __isl_give isl_map *floyd_warshall(__isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project) +static __isl_give isl_map *floyd_warshall(__isl_take isl_space *space, + __isl_keep isl_map *map, isl_bool *exact, int project) { int i; isl_set **set = NULL; @@ -1721,7 +1746,7 @@ if (!map) goto error; if (map->n <= 1) - return incremental_closure(dim, map, exact, project); + return incremental_closure(space, map, exact, project); group = setup_groups(map->ctx, map->p, map->n, &set, &n); if (!group) @@ -1732,9 +1757,9 @@ free(set); - return floyd_warshall_with_groups(dim, map, exact, project, group, n); + return floyd_warshall_with_groups(space, map, exact, project, group, n); error: - isl_space_free(dim); + isl_space_free(space); return NULL; } @@ -1812,7 +1837,7 @@ if (subset) data->check_closed = 1; - return subset < 0 ? isl_bool_error : !subset; + return isl_bool_not(subset); error: isl_map_free(map21); return isl_bool_error; @@ -1851,20 +1876,21 @@ * order, at each join also taking in the union of both arguments * to allow for paths that do not go through one of the two arguments. */ -static __isl_give isl_map *construct_power_components(__isl_take isl_space *dim, - __isl_keep isl_map *map, int *exact, int project) +static __isl_give isl_map *construct_power_components( + __isl_take isl_space *space, __isl_keep isl_map *map, isl_bool *exact, + int project) { int i, n, c; struct isl_map *path = NULL; struct isl_tc_follows_data data; struct isl_tarjan_graph *g = NULL; - int *orig_exact; - int local_exact; + isl_bool *orig_exact; + isl_bool local_exact; if (!map) goto error; if (map->n <= 1) - return floyd_warshall(dim, map, exact, project); + return floyd_warshall(space, map, exact, project); data.list = map->p; data.check_closed = 0; @@ -1882,7 +1908,7 @@ if (project) path = isl_map_empty(isl_map_get_space(map)); else - path = isl_map_empty(isl_space_copy(dim)); + path = isl_map_empty(isl_space_copy(space)); path = anonymize(path); while (n) { struct isl_map *comp; @@ -1894,7 +1920,7 @@ --n; ++i; } - path_comp = floyd_warshall(isl_space_copy(dim), + path_comp = floyd_warshall(isl_space_copy(space), comp, exact, project); path_comp = anonymize(path_comp); path_comb = isl_map_apply_range(isl_map_copy(path), @@ -1907,7 +1933,7 @@ } if (c > 1 && data.check_closed && !*exact) { - int closed; + isl_bool closed; closed = isl_map_is_transitively_closed(path); if (closed < 0) @@ -1915,17 +1941,17 @@ if (!closed) { isl_tarjan_graph_free(g); isl_map_free(path); - return floyd_warshall(dim, map, orig_exact, project); + return floyd_warshall(space, map, orig_exact, project); } } isl_tarjan_graph_free(g); - isl_space_free(dim); + isl_space_free(space); return path; error: isl_tarjan_graph_free(g); - isl_space_free(dim); + isl_space_free(space); isl_map_free(path); return NULL; } @@ -1960,23 +1986,23 @@ * image element(s). */ static __isl_give isl_map *construct_power(__isl_keep isl_map *map, - int *exact, int project) + isl_bool *exact, int project) { struct isl_map *app = NULL; - isl_space *dim = NULL; + isl_space *space = NULL; if (!map) return NULL; - dim = isl_map_get_space(map); + space = isl_map_get_space(map); - dim = isl_space_add_dims(dim, isl_dim_in, 1); - dim = isl_space_add_dims(dim, isl_dim_out, 1); + space = isl_space_add_dims(space, isl_dim_in, 1); + space = isl_space_add_dims(space, isl_dim_out, 1); - app = construct_power_components(isl_space_copy(dim), map, + app = construct_power_components(isl_space_copy(space), map, exact, project); - isl_space_free(dim); + isl_space_free(space); return app; } @@ -1990,28 +2016,20 @@ * encoded as the difference between an extra pair of final coordinates. */ static __isl_give isl_map *map_power(__isl_take isl_map *map, - int *exact, int project) + isl_bool *exact, int project) { struct isl_map *app = NULL; if (exact) - *exact = 1; - - if (!map) - return NULL; + *exact = isl_bool_true; - isl_assert(map->ctx, - isl_map_dim(map, isl_dim_in) == isl_map_dim(map, isl_dim_out), - goto error); + if (isl_map_check_equal_tuples(map) < 0) + return isl_map_free(map); app = construct_power(map, exact, project); isl_map_free(map); return app; -error: - isl_map_free(map); - isl_map_free(app); - return NULL; } /* Compute the positive powers of "map", or an overapproximation. @@ -2023,19 +2041,18 @@ * and made positive. The extra coordinates are subsequently projected out * and the parameter is turned into the domain of the result. */ -__isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact) +__isl_give isl_map *isl_map_power(__isl_take isl_map *map, isl_bool *exact) { - isl_space *target_dim; - isl_space *dim; + isl_space *target_space; + isl_space *space; isl_map *diff; - unsigned d; - unsigned param; + isl_size d; + isl_size param; - if (!map) - return NULL; - d = isl_map_dim(map, isl_dim_in); param = isl_map_dim(map, isl_dim_param); + if (d < 0 || param < 0) + return isl_map_free(map); map = isl_map_compute_divs(map); map = isl_map_coalesce(map); @@ -2047,23 +2064,23 @@ return map; } - target_dim = isl_map_get_space(map); - target_dim = isl_space_from_range(isl_space_wrap(target_dim)); - target_dim = isl_space_add_dims(target_dim, isl_dim_in, 1); - target_dim = isl_space_set_dim_name(target_dim, isl_dim_in, 0, "k"); + target_space = isl_map_get_space(map); + target_space = isl_space_from_range(isl_space_wrap(target_space)); + target_space = isl_space_add_dims(target_space, isl_dim_in, 1); + target_space = isl_space_set_dim_name(target_space, isl_dim_in, 0, "k"); map = map_power(map, exact, 0); map = isl_map_add_dims(map, isl_dim_param, 1); - dim = isl_map_get_space(map); - diff = equate_parameter_to_length(dim, param); + space = isl_map_get_space(map); + diff = equate_parameter_to_length(space, param); map = isl_map_intersect(map, diff); map = isl_map_project_out(map, isl_dim_in, d, 1); map = isl_map_project_out(map, isl_dim_out, d, 1); map = isl_map_from_range(isl_map_wrap(map)); map = isl_map_move_dims(map, isl_dim_in, 0, isl_dim_param, param, 1); - map = isl_map_reset_space(map, target_dim); + map = isl_map_reset_space(map, target_space); return map; } @@ -2078,25 +2095,24 @@ * of a parameter. */ __isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map, - int *exact) + isl_bool *exact) { - isl_space *dim; + isl_space *space; isl_map *diff; - unsigned d; - unsigned param; - - if (!map) - return NULL; + isl_size d; + isl_size param; d = isl_map_dim(map, isl_dim_in); param = isl_map_dim(map, isl_dim_param); + if (d < 0 || param < 0) + return isl_map_free(map); map = isl_map_compute_divs(map); map = isl_map_coalesce(map); if (isl_map_plain_is_empty(map)) { if (exact) - *exact = 1; + *exact = isl_bool_true; map = isl_map_project_out(map, isl_dim_out, 0, d); map = isl_map_add_dims(map, isl_dim_out, 1); return map; @@ -2105,8 +2121,8 @@ map = map_power(map, exact, 0); map = isl_map_add_dims(map, isl_dim_param, 1); - dim = isl_map_get_space(map); - diff = equate_parameter_to_length(dim, param); + space = isl_map_get_space(map); + diff = equate_parameter_to_length(space, param); map = isl_map_intersect(map, diff); map = isl_map_project_out(map, isl_dim_in, 0, d + 1); map = isl_map_project_out(map, isl_dim_out, d, 1); @@ -2321,25 +2337,25 @@ * * app \subset (map \cup (map \circ app)) */ -static int check_exactness_omega(__isl_keep isl_map *map, +static isl_bool check_exactness_omega(__isl_keep isl_map *map, __isl_keep isl_map *app) { isl_set *delta; int i; - int is_empty, is_exact; - unsigned d; + isl_bool is_empty, is_exact; + isl_size d; isl_map *test; delta = isl_map_deltas(isl_map_copy(app)); d = isl_set_dim(delta, isl_dim_set); + if (d < 0) + delta = isl_set_free(delta); for (i = 0; i < d; ++i) delta = isl_set_fix_si(delta, isl_dim_set, i, 0); is_empty = isl_set_is_empty(delta); isl_set_free(delta); - if (is_empty < 0) - return -1; - if (!is_empty) - return 0; + if (is_empty < 0 || !is_empty) + return is_empty; test = isl_map_apply_range(isl_map_copy(app), isl_map_copy(map)); test = isl_map_union(test, isl_map_copy(map)); @@ -2444,13 +2460,19 @@ } static __isl_give isl_map *box_closure_with_check(__isl_take isl_map *map, - int *exact) + isl_bool *exact) { isl_map *app; app = box_closure(isl_map_copy(map)); - if (exact) - *exact = check_exactness_omega(map, app); + if (exact) { + isl_bool is_exact = check_exactness_omega(map, app); + + if (is_exact < 0) + app = isl_map_free(app); + else + *exact = is_exact; + } isl_map_free(map); return app; @@ -2475,10 +2497,10 @@ * If not, we simply call box_closure on the whole map. */ static __isl_give isl_map *transitive_closure_omega(__isl_take isl_map *map, - int *exact) + isl_bool *exact) { int i, j; - int exact_i; + isl_bool exact_i; isl_map *app; if (!map) @@ -2509,7 +2531,7 @@ app = isl_map_union(tc, transitive_closure_omega(app, NULL)); exact_i = check_exactness_omega(map, app); - if (exact_i == 1) { + if (exact_i == isl_bool_true) { if (exact) *exact = exact_i; isl_map_free(map); @@ -2533,10 +2555,10 @@ * the length to a parameter. */ __isl_give isl_map *isl_map_transitive_closure(__isl_take isl_map *map, - int *exact) + isl_bool *exact) { isl_space *target_dim; - int closed; + isl_bool closed; if (!map) goto error; @@ -2551,7 +2573,7 @@ goto error; if (closed) { if (exact) - *exact = 1; + *exact = isl_bool_true; return map; } @@ -2601,10 +2623,10 @@ * grid have domains and ranges of the same dimension and so * the standard algorithm can be used because the nested transitive * closures are only applied to diagonal elements and because all - * compositions are peformed on relations with compatible domains and ranges. + * compositions are performed on relations with compatible domains and ranges. */ static __isl_give isl_union_map *union_floyd_warshall_on_list(isl_ctx *ctx, - __isl_keep isl_basic_map **list, int n, int *exact) + __isl_keep isl_basic_map **list, int n, isl_bool *exact) { int i, j, k; int n_group; @@ -2625,11 +2647,11 @@ if (!grid[i]) goto error; for (j = 0; j < n_group; ++j) { - isl_space *dim1, *dim2, *dim; - dim1 = isl_space_reverse(isl_set_get_space(set[i])); - dim2 = isl_set_get_space(set[j]); - dim = isl_space_join(dim1, dim2); - grid[i][j] = isl_map_empty(dim); + isl_space *space1, *space2, *space; + space1 = isl_space_reverse(isl_set_get_space(set[i])); + space2 = isl_set_get_space(set[j]); + space = isl_space_join(space1, space2); + grid[i][j] = isl_map_empty(space); } } @@ -2684,7 +2706,7 @@ * and then perform the algorithm on this list. */ static __isl_give isl_union_map *union_floyd_warshall( - __isl_take isl_union_map *umap, int *exact) + __isl_take isl_union_map *umap, isl_bool *exact) { int i, n; isl_ctx *ctx; @@ -2731,7 +2753,7 @@ * operations are performed on union maps. */ static __isl_give isl_union_map *union_components( - __isl_take isl_union_map *umap, int *exact) + __isl_take isl_union_map *umap, isl_bool *exact) { int i; int n; @@ -2793,7 +2815,7 @@ } if (c > 1 && data.check_closed && !*exact) { - int closed; + isl_bool closed; closed = isl_union_map_is_transitively_closed(path); if (closed < 0) @@ -2831,15 +2853,15 @@ * If the result is exact, then *exact is set to 1. */ __isl_give isl_union_map *isl_union_map_transitive_closure( - __isl_take isl_union_map *umap, int *exact) + __isl_take isl_union_map *umap, isl_bool *exact) { - int closed; + isl_bool closed; if (!umap) return NULL; if (exact) - *exact = 1; + *exact = isl_bool_true; umap = isl_union_map_compute_divs(umap); umap = isl_union_map_coalesce(umap); @@ -2857,7 +2879,7 @@ struct isl_union_power { isl_union_map *pow; - int *exact; + isl_bool *exact; }; static isl_stat power(__isl_take isl_map *map, void *user) @@ -2870,29 +2892,6 @@ return isl_stat_error; } -/* Construct a map [x] -> [x+1], with parameters prescribed by "dim". - */ -static __isl_give isl_union_map *increment(__isl_take isl_space *dim) -{ - int k; - isl_basic_map *bmap; - - dim = isl_space_add_dims(dim, isl_dim_in, 1); - dim = isl_space_add_dims(dim, isl_dim_out, 1); - bmap = isl_basic_map_alloc_space(dim, 0, 1, 0); - k = isl_basic_map_alloc_equality(bmap); - if (k < 0) - goto error; - isl_seq_clr(bmap->eq[k], isl_basic_map_total_dim(bmap)); - isl_int_set_si(bmap->eq[k][0], 1); - isl_int_set_si(bmap->eq[k][isl_basic_map_offset(bmap, isl_dim_in)], 1); - isl_int_set_si(bmap->eq[k][isl_basic_map_offset(bmap, isl_dim_out)], -1); - return isl_union_map_from_map(isl_map_from_basic_map(bmap)); -error: - isl_basic_map_free(bmap); - return NULL; -} - /* Construct a map [[x]->[y]] -> [y-x], with parameters prescribed by "dim". */ static __isl_give isl_union_map *deltas_map(__isl_take isl_space *dim) @@ -2912,15 +2911,15 @@ * If the result is exact, then *exact is set to 1. */ __isl_give isl_union_map *isl_union_map_power(__isl_take isl_union_map *umap, - int *exact) + isl_bool *exact) { - int n; + isl_size n; isl_union_map *inc; isl_union_map *dm; - if (!umap) - return NULL; n = isl_union_map_n_map(umap); + if (n < 0) + return isl_union_map_free(umap); if (n == 0) return umap; if (n == 1) { @@ -2929,7 +2928,7 @@ isl_union_map_free(umap); return up.pow; } - inc = increment(isl_union_map_get_space(umap)); + inc = isl_union_map_from_map(increment(isl_union_map_get_space(umap))); umap = isl_union_map_product(inc, umap); umap = isl_union_map_transitive_closure(umap, exact); umap = isl_union_map_zip(umap); diff --git a/gcc/isl/isl_union_eval.c b/gcc/isl/isl_union_eval.c index b26a74d..bc222ab 100644 --- a/gcc/isl/isl_union_eval.c +++ a/gcc/isl/isl_union_eval.c @@ -26,7 +26,7 @@ /* Is the domain space of "entry" equal to "space"? */ -static int FN(UNION,has_domain_space)(const void *entry, const void *val) +static isl_bool FN(UNION,has_domain_space)(const void *entry, const void *val) { PART *part = (PART *)entry; isl_space *space = (isl_space *) val; @@ -63,7 +63,9 @@ hash, &FN(UNION,has_domain_space), space, 0); isl_space_free(space); - if (!entry) { + if (!entry) + goto error; + if (entry == isl_hash_table_entry_none) { v = isl_val_zero(isl_point_get_ctx(pnt)); isl_point_free(pnt); } else { diff --git a/gcc/isl/isl_union_macro.h b/gcc/isl/isl_union_macro.h index f445df6..2cc21a9 100644 --- a/gcc/isl/isl_union_macro.h +++ a/gcc/isl/isl_union_macro.h @@ -1,3 +1,9 @@ +#define xCAT(A,B) A ## B +#define CAT(A,B) xCAT(A,B) +#undef PART +#define PART CAT(isl_,BASE) +#undef UNION +#define UNION CAT(isl_union_,BASE) #define xFN(TYPE,NAME) TYPE ## _ ## NAME #define FN(TYPE,NAME) xFN(TYPE,NAME) #define xS(TYPE,NAME) struct TYPE ## _ ## NAME diff --git a/gcc/isl/isl_union_map.c b/gcc/isl/isl_union_map.c index caccf04..cd8c310 100644 --- a/gcc/isl/isl_union_map.c +++ a/gcc/isl/isl_union_map.c @@ -13,35 +13,37 @@ * B.P. 105 - 78153 Le Chesnay, France */ -#define ISL_DIM_H #include #include #include #include -#include +#include #include #include #include #include #include +#include #include #include #include #include +#include +#include /* Return the number of parameters of "umap", where "type" * is required to be set to isl_dim_param. */ -unsigned isl_union_map_dim(__isl_keep isl_union_map *umap, +isl_size isl_union_map_dim(__isl_keep isl_union_map *umap, enum isl_dim_type type) { if (!umap) - return 0; + return isl_size_error; if (type != isl_dim_param) isl_die(isl_union_map_get_ctx(umap), isl_error_invalid, - "can only reference parameters", return 0); + "can only reference parameters", return isl_size_error); return isl_space_dim(umap->dim, type); } @@ -49,7 +51,7 @@ /* Return the number of parameters of "uset", where "type" * is required to be set to isl_dim_param. */ -unsigned isl_union_set_dim(__isl_keep isl_union_set *uset, +isl_size isl_union_set_dim(__isl_keep isl_union_set *uset, enum isl_dim_type type) { return isl_union_map_dim(uset, type); @@ -86,6 +88,15 @@ params = isl_set_is_params(set); isl_set_free(set); return params; +} + +/* Is this union map actually a parameter domain? + * Users should never call this function. Outside of isl, + * a union map can never be a parameter domain. + */ +isl_bool isl_union_map_is_params(__isl_keep isl_union_map *umap) +{ + return isl_union_set_is_params(uset_from_umap(umap)); } static __isl_give isl_union_map *isl_union_map_alloc( @@ -111,14 +122,42 @@ return umap; } -__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *space) +/* Create an empty union map without specifying any parameters. + */ +__isl_give isl_union_map *isl_union_map_empty_ctx(isl_ctx *ctx) { + return isl_union_map_empty_space(isl_space_unit(ctx)); +} + +__isl_give isl_union_map *isl_union_map_empty_space(__isl_take isl_space *space) +{ return isl_union_map_alloc(space, 16); +} + +/* This is an alternative name for the function above. + */ +__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *space) +{ + return isl_union_map_empty_space(space); } +/* Create an empty union set without specifying any parameters. + */ +__isl_give isl_union_set *isl_union_set_empty_ctx(isl_ctx *ctx) +{ + return uset_from_umap(isl_union_map_empty_ctx(ctx)); +} + +__isl_give isl_union_set *isl_union_set_empty_space(__isl_take isl_space *space) +{ + return uset_from_umap(isl_union_map_empty_space(space)); +} + +/* This is an alternative name for the function above. + */ __isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *space) { - return isl_union_map_empty(space); + return isl_union_set_empty_space(space); } isl_ctx *isl_union_map_get_ctx(__isl_keep isl_union_map *umap) @@ -138,6 +177,13 @@ return umap ? umap->dim : NULL; } +/* Return the space of "uset". + */ +__isl_keep isl_space *isl_union_set_peek_space(__isl_keep isl_union_set *uset) +{ + return isl_union_map_peek_space(uset_to_umap(uset)); +} + __isl_give isl_space *isl_union_map_get_space(__isl_keep isl_union_map *umap) { return isl_space_copy(isl_union_map_peek_space(umap)); @@ -245,12 +291,11 @@ return umap; } - model = isl_space_params(model); data.exp = isl_parameter_alignment_reordering(umap->dim, model); if (!data.exp) goto error; - data.res = isl_union_map_alloc(isl_space_copy(data.exp->dim), + data.res = isl_union_map_alloc(isl_reordering_get_space(data.exp), umap->table.n); if (isl_hash_table_foreach(umap->dim->ctx, &umap->table, &align_entry, &data) < 0) @@ -357,7 +402,7 @@ return isl_union_map_space_has_equal_params(uset_to_umap(uset), space); } -static int has_space(const void *entry, const void *val) +static isl_bool has_space(const void *entry, const void *val) { isl_map *map = (isl_map *)entry; isl_space *space = (isl_space *) val; @@ -469,14 +514,14 @@ return data->fn(isl_map_copy(map), data->user); } -int isl_union_map_n_map(__isl_keep isl_union_map *umap) +isl_size isl_union_map_n_map(__isl_keep isl_union_map *umap) { - return umap ? umap->table.n : 0; + return umap ? umap->table.n : isl_size_error; } -int isl_union_set_n_set(__isl_keep isl_union_set *uset) +isl_size isl_union_set_n_set(__isl_keep isl_union_set *uset) { - return uset ? uset->table.n : 0; + return uset ? uset->table.n : isl_size_error; } isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap, @@ -541,6 +586,73 @@ if (data.failed) return isl_bool_false; return isl_bool_error; +} + +/* Add "map" to "list". + */ +static isl_stat add_list_map(__isl_take isl_map *map, void *user) +{ + isl_map_list **list = user; + + *list = isl_map_list_add(*list, map); + + if (!*list) + return isl_stat_error; + return isl_stat_ok; +} + +/* Return the maps in "umap" as a list. + * + * First construct a list of the appropriate size and then add all the + * elements. + */ +__isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap) +{ + isl_size n_maps; + isl_ctx *ctx; + isl_map_list *list; + + n_maps = isl_union_map_n_map(umap); + if (n_maps < 0) + return NULL; + ctx = isl_union_map_get_ctx(umap); + list = isl_map_list_alloc(ctx, n_maps); + + if (isl_union_map_foreach_map(umap, &add_list_map, &list) < 0) + list = isl_map_list_free(list); + + return list; +} + +/* Return the sets in "uset" as a list. + */ +__isl_give isl_set_list *isl_union_set_get_set_list( + __isl_keep isl_union_set *uset) +{ + return set_list_from_map_list( + isl_union_map_get_map_list(uset_to_umap(uset))); +} + +/* Can "umap" be converted to an isl_map? + * That is, does it contain elements in exactly one space? + */ +isl_bool isl_union_map_isa_map(__isl_keep isl_union_map *umap) +{ + isl_size n; + + n = isl_union_map_n_map(umap); + if (n < 0) + return isl_bool_error; + return isl_bool_ok(n == 1); +} + +/* Can "uset" be converted to an isl_set? + * That is, does it contain elements in exactly one space? + */ +isl_bool isl_union_set_isa_set(__isl_keep isl_union_set *uset) +{ + return isl_union_map_isa_map(uset_to_umap(uset)); } static isl_stat copy_map(void **entry, void *user) @@ -555,13 +667,15 @@ __isl_give isl_map *isl_map_from_union_map(__isl_take isl_union_map *umap) { + isl_bool is_map; isl_ctx *ctx; isl_map *map = NULL; - if (!umap) - return NULL; + is_map = isl_union_map_isa_map(umap); + if (is_map < 0) + goto error; ctx = isl_union_map_get_ctx(umap); - if (umap->table.n != 1) + if (!is_map) isl_die(ctx, isl_error_invalid, "union map needs to contain elements in exactly " "one space", goto error); @@ -590,8 +704,7 @@ uint32_t hash; struct isl_hash_table_entry *entry; - space = isl_space_drop_dims(space, isl_dim_param, - 0, isl_space_dim(space, isl_dim_param)); + space = isl_space_drop_all_params(space); space = isl_space_align_params(space, isl_union_map_get_space(umap)); if (!umap || !space) goto error; @@ -600,6 +713,8 @@ entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash, &has_space, space, 0); if (!entry) + goto error; + if (entry == isl_hash_table_entry_none) return isl_map_empty(space); isl_space_free(space); return isl_map_copy(entry->data); @@ -628,7 +743,9 @@ hash = isl_space_get_hash(space); entry = isl_hash_table_find(umap->dim->ctx, &umap->table, hash, &has_space, space, 0); - return !!entry; + if (!entry) + return isl_bool_error; + return isl_bool_ok(entry != isl_hash_table_entry_none); } isl_bool isl_union_set_contains(__isl_keep isl_union_set *uset, @@ -642,6 +759,37 @@ { return isl_union_map_foreach_map(uset, (isl_stat(*)(__isl_take isl_map *, void*))fn, user); +} + +/* Internal data structure for isl_union_set_every_set. + * + * "test" is the user-specified callback function. + * "user" is the user-specified callback function argument. + */ +struct isl_test_set_from_map_data { + isl_bool (*test)(__isl_keep isl_set *set, void *user); + void *user; +}; + +/* Call data->test on "map", which is part of an isl_union_set and + * therefore known to be an isl_set. + */ +static isl_bool test_set_from_map(__isl_keep isl_map *map, void *user) +{ + struct isl_test_set_from_map_data *data = user; + + return data->test(set_from_map(map), data->user); +} + +/* Does "test" succeed on every set in "uset"? + */ +isl_bool isl_union_set_every_set(__isl_keep isl_union_set *uset, + isl_bool (*test)(__isl_keep isl_set *set, void *user), void *user) +{ + struct isl_test_set_from_map_data data = { test, user }; + + return isl_union_map_every_map(uset_to_umap(uset), + &test_set_from_map, &data); } struct isl_union_set_foreach_point_data { @@ -774,8 +922,9 @@ &data->umap2->table, hash, &has_space, space, 0); isl_space_free(space); - res.valid = entry2 != NULL; if (entry2) + res.valid = isl_bool_ok(entry2 != isl_hash_table_entry_none); + if (res.valid >= 0 && res.valid) res.value = entry2->data; return res; @@ -976,6 +1125,8 @@ entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table, hash, &has_space, map->dim, 0); if (!entry2) + return isl_stat_error; + if (entry2 == isl_hash_table_entry_none) return isl_stat_ok; map = isl_map_copy(map); @@ -1274,6 +1425,38 @@ }; return gen_bin_op(umap, uset, &control); +} + +/* Intersect each map in "umap" in a space [A -> B] -> C + * with the corresponding map in "factor" in the space B -> C and + * collect the results. + */ +__isl_give isl_union_map *isl_union_map_intersect_domain_factor_range( + __isl_take isl_union_map *umap, __isl_take isl_union_map *factor) +{ + struct isl_bin_op_control control = { + .filter = &isl_map_domain_is_wrapping, + .match_space = &isl_space_domain_factor_range, + .fn_map = &isl_map_intersect_domain_factor_range, + }; + + return gen_bin_op(umap, factor, &control); +} + +/* Intersect each map in "umap" in a space A -> [B -> C] + * with the corresponding map in "factor" in the space A -> B and + * collect the results. + */ +__isl_give isl_union_map *isl_union_map_intersect_range_factor_domain( + __isl_take isl_union_map *umap, __isl_take isl_union_map *factor) +{ + struct isl_bin_op_control control = { + .filter = &isl_map_range_is_wrapping, + .match_space = &isl_space_range_factor_domain, + .fn_map = &isl_map_intersect_range_factor_domain, + }; + + return gen_bin_op(umap, factor, &control); } /* Intersect each map in "umap" in a space A -> [B -> C] @@ -1581,8 +1764,9 @@ * are taken into account. "filter_user" is passed as the second argument * to "filter". No filter can be set if "inplace" or * "total" is set. - * "fn_map" specifies how the maps (selected by "filter") - * should be transformed. + * Exactly one of "fn_map" or "fn_map2" should be set, specifying + * how the maps (selected by "filter") should be transformed. + * If "fn_map2" is set, then "fn_map2_user" is passed as the second argument. */ struct isl_un_op_control { int inplace; @@ -1590,6 +1774,8 @@ isl_bool (*filter)(__isl_keep isl_map *map, void *user); void *filter_user; __isl_give isl_map *(*fn_map)(__isl_take isl_map *map); + __isl_give isl_map *(*fn_map2)(__isl_take isl_map *map, void *user); + void *fn_map2_user; }; /* Data structure for wrapping the data for un_op_filter_drop_user. @@ -1623,28 +1809,34 @@ * * If control->filter is set, then check if this map satisfies the filter. * If so (or if control->filter is not set), modify the map - * by calling control->fn_map and either add the result to data->res or + * by calling control->fn_map or control->fn_map2 and + * either add the result to data->res or * replace the original entry by the result (if control->inplace is set). */ static isl_stat un_entry(void **entry, void *user) { struct isl_union_map_un_data *data = user; + struct isl_un_op_control *control = data->control; isl_map *map = *entry; - if (data->control->filter) { + if (control->filter) { isl_bool ok; - ok = data->control->filter(map, data->control->filter_user); + ok = control->filter(map, control->filter_user); if (ok < 0) return isl_stat_error; if (!ok) return isl_stat_ok; } - map = data->control->fn_map(isl_map_copy(map)); + map = isl_map_copy(map); + if (control->fn_map2 != NULL) + map = control->fn_map2(map, control->fn_map2_user); + else + map = control->fn_map(map); if (!map) return isl_stat_error; - if (data->control->inplace) { + if (control->inplace) { isl_map_free(*entry); *entry = map; } else { @@ -1670,6 +1862,10 @@ if (!umap) return NULL; + if (!!control->fn_map == !!control->fn_map2) + isl_die(isl_union_map_get_ctx(umap), isl_error_internal, + "exactly one mapping function should be specified", + return isl_union_map_free(umap)); if ((control->inplace || control->total) && control->filter) isl_die(isl_union_map_get_ctx(umap), isl_error_invalid, "inplace/total modification cannot be filtered", @@ -1929,6 +2125,21 @@ { struct isl_un_op_control control = { .fn_map = &isl_map_reverse, + }; + return un_op(umap, &control); +} + +/* Given a union map, take the maps of the form A -> (B -> C) and + * return the union of the corresponding maps A -> (C -> B). + */ +__isl_give isl_union_map *isl_union_map_range_reverse( + __isl_take isl_union_map *umap) +{ + struct isl_un_op_drop_user_data data = { &isl_map_range_is_wrapping }; + struct isl_un_op_control control = { + .filter = &un_op_filter_drop_user, + .filter_user = &data, + .fn_map = &isl_map_range_reverse, }; return un_op(umap, &control); } @@ -2237,13 +2448,15 @@ hash = isl_space_get_hash(map->dim); entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table, hash, &has_space, map->dim, 0); - if (!entry2) { + if (!entry2) + return isl_stat_error; + if (entry2 == isl_hash_table_entry_none) { int empty = isl_map_is_empty(map); if (empty < 0) return isl_stat_error; if (empty) return isl_stat_ok; - data->is_subset = 0; + data->is_subset = isl_bool_false; return isl_stat_error; } @@ -2320,9 +2533,7 @@ if (is_subset != isl_bool_true) return is_subset; is_subset = isl_union_map_is_subset(umap2, umap1); - if (is_subset == isl_bool_error) - return is_subset; - return !is_subset; + return isl_bool_not(is_subset); } isl_bool isl_union_set_is_strict_subset(__isl_keep isl_union_set *uset1, @@ -2355,6 +2566,8 @@ entry2 = isl_hash_table_find(data->umap2->dim->ctx, &data->umap2->table, hash, &has_space, map->dim, 0); if (!entry2) + return isl_stat_error; + if (entry2 == isl_hash_table_entry_none) return isl_stat_ok; data->is_disjoint = isl_map_is_disjoint(map, entry2->data); @@ -2531,9 +2744,12 @@ */ isl_bool isl_union_map_plain_is_empty(__isl_keep isl_union_map *umap) { - if (!umap) + isl_size n; + + n = isl_union_map_n_map(umap); + if (n < 0) return isl_bool_error; - return isl_union_map_n_map(umap) == 0; + return n == 0; } isl_bool isl_union_map_is_empty(__isl_keep isl_union_map *umap) @@ -2614,12 +2830,16 @@ { struct isl_union_map_is_sv_data *data = user; isl_union_map *umap, *test; + isl_size n; umap = isl_union_map_copy(data->umap); umap = isl_union_map_intersect_domain(umap, isl_union_set_from_set(set)); - if (isl_union_map_n_map(umap) == 1) { + n = isl_union_map_n_map(umap); + if (n < 0) { + data->sv = isl_bool_error; + } else if (n == 1) { data->sv = single_map_is_single_valued(umap); isl_union_map_free(umap); } else { @@ -2647,8 +2867,12 @@ isl_union_map *universe; isl_union_set *domain; struct isl_union_map_is_sv_data data; + isl_size n; - if (isl_union_map_n_map(umap) == 1) + n = isl_union_map_n_map(umap); + if (n < 0) + return isl_bool_error; + if (n == 1) return single_map_is_single_valued(umap); universe = isl_union_map_universe(isl_union_map_copy(umap)); @@ -2906,13 +3130,13 @@ int first, int n_range) { isl_ctx *ctx; - int n; + isl_size n; struct isl_fixed_dim_data data = { NULL }; ctx = isl_union_map_get_ctx(umap); n = isl_union_map_n_map(umap); - if (!umap) + if (n < 0) goto error; if (n <= 1) { @@ -2962,12 +3186,17 @@ static isl_bool plain_injective_on_range_wrap(__isl_keep isl_set *ran, void *user) { + isl_size dim; isl_union_map *umap = user; + + dim = isl_set_dim(ran, isl_dim_set); + if (dim < 0) + return isl_bool_error; umap = isl_union_map_copy(umap); umap = isl_union_map_intersect_range(umap, isl_union_set_from_set(isl_set_copy(ran))); - return plain_injective_on_range(umap, 0, isl_set_dim(ran, isl_dim_set)); + return plain_injective_on_range(umap, 0, dim); } /* Check if the given union_map is obviously injective. @@ -3658,20 +3887,10 @@ return data.res; } - -/* Project out all parameters from "umap" by existentially quantifying - * over them. - */ -__isl_give isl_union_map *isl_union_map_project_out_all_params( - __isl_take isl_union_map *umap) -{ - unsigned n; - if (!umap) - return NULL; - n = isl_union_map_dim(umap, isl_dim_param); - return isl_union_map_project_out(umap, isl_dim_param, 0, n); -} +#undef TYPE +#define TYPE isl_union_map +#include "isl_project_out_all_params_templ.c" /* Turn the "n" dimensions of type "type", starting at "first" * into existentially quantified variables. @@ -3683,6 +3902,16 @@ enum isl_dim_type type, unsigned first, unsigned n) { return isl_union_map_project_out(uset, type, first, n); +} + +/* Project out all parameters from "uset" by existentially quantifying + * over them. + */ +__isl_give isl_union_set *isl_union_set_project_out_all_params( + __isl_take isl_union_set *uset) +{ + return uset_from_umap( + isl_union_map_project_out_all_params(uset_to_umap(uset))); } /* Internal data structure for isl_union_map_involves_dims. @@ -3702,9 +3931,7 @@ involves = isl_map_involves_dims(map, isl_dim_param, data->first, data->n); - if (involves < 0) - return isl_bool_error; - return !involves; + return isl_bool_not(involves); } /* Does "umap" involve any of the n parameters starting at first? @@ -3726,11 +3953,8 @@ "can only reference parameters", return isl_bool_error); excludes = union_map_forall_user(umap, &map_excludes, &data); - - if (excludes < 0) - return isl_bool_error; - return !excludes; + return isl_bool_not(excludes); } /* Internal data structure for isl_union_map_reset_range_space. @@ -3776,11 +4000,90 @@ data.res = isl_union_map_empty(isl_union_map_get_space(umap)); if (isl_union_map_foreach_map(umap, &reset_range_space, &data) < 0) + data.res = isl_union_map_free(data.res); + + isl_space_free(space); + isl_union_map_free(umap); + return data.res; +} + +/* Check that "umap" and "space" have the same number of parameters. + */ +static isl_stat check_union_map_space_equal_dim(__isl_keep isl_union_map *umap, + __isl_keep isl_space *space) +{ + isl_size dim1, dim2; + + dim1 = isl_union_map_dim(umap, isl_dim_param); + dim2 = isl_space_dim(space, isl_dim_param); + if (dim1 < 0 || dim2 < 0) + return isl_stat_error; + if (dim1 == dim2) + return isl_stat_ok; + isl_die(isl_union_map_get_ctx(umap), isl_error_invalid, + "number of parameters does not match", return isl_stat_error); +} + +/* Internal data structure for isl_union_map_reset_equal_dim_space. + * "space" is the target space. + * "res" collects the results. + */ +struct isl_union_map_reset_params_data { + isl_space *space; + isl_union_map *res; +}; + +/* Replace the parameters of "map" by those of data->space and + * add the result to data->res. + */ +static isl_stat reset_params(__isl_take isl_map *map, void *user) +{ + struct isl_union_map_reset_params_data *data = user; + isl_space *space; + + space = isl_map_get_space(map); + space = isl_space_replace_params(space, data->space); + map = isl_map_reset_equal_dim_space(map, space); + data->res = isl_union_map_add_map(data->res, map); + + return data->res ? isl_stat_ok : isl_stat_error; +} + +/* Replace the space of "umap" by "space", without modifying + * the dimension of "umap", i.e., the number of parameters of "umap". + * + * Since the hash values of the maps in the union map depend + * on the parameters, a new union map needs to be constructed. + */ +__isl_give isl_union_map *isl_union_map_reset_equal_dim_space( + __isl_take isl_union_map *umap, __isl_take isl_space *space) +{ + struct isl_union_map_reset_params_data data = { space }; + isl_bool equal; + isl_space *umap_space; + + umap_space = isl_union_map_peek_space(umap); + equal = isl_space_is_equal(umap_space, space); + if (equal < 0) + goto error; + if (equal) { + isl_space_free(space); + return umap; + } + if (check_union_map_space_equal_dim(umap, space) < 0) + goto error; + + data.res = isl_union_map_empty(isl_space_copy(space)); + if (isl_union_map_foreach_map(umap, &reset_params, &data) < 0) data.res = isl_union_map_free(data.res); isl_space_free(space); isl_union_map_free(umap); return data.res; +error: + isl_union_map_free(umap); + isl_space_free(space); + return NULL; } /* Internal data structure for isl_union_map_order_at_multi_union_pw_aff. @@ -3816,6 +4119,41 @@ data->res = isl_union_map_add_map(data->res, map); return data->res ? isl_stat_ok : isl_stat_error; +} + +/* If "mupa" has a non-trivial explicit domain, then intersect + * domain and range of "umap" with this explicit domain. + * If the explicit domain only describes constraints on the parameters, + * then the intersection only needs to be performed once. + */ +static __isl_give isl_union_map *intersect_explicit_domain( + __isl_take isl_union_map *umap, __isl_keep isl_multi_union_pw_aff *mupa) +{ + isl_bool non_trivial, is_params; + isl_union_set *dom; + + non_trivial = isl_multi_union_pw_aff_has_non_trivial_domain(mupa); + if (non_trivial < 0) + return isl_union_map_free(umap); + if (!non_trivial) + return umap; + mupa = isl_multi_union_pw_aff_copy(mupa); + dom = isl_multi_union_pw_aff_domain(mupa); + is_params = isl_union_set_is_params(dom); + if (is_params < 0) { + isl_union_set_free(dom); + return isl_union_map_free(umap); + } + if (is_params) { + isl_set *set; + + set = isl_union_set_params(dom); + umap = isl_union_map_intersect_params(umap, set); + return umap; + } + umap = isl_union_map_intersect_domain(umap, isl_union_set_copy(dom)); + umap = isl_union_map_intersect_range(umap, dom); + return umap; } /* Intersect each map in "umap" with the result of calling "order" @@ -3833,6 +4171,7 @@ isl_multi_union_pw_aff_get_space(mupa)); mupa = isl_multi_union_pw_aff_align_params(mupa, isl_union_map_get_space(umap)); + umap = intersect_explicit_domain(umap, mupa); data.mupa = mupa; data.order = order; data.res = isl_union_map_empty(isl_union_map_get_space(umap)); @@ -3882,19 +4221,20 @@ __isl_give isl_union_set *isl_union_set_list_union( __isl_take isl_union_set_list *list) { - int i, n; + int i; + isl_size n; isl_ctx *ctx; isl_space *space; isl_union_set *res; - if (!list) - return NULL; + n = isl_union_set_list_n_union_set(list); + if (n < 0) + goto error; ctx = isl_union_set_list_get_ctx(list); space = isl_space_params_alloc(ctx, 0); res = isl_union_set_empty(space); - n = isl_union_set_list_n_union_set(list); for (i = 0; i < n; ++i) { isl_union_set *uset_i; @@ -3904,6 +4244,9 @@ isl_union_set_list_free(list); return res; +error: + isl_union_set_list_free(list); + return NULL; } /* Update *hash with the hash value of "map". @@ -3948,11 +4291,13 @@ static isl_stat add_n(__isl_take isl_set *set, void *user) { int *n = user; + isl_size set_n; - *n += isl_set_n_basic_set(set); + set_n = isl_set_n_basic_set(set); + *n += set_n; isl_set_free(set); - return isl_stat_ok; + return set_n < 0 ? isl_stat_error : isl_stat_ok; } /* Return the total number of basic sets in "uset". @@ -4051,4 +4396,42 @@ .fn_map = &map_id, }; return un_op(umap, &control); +} + +/* Does "map" have "space" as range (ignoring parameters)? + */ +static isl_bool has_range_space(__isl_keep isl_map *map, void *user) +{ + isl_space *space = user; + + return isl_space_has_range_tuples(space, isl_map_peek_space(map)); +} + +/* Wrapper around isl_map_bind_range for use as a un_op callback. + */ +static __isl_give isl_map *bind_range(__isl_take isl_map *map, void *user) +{ + isl_multi_id *tuple = user; + + return isl_map_bind_range(map, isl_multi_id_copy(tuple)); +} + +/* Bind the output dimensions of "umap" to parameters with identifiers + * specified by "tuple", living in the range space of "umap", + * for those maps that have a matching range space. + */ +__isl_give isl_union_set *isl_union_map_bind_range( + __isl_take isl_union_map *umap, __isl_take isl_multi_id *tuple) +{ + struct isl_un_op_control control = { + .filter = &has_range_space, + .filter_user = isl_multi_id_peek_space(tuple), + .fn_map2 = &bind_range, + .fn_map2_user = tuple, + }; + isl_union_set *bound; + + bound = uset_from_umap(un_op(umap, &control)); + isl_multi_id_free(tuple); + return bound; } diff --git a/gcc/isl/isl_union_map_private.h b/gcc/isl/isl_union_map_private.h index b6912d4..2af6c2b 100644 --- a/gcc/isl/isl_union_map_private.h +++ a/gcc/isl/isl_union_map_private.h @@ -10,9 +10,14 @@ struct isl_hash_table table; }; +__isl_keep isl_space *isl_union_map_peek_space(__isl_keep isl_union_map *umap); +__isl_keep isl_space *isl_union_set_peek_space(__isl_keep isl_union_set *uset); +isl_bool isl_union_map_is_params(__isl_keep isl_union_map *umap); isl_bool isl_union_map_space_has_equal_params(__isl_keep isl_union_map *umap, __isl_keep isl_space *space); isl_bool isl_union_set_space_has_equal_params(__isl_keep isl_union_set *uset, __isl_keep isl_space *space); __isl_give isl_union_map *isl_union_map_reset_range_space( + __isl_take isl_union_map *umap, __isl_take isl_space *space); +__isl_give isl_union_map *isl_union_map_reset_equal_dim_space( __isl_take isl_union_map *umap, __isl_take isl_space *space); diff --git a/gcc/isl/isl_union_multi.c b/gcc/isl/isl_union_multi.c index e78e36b..7a28006 100644 --- a/gcc/isl/isl_union_multi.c +++ a/gcc/isl/isl_union_multi.c @@ -13,7 +13,7 @@ * 78153 Le Chesnay Cedex France */ -#include +#include #include /* A group of expressions defined over the same domain space "domain_space". @@ -93,13 +93,13 @@ /* Return the number of base expressions in "u". */ -int FN(FN(UNION,n),PARTS)(__isl_keep UNION *u) +isl_size FN(FN(UNION,n),BASE)(__isl_keep UNION *u) { int n; n = 0; if (FN(UNION,foreach_group)(u, &FN(UNION,count_part), &n) < 0) - n = -1; + return isl_size_error; return n; } @@ -160,7 +160,7 @@ /* Is the space of "entry" equal to "space"? */ -static int FN(UNION,has_space)(const void *entry, const void *val) +static isl_bool FN(UNION,has_space)(const void *entry, const void *val) { PART *part = (PART *) entry; isl_space *space = (isl_space *) val; @@ -209,7 +209,7 @@ &FN(UNION,call_on_copy), user); } -isl_stat FN(FN(UNION,foreach),PARTS)(__isl_keep UNION *u, +isl_stat FN(FN(UNION,foreach),BASE)(__isl_keep UNION *u, isl_stat (*fn)(__isl_take PART *part, void *user), void *user) { S(UNION,foreach_data) data = { fn, user }; @@ -221,9 +221,10 @@ } /* Is the domain space of the group of expressions at "entry" - * equal to "space"? + * equal to that of "space"? */ -static int FN(UNION,group_has_domain_space)(const void *entry, const void *val) +static isl_bool FN(UNION,group_has_same_domain_space)(const void *entry, + const void *val) { S(UNION,group) *group = (S(UNION,group) *) entry; isl_space *space = (isl_space *) val; @@ -246,7 +247,7 @@ { isl_ctx *ctx; uint32_t hash; - struct isl_hash_table_entry *group_entry, *part_entry; + struct isl_hash_table_entry *group_entry; S(UNION,group) *group; if (!u || !space) @@ -255,9 +256,9 @@ ctx = FN(UNION,get_ctx)(u); hash = isl_space_get_domain_hash(space); group_entry = isl_hash_table_find(ctx, &u->table, hash, - &FN(UNION,group_has_domain_space), space, reserve); - if (!group_entry) - return reserve ? NULL : isl_hash_table_entry_none; + &FN(UNION,group_has_same_domain_space), space, reserve); + if (!group_entry || group_entry == isl_hash_table_entry_none) + return group_entry; if (reserve && !group_entry->data) { isl_space *domain = isl_space_domain(isl_space_copy(space)); group = FN(UNION,group_alloc)(domain, 1); @@ -270,11 +271,8 @@ if (!group) return NULL; hash = isl_space_get_hash(space); - part_entry = isl_hash_table_find(ctx, &group->part_table, hash, + return isl_hash_table_find(ctx, &group->part_table, hash, &FN(UNION,has_space), space, reserve); - if (!reserve && !part_entry) - return isl_hash_table_entry_none; - return part_entry; } /* Remove "part_entry" from the hash table of "u". @@ -288,6 +286,7 @@ { isl_ctx *ctx; uint32_t hash; + isl_space *space; PART *part; struct isl_hash_table_entry *group_entry; S(UNION,group) *group; @@ -297,10 +296,13 @@ part = part_entry->data; ctx = FN(UNION,get_ctx)(u); - hash = isl_space_get_domain_hash(part->dim); + space = FN(PART,peek_space)(part); + hash = isl_space_get_domain_hash(space); group_entry = isl_hash_table_find(ctx, &u->table, hash, - &FN(UNION,group_has_domain_space), part->dim, 0); + &FN(UNION,group_has_same_domain_space), space, 0); if (!group_entry) + return FN(UNION,free)(u); + if (group_entry == isl_hash_table_entry_none) isl_die(ctx, isl_error_internal, "missing group", return FN(UNION,free)(u)); group = group_entry->data; @@ -373,16 +375,20 @@ { isl_ctx *ctx; uint32_t hash; + isl_space *space; struct isl_hash_table_entry *group_entry; S(UNION,group) *group; if (!u || !part) return isl_stat_error; ctx = FN(UNION,get_ctx)(u); - hash = isl_space_get_domain_hash(part->dim); + space = FN(PART,peek_space)(part); + hash = isl_space_get_domain_hash(space); group_entry = isl_hash_table_find(ctx, &u->table, hash, - &FN(UNION,group_has_domain_space), part->dim, 0); + &FN(UNION,group_has_same_domain_space), space, 0); if (!group_entry) + return isl_stat_error; + if (group_entry == isl_hash_table_entry_none) return isl_stat_ok; group = group_entry->data; return isl_hash_table_foreach(ctx, &group->part_table, @@ -443,23 +449,89 @@ S(UNION,foreach_inplace_data) data = { fn, user }; return FN(UNION,foreach_group)(u, &FN(UNION,group_call_inplace), &data); +} + +static isl_stat FN(UNION,free_u_entry)(void **entry, void *user) +{ + S(UNION,group) *group = *entry; + FN(UNION,group_free)(group); + return isl_stat_ok; +} + +/* Set "single" to true if this group of expressions + * contains an expression living in exactly one space. + */ +static isl_stat FN(UNION,group_single_space)(__isl_keep S(UNION,group) *group, + void *user) +{ + isl_bool *single = user; + + if (!group) + return isl_stat_error; + *single = isl_bool_ok(group->part_table.n == 1); + return isl_stat_ok; } -/* Does "u" have a single reference? - * That is, can we change "u" inplace? +/* Can this union expression be converted to a single base expression? + * That is, does it contain a base expression in exactly one space? + * In particular, is only one domain space involved and + * is only a single expression associated to that domain? */ -static isl_bool FN(UNION,has_single_reference)(__isl_keep UNION *u) +isl_bool FN(FN(UNION,isa),BASE)(__isl_take UNION *u) { + isl_bool single; + if (!u) return isl_bool_error; - return u->ref == 1; + if (u->table.n != 1) + return isl_bool_false; + if (FN(UNION,foreach_group)(u, + &FN(UNION,group_single_space), &single) < 0) + return isl_bool_error; + return single; } -static isl_stat FN(UNION,free_u_entry)(void **entry, void *user) +/* Callback for isl_union_*_foreach_inplace call + * on a union expression with a single base expression. + * Store that base expression in "user". + * This callback should only be called once + * for any given isl_union_*_foreach_inplace call. + */ +static isl_stat FN(UNION,extract_part)(void **entry, void *user) { - S(UNION,group) *group = *entry; - FN(UNION,group_free)(group); + PART **part_p = user; + PART *part = *entry; + + if (*part_p) + isl_die(FN(PART,get_ctx)(part), isl_error_internal, + "more than one part", return isl_stat_error); + *part_p = FN(PART,copy)(part); + if (!*part_p) + return isl_stat_error; return isl_stat_ok; +} + +/* Convert the union expression to its single base expression. + */ +__isl_give PART *FN(FN(UNION,as),BASE)(__isl_take UNION *u) +{ + isl_bool has_single_space; + PART *part = NULL; + + has_single_space = FN(FN(UNION,isa),BASE)(u); + if (has_single_space < 0) + goto error; + if (!has_single_space) + isl_die(FN(UNION,get_ctx)(u), isl_error_invalid, + "expecting elements in exactly one space", + goto error); + if (FN(UNION,foreach_inplace)(u, &FN(UNION,extract_part), &part) < 0) + part = FN(PART,free)(part); + FN(UNION,free)(u); + return part; +error: + FN(UNION,free)(u); + return NULL; } #include diff --git a/gcc/isl/isl_union_single.c b/gcc/isl/isl_union_single.c index d365aae..1ec7c45 100644 --- a/gcc/isl/isl_union_single.c +++ a/gcc/isl/isl_union_single.c @@ -10,7 +10,7 @@ * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France */ -#include +#include #include /* A union of expressions defined over different domain spaces. @@ -29,9 +29,9 @@ /* Return the number of base expressions in "u". */ -int FN(FN(UNION,n),PARTS)(__isl_keep UNION *u) +isl_size FN(FN(UNION,n),BASE)(__isl_keep UNION *u) { - return u ? u->table.n : 0; + return u ? u->table.n : isl_size_error; } S(UNION,foreach_data) @@ -51,7 +51,7 @@ return data->fn(part, data->user); } -isl_stat FN(FN(UNION,foreach),PARTS)(__isl_keep UNION *u, +isl_stat FN(FN(UNION,foreach),BASE)(__isl_keep UNION *u, isl_stat (*fn)(__isl_take PART *part, void *user), void *user) { S(UNION,foreach_data) data = { fn, user }; @@ -65,7 +65,8 @@ /* Is the domain space of "entry" equal to the domain of "space"? */ -static int FN(UNION,has_same_domain_space)(const void *entry, const void *val) +static isl_bool FN(UNION,has_same_domain_space)(const void *entry, + const void *val) { PART *part = (PART *)entry; isl_space *space = (isl_space *) val; @@ -102,8 +103,8 @@ hash = isl_space_get_domain_hash(space); entry = isl_hash_table_find(ctx, &u->table, hash, &FN(UNION,has_same_domain_space), space, reserve); - if (!entry) - return reserve ? NULL : isl_hash_table_entry_none; + if (!entry || entry == isl_hash_table_entry_none) + return entry; if (reserve && !entry->data) return entry; part = entry->data; @@ -175,16 +176,6 @@ return isl_stat_error; ctx = FN(UNION,get_ctx)(u); return isl_hash_table_foreach(ctx, &u->table, fn, user); -} - -/* Does "u" have a single reference? - * That is, can we change "u" inplace? - */ -static isl_bool FN(UNION,has_single_reference)(__isl_keep UNION *u) -{ - if (!u) - return isl_bool_error; - return u->ref == 1; } static isl_stat FN(UNION,free_u_entry)(void **entry, void *user) diff --git a/gcc/isl/isl_union_templ.c b/gcc/isl/isl_union_templ.c index b2ad551..1848fa8 100644 --- a/gcc/isl/isl_union_templ.c +++ a/gcc/isl/isl_union_templ.c @@ -10,6 +10,11 @@ * and Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France */ +#undef TYPE +#define TYPE UNION +static +#include "has_single_reference_templ.c" + __isl_give UNION *FN(UNION,cow)(__isl_take UNION *u); isl_ctx *FN(UNION,get_ctx)(__isl_keep UNION *u) @@ -17,24 +22,33 @@ return u ? u->space->ctx : NULL; } -__isl_give isl_space *FN(UNION,get_space)(__isl_keep UNION *u) +/* Return the space of "u". + */ +static __isl_keep isl_space *FN(UNION,peek_space)(__isl_keep UNION *u) { if (!u) return NULL; - return isl_space_copy(u->space); + return u->space; +} + +/* Return a copy of the space of "u". + */ +__isl_give isl_space *FN(UNION,get_space)(__isl_keep UNION *u) +{ + return isl_space_copy(FN(UNION,peek_space)(u)); } /* Return the number of parameters of "u", where "type" * is required to be set to isl_dim_param. */ -unsigned FN(UNION,dim)(__isl_keep UNION *u, enum isl_dim_type type) +isl_size FN(UNION,dim)(__isl_keep UNION *u, enum isl_dim_type type) { if (!u) - return 0; + return isl_size_error; if (type != isl_dim_param) isl_die(FN(UNION,get_ctx)(u), isl_error_invalid, - "can only reference parameters", return 0); + "can only reference parameters", return isl_size_error); return isl_space_dim(u->space, type); } @@ -51,48 +65,55 @@ return isl_space_find_dim_by_name(u->space, type, name); } -#ifdef HAS_TYPE -static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_space *dim, - enum isl_fold type, int size) -#else -static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_space *dim, int size) -#endif +#include "opt_type.h" + +static __isl_give UNION *FN(UNION,alloc)(__isl_take isl_space *space + OPT_TYPE_PARAM, int size) { UNION *u; - dim = isl_space_params(dim); - if (!dim) + space = isl_space_params(space); + if (!space) return NULL; - u = isl_calloc_type(dim->ctx, UNION); + u = isl_calloc_type(space->ctx, UNION); if (!u) goto error; u->ref = 1; -#ifdef HAS_TYPE - u->type = type; -#endif - u->space = dim; - if (isl_hash_table_init(dim->ctx, &u->table, size) < 0) + OPT_SET_TYPE(u->, type); + u->space = space; + if (isl_hash_table_init(space->ctx, &u->table, size) < 0) return FN(UNION,free)(u); return u; error: - isl_space_free(dim); + isl_space_free(space); return NULL; } -#ifdef HAS_TYPE -__isl_give UNION *FN(UNION,ZERO)(__isl_take isl_space *dim, enum isl_fold type) +/* Create an empty/zero union without specifying any parameters. + */ +__isl_give UNION *FN(FN(UNION,ZERO),ctx)(isl_ctx *ctx OPT_TYPE_PARAM) { - return FN(UNION,alloc)(dim, type, 16); + isl_space *space; + + space = isl_space_unit(ctx); + return FN(FN(UNION,ZERO),space)(space OPT_TYPE_ARG(NO_LOC)); } -#else -__isl_give UNION *FN(UNION,ZERO)(__isl_take isl_space *dim) + +__isl_give UNION *FN(FN(UNION,ZERO),space)(__isl_take isl_space *space + OPT_TYPE_PARAM) { - return FN(UNION,alloc)(dim, 16); + return FN(UNION,alloc)(space OPT_TYPE_ARG(NO_LOC), 16); } -#endif + +/* This is an alternative name for the function above. + */ +__isl_give UNION *FN(UNION,ZERO)(__isl_take isl_space *space OPT_TYPE_PARAM) +{ + return FN(FN(UNION,ZERO),space)(space OPT_TYPE_ARG(NO_LOC)); +} __isl_give UNION *FN(UNION,copy)(__isl_keep UNION *u) { @@ -108,35 +129,18 @@ * Return the ZERO element if "u" does not contain any element * living in "space". */ -__isl_give PART *FN(FN(UNION,extract),PARTS)(__isl_keep UNION *u, +__isl_give PART *FN(FN(UNION,extract),BASE)(__isl_keep UNION *u, __isl_take isl_space *space) { struct isl_hash_table_entry *entry; - isl_bool equal_params; - if (!u || !space) - goto error; - equal_params = isl_space_has_equal_params(u->space, space); - if (equal_params < 0) - goto error; - if (!equal_params) { - space = isl_space_drop_dims(space, isl_dim_param, - 0, isl_space_dim(space, isl_dim_param)); - space = isl_space_align_params(space, - FN(UNION,get_space)(u)); - if (!space) - goto error; - } + space = isl_space_replace_params(space, FN(UNION,peek_space)(u)); entry = FN(UNION,find_part_entry)(u, space, 0); if (!entry) goto error; if (entry == isl_hash_table_entry_none) -#ifdef HAS_TYPE - return FN(PART,ZERO)(space, u->type); -#else - return FN(PART,ZERO)(space); -#endif + return FN(PART,ZERO)(space OPT_TYPE_ARG(u->)); isl_space_free(space); return FN(PART,copy)(entry->data); error: @@ -210,40 +214,25 @@ /* Add "part" to "u", where "u" is assumed not to already have * a part that is defined on the same space as "part". */ -__isl_give UNION *FN(FN(UNION,add),PARTS)(__isl_take UNION *u, +__isl_give UNION *FN(FN(UNION,add),BASE)(__isl_take UNION *u, __isl_take PART *part) { return FN(UNION,add_part_generic)(u, part, 1); } -#ifdef HAS_TYPE -/* Allocate a UNION with the same type and the same size as "u" and +/* Allocate a UNION with the same type (if any) and the same size as "u" and * with space "space". - */ -static __isl_give UNION *FN(UNION,alloc_same_size_on_space)(__isl_keep UNION *u, - __isl_take isl_space *space) -{ - if (!u) - goto error; - return FN(UNION,alloc)(space, u->type, u->table.n); -error: - isl_space_free(space); - return NULL; -} -#else -/* Allocate a UNION with the same size as "u" and with space "space". */ static __isl_give UNION *FN(UNION,alloc_same_size_on_space)(__isl_keep UNION *u, __isl_take isl_space *space) { if (!u) goto error; - return FN(UNION,alloc)(space, u->table.n); + return FN(UNION,alloc)(space OPT_TYPE_ARG(u->), u->table.n); error: isl_space_free(space); return NULL; } -#endif /* Allocate a UNION with the same space, the same type (if any) and * the same size as "u". @@ -252,69 +241,105 @@ { return FN(UNION,alloc_same_size_on_space)(u, FN(UNION,get_space)(u)); } + +/* Data structure that specifies how isl_union_*_transform + * should modify the base expressions in the union expression. + * + * If "inplace" is set, then the base expression in the input union + * are modified in place. This means that "fn" should not + * change the meaning of the union or that the union only + * has a single reference. + * If "space" is not NULL, then a new union is created in this space. + * If "filter" is not NULL, then only the base expressions that satisfy "filter" + * are taken into account. + * "fn" is applied to each entry in the input. + * "fn_user" is passed as the second argument to "fn". + */ +S(UNION,transform_control) { + int inplace; + isl_space *space; + isl_bool (*filter)(__isl_keep PART *part); + __isl_give PART *(*fn)(__isl_take PART *part, void *user); + void *fn_user; +}; /* Internal data structure for isl_union_*_transform_space. - * "fn' is applied to each entry in the input. - * "res" collects the results. + * "control" specifies how the base expressions should be modified. + * "res" collects the results (if control->inplace is not set). */ S(UNION,transform_data) { - __isl_give PART *(*fn)(__isl_take PART *part, void *user); - void *user; - + S(UNION,transform_control) *control; UNION *res; }; -/* Apply data->fn to "part" and add the result to data->res. +/* Apply control->fn to "part" and add the result to data->res or + * place it back into the input union if control->inplace is set. */ -static isl_stat FN(UNION,transform_entry)(__isl_take PART *part, void *user) +static isl_stat FN(UNION,transform_entry)(void **entry, void *user) { S(UNION,transform_data) *data = (S(UNION,transform_data) *)user; + PART *part = *entry; + + if (data->control->filter) { + isl_bool handle; + + handle = data->control->filter(part); + if (handle < 0) + return isl_stat_error; + if (!handle) + return isl_stat_ok; + } - part = data->fn(part, data->user); - data->res = FN(FN(UNION,add),PARTS)(data->res, part); - if (!data->res) + if (!data->control->inplace) + part = FN(PART,copy)(part); + part = data->control->fn(part, data->control->fn_user); + if (data->control->inplace) + *entry = part; + else + data->res = FN(FN(UNION,add),BASE)(data->res, part); + if (!part || !data->res) return isl_stat_error; return isl_stat_ok; } -/* Return a UNION living in "space" that is obtained by applying "fn" - * to each of the entries in "u". +/* Return a UNION that is obtained by modifying "u" according to "control". */ -static __isl_give UNION *FN(UNION,transform_space)(__isl_take UNION *u, - isl_space *space, - __isl_give PART *(*fn)(__isl_take PART *part, void *user), void *user) +static __isl_give UNION *FN(UNION,transform)(__isl_take UNION *u, + S(UNION,transform_control) *control) { - S(UNION,transform_data) data = { fn, user }; + S(UNION,transform_data) data = { control }; + isl_space *space; - data.res = FN(UNION,alloc_same_size_on_space)(u, space); - if (FN(FN(UNION,foreach),PARTS)(u, - &FN(UNION,transform_entry), &data) < 0) + if (control->inplace) { + data.res = u; + } else { + if (control->space) + space = isl_space_copy(control->space); + else + space = FN(UNION,get_space)(u); + data.res = FN(UNION,alloc_same_size_on_space)(u, space); + } + if (FN(UNION,foreach_inplace)(u, &FN(UNION,transform_entry), &data) < 0) data.res = FN(UNION,free)(data.res); - FN(UNION,free)(u); + if (!control->inplace) + FN(UNION,free)(u); return data.res; -} - -/* Return a UNION that lives in the same space as "u" and that is obtained - * by applying "fn" to each of the entries in "u". - */ -static __isl_give UNION *FN(UNION,transform)(__isl_take UNION *u, - __isl_give PART *(*fn)(__isl_take PART *part, void *user), void *user) -{ - return FN(UNION,transform_space)(u, FN(UNION,get_space)(u), fn, user); } -/* Apply data->fn to *part and store the result back into *part. +/* Return a UNION living in "space" that is otherwise obtained by modifying "u" + * according to "control". */ -static isl_stat FN(UNION,transform_inplace_entry)(void **part, void *user) +static __isl_give UNION *FN(UNION,transform_space)(__isl_take UNION *u, + __isl_take isl_space *space, S(UNION,transform_control) *control) { - S(UNION,transform_data) *data = (S(UNION,transform_data) *) user; - - *part = data->fn(*part, data->user); - if (!*part) - return isl_stat_error; - return isl_stat_ok; + if (!space) + return FN(UNION,free)(u); + control->space = space; + u = FN(UNION,transform)(u, control); + isl_space_free(space); + return u; } /* Update "u" by applying "fn" to each entry. @@ -327,19 +352,15 @@ static __isl_give UNION *FN(UNION,transform_inplace)(__isl_take UNION *u, __isl_give PART *(*fn)(__isl_take PART *part, void *user), void *user) { + S(UNION,transform_control) control = { .fn = fn, .fn_user = user }; isl_bool single_ref; single_ref = FN(UNION,has_single_reference)(u); if (single_ref < 0) return FN(UNION,free)(u); - if (single_ref) { - S(UNION,transform_data) data = { fn, user }; - if (FN(UNION,foreach_inplace)(u, - &FN(UNION,transform_inplace_entry), &data) < 0) - return FN(UNION,free)(u); - return u; - } - return FN(UNION,transform)(u, fn, user); + if (single_ref) + control.inplace = 1; + return FN(UNION,transform)(u, &control); } /* An isl_union_*_transform callback for use in isl_union_*_dup @@ -352,8 +373,10 @@ __isl_give UNION *FN(UNION,dup)(__isl_keep UNION *u) { + S(UNION,transform_control) control = { .fn = &FN(UNION,copy_part) }; + u = FN(UNION,copy)(u); - return FN(UNION,transform)(u, &FN(UNION,copy_part), NULL); + return FN(UNION,transform)(u, &control); } __isl_give UNION *FN(UNION,cow)(__isl_take UNION *u) @@ -397,13 +420,17 @@ static __isl_give UNION *FN(UNION,realign_domain)(__isl_take UNION *u, __isl_take isl_reordering *r) { + S(UNION,transform_control) control = { + .fn = &FN(UNION,align_entry), + .fn_user = r, + }; isl_space *space; if (!u || !r) goto error; - space = isl_space_copy(r->dim); - u = FN(UNION,transform_space)(u, space, &FN(UNION,align_entry), r); + space = isl_reordering_get_space(r); + u = FN(UNION,transform_space)(u, space, &control); isl_reordering_free(r); return u; error: @@ -431,7 +458,6 @@ return u; } - model = isl_space_params(model); r = isl_parameter_alignment_reordering(u->space, model); isl_space_free(model); @@ -475,7 +501,7 @@ if (!u1 || !u2) goto error; - if (FN(FN(UNION,foreach),PARTS)(u2, &FN(UNION,union_add_part), &u1) < 0) + if (FN(FN(UNION,foreach),BASE)(u2, &FN(UNION,union_add_part), &u1) < 0) goto error; FN(UNION,free)(u2); @@ -487,23 +513,21 @@ return NULL; } -__isl_give UNION *FN(FN(UNION,from),PARTS)(__isl_take PART *part) +__isl_give UNION *FN(FN(UNION,from),BASE)(__isl_take PART *part) { - isl_space *dim; + isl_space *space; UNION *u; if (!part) return NULL; - dim = FN(PART,get_space)(part); - dim = isl_space_drop_dims(dim, isl_dim_in, 0, isl_space_dim(dim, isl_dim_in)); - dim = isl_space_drop_dims(dim, isl_dim_out, 0, isl_space_dim(dim, isl_dim_out)); -#ifdef HAS_TYPE - u = FN(UNION,ZERO)(dim, part->type); -#else - u = FN(UNION,ZERO)(dim); -#endif - u = FN(FN(UNION,add),PARTS)(u, part); + space = FN(PART,get_space)(part); + space = isl_space_drop_dims(space, isl_dim_in, 0, + isl_space_dim(space, isl_dim_in)); + space = isl_space_drop_dims(space, isl_dim_out, 0, + isl_space_dim(space, isl_dim_out)); + u = FN(UNION,ZERO)(space OPT_TYPE_ARG(part->)); + u = FN(FN(UNION,add),BASE)(u, part); return u; } @@ -544,7 +568,7 @@ part = data->fn(part, FN(PART, copy)(entry2->data)); - data->res = FN(FN(UNION,add),PARTS)(data->res, part); + data->res = FN(FN(UNION,add),BASE)(data->res, part); if (!data->res) return isl_stat_error; @@ -578,7 +602,7 @@ data.u2 = u2; data.res = FN(UNION,alloc_same_size)(u1); - if (FN(FN(UNION,foreach),PARTS)(u1, + if (FN(FN(UNION,foreach),BASE)(u1, &FN(UNION,match_bin_entry), &data) < 0) goto error; @@ -636,6 +660,10 @@ __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*)) { S(UNION,any_set_data) data = { NULL, fn }; + S(UNION,transform_control) control = { + .fn = &FN(UNION,any_set_entry), + .fn_user = &data, + }; u = FN(UNION,align_params)(u, isl_set_get_space(set)); set = isl_set_align_params(set, FN(UNION,get_space)(u)); @@ -644,7 +672,7 @@ goto error; data.set = set; - u = FN(UNION,transform)(u, &FN(UNION,any_set_entry), &data); + u = FN(UNION,transform)(u, &control); isl_set_free(set); return u; error: @@ -669,19 +697,38 @@ { return FN(UNION,any_set_op)(u, set, &FN(PW,gist_params)); } + +/* Data structure that specifies how isl_union_*_match_domain_op + * should combine its arguments. + * + * If "filter" is not NULL, then only parts that pass the given + * filter are considered for matching. + * "fn" is applied to each part in the union and each corresponding + * set in the union set, i.e., such that the set lives in the same space + * as the domain of the part. + * If "match_space" is not NULL, then the set extracted from the union set + * does not live in the same space as the domain of the part, + * but rather in the space that results from calling "match_space" + * on this domain space. + */ +S(UNION,match_domain_control) { + isl_bool (*filter)(__isl_keep PART *part); + __isl_give isl_space *(*match_space)(__isl_take isl_space *space); + __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*); +}; S(UNION,match_domain_data) { isl_union_set *uset; UNION *res; - __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*); + S(UNION,match_domain_control) *control; }; -static int FN(UNION,set_has_dim)(const void *entry, const void *val) +static isl_bool FN(UNION,set_has_space)(const void *entry, const void *val) { isl_set *set = (isl_set *)entry; - isl_space *dim = (isl_space *)val; + isl_space *space = (isl_space *)val; - return isl_space_is_equal(set->dim, dim); + return isl_space_is_equal(set->dim, space); } /* Find the set in data->uset that lives in the same space as the domain @@ -693,46 +740,53 @@ S(UNION,match_domain_data) *data = user; uint32_t hash; struct isl_hash_table_entry *entry2; - isl_space *space; + isl_space *space, *uset_space; + + if (data->control->filter) { + isl_bool pass = data->control->filter(part); + if (pass < 0 || !pass) { + FN(PART,free)(part); + return pass < 0 ? isl_stat_error : isl_stat_ok; + } + } + uset_space = isl_union_set_peek_space(data->uset); space = FN(PART,get_domain_space)(part); + if (data->control->match_space) + space = data->control->match_space(space); + space = isl_space_replace_params(space, uset_space); hash = isl_space_get_hash(space); entry2 = isl_hash_table_find(data->uset->dim->ctx, &data->uset->table, - hash, &FN(UNION,set_has_dim), space, 0); + hash, &FN(UNION,set_has_space), space, 0); isl_space_free(space); - if (!entry2) { + if (!entry2 || entry2 == isl_hash_table_entry_none) { FN(PART,free)(part); - return isl_stat_ok; + return isl_stat_non_null(entry2); } - part = data->fn(part, isl_set_copy(entry2->data)); + part = data->control->fn(part, isl_set_copy(entry2->data)); - data->res = FN(FN(UNION,add),PARTS)(data->res, part); + data->res = FN(FN(UNION,add),BASE)(data->res, part); if (!data->res) return isl_stat_error; return isl_stat_ok; } -/* Apply fn to each pair of PW in u and set in uset such that - * the set lives in the same space as the domain of PW +/* Combine "u" and "uset" according to "control" * and collect the results. */ static __isl_give UNION *FN(UNION,match_domain_op)(__isl_take UNION *u, - __isl_take isl_union_set *uset, - __isl_give PW *(*fn)(__isl_take PW*, __isl_take isl_set*)) + __isl_take isl_union_set *uset, S(UNION,match_domain_control) *control) { - S(UNION,match_domain_data) data = { NULL, NULL, fn }; - - u = FN(UNION,align_params)(u, isl_union_set_get_space(uset)); - uset = isl_union_set_align_params(uset, FN(UNION,get_space)(u)); + S(UNION,match_domain_data) data = { NULL, NULL, control }; if (!u || !uset) goto error; data.uset = uset; data.res = FN(UNION,alloc_same_size)(u); - if (FN(FN(UNION,foreach),PARTS)(u, + if (FN(FN(UNION,foreach),BASE)(u, &FN(UNION,match_domain_entry), &data) < 0) goto error; @@ -753,12 +807,53 @@ __isl_give UNION *FN(UNION,intersect_domain)(__isl_take UNION *u, __isl_take isl_union_set *uset) { + S(UNION,match_domain_control) control = { + .fn = &FN(PW,intersect_domain), + }; + if (isl_union_set_is_params(uset)) return FN(UNION,intersect_params)(u, isl_set_from_union_set(uset)); - return FN(UNION,match_domain_op)(u, uset, &FN(PW,intersect_domain)); + return FN(UNION,match_domain_op)(u, uset, &control); +} + +/* Is the domain of "pw" a wrapped relation? + */ +static isl_bool FN(PW,domain_is_wrapping)(__isl_keep PW *pw) +{ + return isl_space_domain_is_wrapping(FN(PW,peek_space)(pw)); } +/* Intersect the domain of the wrapped relation inside the domain of "u" + * with "uset". + */ +__isl_give UNION *FN(UNION,intersect_domain_wrapped_domain)(__isl_take UNION *u, + __isl_take isl_union_set *uset) +{ + S(UNION,match_domain_control) control = { + .filter = &FN(PART,domain_is_wrapping), + .match_space = &isl_space_factor_domain, + .fn = &FN(PW,intersect_domain_wrapped_domain), + }; + + return FN(UNION,match_domain_op)(u, uset, &control); +} + +/* Intersect the range of the wrapped relation inside the domain of "u" + * with "uset". + */ +__isl_give UNION *FN(UNION,intersect_domain_wrapped_range)(__isl_take UNION *u, + __isl_take isl_union_set *uset) +{ + S(UNION,match_domain_control) control = { + .filter = &FN(PART,domain_is_wrapping), + .match_space = &isl_space_factor_range, + .fn = &FN(PW,intersect_domain_wrapped_range), + }; + + return FN(UNION,match_domain_op)(u, uset, &control); +} + /* Take the set (which may be empty) in data->uset that lives * in the same space as the domain of "pw", subtract it from the domain * of "part" and return the result. @@ -775,12 +870,17 @@ return FN(PART,subtract_domain)(part, set); } -/* Subtract "uset' from the domain of "u". +/* Subtract "uset" from the domain of "u". */ __isl_give UNION *FN(UNION,subtract_domain)(__isl_take UNION *u, __isl_take isl_union_set *uset) { - u = FN(UNION,transform)(u, &FN(UNION,subtract_domain_entry), uset); + S(UNION,transform_control) control = { + .fn = &FN(UNION,subtract_domain_entry), + .fn_user = uset, + }; + + u = FN(UNION,transform)(u, &control); isl_union_set_free(uset); return u; } @@ -788,9 +888,13 @@ __isl_give UNION *FN(UNION,gist)(__isl_take UNION *u, __isl_take isl_union_set *uset) { + S(UNION,match_domain_control) control = { + .fn = &FN(PW,gist), + }; + if (isl_union_set_is_params(uset)) return FN(UNION,gist_params)(u, isl_set_from_union_set(uset)); - return FN(UNION,match_domain_op)(u, uset, &FN(PW,gist)); + return FN(UNION,match_domain_op)(u, uset, &control); } /* Coalesce an entry in a UNION. Coalescing is performed in-place. @@ -837,7 +941,7 @@ isl_union_set *uset; uset = isl_union_set_empty(FN(UNION,get_space)(u)); - if (FN(FN(UNION,foreach),PARTS)(u, &FN(UNION,domain_entry), &uset) < 0) + if (FN(FN(UNION,foreach),BASE)(u, &FN(UNION,domain_entry), &uset) < 0) goto error; FN(UNION,free)(u); @@ -895,11 +999,7 @@ if (DEFAULT_IS_ZERO && u && isl_val_is_zero(v)) { UNION *zero; isl_space *space = FN(UNION,get_space)(u); -#ifdef HAS_TYPE - zero = FN(UNION,ZERO)(space, u->type); -#else - zero = FN(UNION,ZERO)(space); -#endif + zero = FN(UNION,ZERO)(space OPT_TYPE_ARG(u->)); FN(UNION,free)(u); isl_val_free(v); return zero; @@ -993,7 +1093,7 @@ isl_bool FN(UNION,plain_is_equal)(__isl_keep UNION *u1, __isl_keep UNION *u2) { S(UNION,plain_is_equal_data) data = { NULL, isl_bool_true }; - int n1, n2; + isl_size n1, n2; if (!u1 || !u2) return isl_bool_error; @@ -1001,8 +1101,8 @@ return isl_bool_true; if (u1->table.n != u2->table.n) return isl_bool_false; - n1 = FN(FN(UNION,n),PARTS)(u1); - n2 = FN(FN(UNION,n),PARTS)(u2); + n1 = FN(FN(UNION,n),BASE)(u1); + n2 = FN(FN(UNION,n),BASE)(u2); if (n1 < 0 || n2 < 0) return isl_bool_error; if (n1 != n2) @@ -1091,6 +1191,10 @@ { isl_space *space; S(UNION,drop_dims_data) data = { type, first, n }; + S(UNION,transform_control) control = { + .fn = &FN(UNION,drop_dims_entry), + .fn_user = &data, + }; if (!u) return NULL; @@ -1102,8 +1206,7 @@ space = FN(UNION,get_space)(u); space = isl_space_drop_dims(space, type, first, n); - return FN(UNION,transform_space)(u, space, &FN(UNION,drop_dims_entry), - &data); + return FN(UNION,transform_space)(u, space, &control); } /* Internal data structure for isl_union_*_set_dim_name. @@ -1133,6 +1236,10 @@ enum isl_dim_type type, unsigned pos, const char *s) { S(UNION,set_dim_name_data) data = { pos, s }; + S(UNION,transform_control) control = { + .fn = &FN(UNION,set_dim_name_entry), + .fn_user = &data, + }; isl_space *space; if (!u) @@ -1145,8 +1252,7 @@ space = FN(UNION,get_space)(u); space = isl_space_set_dim_name(space, type, pos, s); - return FN(UNION,transform_space)(u, space, - &FN(UNION,set_dim_name_entry), &data); + return FN(UNION,transform_space)(u, space, &control); } /* Reset the user pointer on all identifiers of parameters and tuples @@ -1163,10 +1269,48 @@ */ __isl_give UNION *FN(UNION,reset_user)(__isl_take UNION *u) { + S(UNION,transform_control) control = { + .fn = &FN(UNION,reset_user_entry), + }; isl_space *space; space = FN(UNION,get_space)(u); space = isl_space_reset_user(space); - return FN(UNION,transform_space)(u, space, &FN(UNION,reset_user_entry), - NULL); + return FN(UNION,transform_space)(u, space, &control); +} + +/* Add the base expression held by "entry" to "list". + */ +static isl_stat FN(UNION,add_to_list)(void **entry, void *user) +{ + PW *pw = *entry; + LIST(PART) **list = user; + + *list = FN(LIST(PART),add)(*list, FN(PART,copy)(pw)); + if (!*list) + return isl_stat_error; + + return isl_stat_ok; +} + +/* Return a list containing all the base expressions in "u". + * + * First construct a list of the appropriate size and + * then add all the elements. + */ +__isl_give LIST(PART) *FN(FN(UNION,get),LIST(BASE))(__isl_keep UNION *u) +{ + isl_size n; + LIST(PART) *list; + + if (!u) + return NULL; + n = FN(FN(UNION,n),BASE)(u); + if (n < 0) + return NULL; + list = FN(LIST(PART),alloc)(FN(UNION,get_ctx(u)), n); + if (FN(UNION,foreach_inplace)(u, &FN(UNION,add_to_list), &list) < 0) + return FN(LIST(PART),free)(list); + + return list; } diff --git a/gcc/isl/isl_val.c b/gcc/isl/isl_val.c index e6d4cba..ed438fa 100644 --- a/gcc/isl/isl_val.c +++ a/gcc/isl/isl_val.c @@ -11,8 +11,8 @@ #include #include -#undef BASE -#define BASE val +#undef EL_BASE +#define EL_BASE val #include @@ -295,15 +295,15 @@ * * If "v" is not a rational value, then the result is undefined. */ -int isl_val_get_num_isl_int(__isl_keep isl_val *v, isl_int *n) +isl_stat isl_val_get_num_isl_int(__isl_keep isl_val *v, isl_int *n) { if (!v) - return -1; + return isl_stat_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return -1); + "expecting rational value", return isl_stat_error); isl_int_set(*n, v->n); - return 0; + return isl_stat_ok; } /* Extract the denominator of a rational value "v" as an integer. @@ -528,7 +528,7 @@ /* Return 2^v, where v is an integer (that is not too large). */ -__isl_give isl_val *isl_val_2exp(__isl_take isl_val *v) +__isl_give isl_val *isl_val_pow2(__isl_take isl_val *v) { unsigned long exp; int neg; @@ -555,6 +555,13 @@ } return v; +} + +/* This is an alternative name for the function above. + */ +__isl_give isl_val *isl_val_2exp(__isl_take isl_val *v) +{ + return isl_val_pow2(v); } /* Return the minimum of "v1" and "v2". @@ -962,7 +969,7 @@ isl_die(isl_val_get_ctx(v1), isl_error_invalid, "expecting two integers", return isl_bool_error); - return isl_int_is_divisible_by(v1->n, v2->n); + return isl_bool_ok(isl_int_is_divisible_by(v1->n, v2->n)); } /* Given two integer values "v1" and "v2", return the residue of "v1" @@ -1135,7 +1142,7 @@ if (!v) return isl_bool_error; - return isl_int_is_one(v->d); + return isl_bool_ok(isl_int_is_one(v->d)); } /* Does "v" represent a rational value? @@ -1145,7 +1152,7 @@ if (!v) return isl_bool_error; - return !isl_int_is_zero(v->d); + return isl_bool_ok(!isl_int_is_zero(v->d)); } /* Does "v" represent NaN? @@ -1155,7 +1162,7 @@ if (!v) return isl_bool_error; - return isl_int_is_zero(v->n) && isl_int_is_zero(v->d); + return isl_bool_ok(isl_int_is_zero(v->n) && isl_int_is_zero(v->d)); } /* Does "v" represent +infinity? @@ -1165,7 +1172,7 @@ if (!v) return isl_bool_error; - return isl_int_is_pos(v->n) && isl_int_is_zero(v->d); + return isl_bool_ok(isl_int_is_pos(v->n) && isl_int_is_zero(v->d)); } /* Does "v" represent -infinity? @@ -1175,7 +1182,7 @@ if (!v) return isl_bool_error; - return isl_int_is_neg(v->n) && isl_int_is_zero(v->d); + return isl_bool_ok(isl_int_is_neg(v->n) && isl_int_is_zero(v->d)); } /* Does "v" represent the integer zero? @@ -1185,7 +1192,7 @@ if (!v) return isl_bool_error; - return isl_int_is_zero(v->n) && !isl_int_is_zero(v->d); + return isl_bool_ok(isl_int_is_zero(v->n) && !isl_int_is_zero(v->d)); } /* Does "v" represent the integer one? @@ -1198,7 +1205,7 @@ if (isl_val_is_nan(v)) return isl_bool_false; - return isl_int_eq(v->n, v->d); + return isl_bool_ok(isl_int_eq(v->n, v->d)); } /* Does "v" represent the integer negative one? @@ -1208,7 +1215,7 @@ if (!v) return isl_bool_error; - return isl_int_is_neg(v->n) && isl_int_abs_eq(v->n, v->d); + return isl_bool_ok(isl_int_is_neg(v->n) && isl_int_abs_eq(v->n, v->d)); } /* Is "v" (strictly) positive? @@ -1218,7 +1225,7 @@ if (!v) return isl_bool_error; - return isl_int_is_pos(v->n); + return isl_bool_ok(isl_int_is_pos(v->n)); } /* Is "v" (strictly) negative? @@ -1228,7 +1235,7 @@ if (!v) return isl_bool_error; - return isl_int_is_neg(v->n); + return isl_bool_ok(isl_int_is_neg(v->n)); } /* Is "v" non-negative? @@ -1241,7 +1248,7 @@ if (isl_val_is_nan(v)) return isl_bool_false; - return isl_int_is_nonneg(v->n); + return isl_bool_ok(isl_int_is_nonneg(v->n)); } /* Is "v" non-positive? @@ -1254,7 +1261,7 @@ if (isl_val_is_nan(v)) return isl_bool_false; - return isl_int_is_nonpos(v->n); + return isl_bool_ok(isl_int_is_nonpos(v->n)); } /* Return the sign of "v". @@ -1282,7 +1289,7 @@ if (!v1 || !v2) return isl_bool_error; if (isl_val_is_int(v1) && isl_val_is_int(v2)) - return isl_int_lt(v1->n, v2->n); + return isl_bool_ok(isl_int_lt(v1->n, v2->n)); if (isl_val_is_nan(v1) || isl_val_is_nan(v2)) return isl_bool_false; if (isl_val_eq(v1, v2)) @@ -1299,7 +1306,7 @@ isl_int_init(t); isl_int_mul(t, v1->n, v2->d); isl_int_submul(t, v2->n, v1->d); - lt = isl_int_is_neg(t); + lt = isl_bool_ok(isl_int_is_neg(t)); isl_int_clear(t); return lt; @@ -1310,6 +1317,31 @@ isl_bool isl_val_gt(__isl_keep isl_val *v1, __isl_keep isl_val *v2) { return isl_val_lt(v2, v1); +} + +/* Is "v" (strictly) greater than "i"? + */ +isl_bool isl_val_gt_si(__isl_keep isl_val *v, long i) +{ + isl_val *vi; + isl_bool res; + + if (!v) + return isl_bool_error; + if (isl_val_is_int(v)) + return isl_bool_ok(isl_int_cmp_si(v->n, i) > 0); + if (isl_val_is_nan(v)) + return isl_bool_false; + if (isl_val_is_infty(v)) + return isl_bool_true; + if (isl_val_is_neginfty(v)) + return isl_bool_false; + + vi = isl_val_int_from_si(isl_val_get_ctx(v), i); + res = isl_bool_ok(isl_val_gt(v, vi)); + isl_val_free(vi); + + return res; } /* Is "v1" less than or equal to "v2"? @@ -1322,7 +1354,7 @@ if (!v1 || !v2) return isl_bool_error; if (isl_val_is_int(v1) && isl_val_is_int(v2)) - return isl_int_le(v1->n, v2->n); + return isl_bool_ok(isl_int_le(v1->n, v2->n)); if (isl_val_is_nan(v1) || isl_val_is_nan(v2)) return isl_bool_false; if (isl_val_eq(v1, v2)) @@ -1339,7 +1371,7 @@ isl_int_init(t); isl_int_mul(t, v1->n, v2->d); isl_int_submul(t, v2->n, v1->d); - le = isl_int_is_nonpos(t); + le = isl_bool_ok(isl_int_is_nonpos(t)); isl_int_clear(t); return le; @@ -1392,7 +1424,8 @@ if (isl_val_is_nan(v1) || isl_val_is_nan(v2)) return isl_bool_false; - return isl_int_eq(v1->n, v2->n) && isl_int_eq(v1->d, v2->d); + return isl_bool_ok(isl_int_eq(v1->n, v2->n) && + isl_int_eq(v1->d, v2->d)); } /* Is "v1" equal to "v2" in absolute value? @@ -1404,7 +1437,8 @@ if (isl_val_is_nan(v1) || isl_val_is_nan(v2)) return isl_bool_false; - return isl_int_abs_eq(v1->n, v2->n) && isl_int_eq(v1->d, v2->d); + return isl_bool_ok(isl_int_abs_eq(v1->n, v2->n) && + isl_int_eq(v1->d, v2->d)); } /* Is "v1" different from "v2"? @@ -1416,7 +1450,8 @@ if (isl_val_is_nan(v1) || isl_val_is_nan(v2)) return isl_bool_false; - return isl_int_ne(v1->n, v2->n) || isl_int_ne(v1->d, v2->d); + return isl_bool_ok(isl_int_ne(v1->n, v2->n) || + isl_int_ne(v1->d, v2->d)); } /* Print a textual representation of "v" onto "p". @@ -1455,7 +1490,8 @@ * This is a private copy of isl_val_eq for use in the generic * isl_multi_*_plain_is_equal instantiated for isl_val. */ -int isl_val_plain_is_equal(__isl_keep isl_val *val1, __isl_keep isl_val *val2) +isl_bool isl_val_plain_is_equal(__isl_keep isl_val *val1, + __isl_keep isl_val *val2) { return isl_val_eq(val1, val2); } @@ -1466,15 +1502,15 @@ * This function is only meant to be used in the generic isl_multi_* * functions which have to deal with base objects that have an associated * space. Since an isl_val does not have any coefficients, this function - * always return 0. + * always returns isl_bool_false. */ -int isl_val_involves_dims(__isl_keep isl_val *v, enum isl_dim_type type, +isl_bool isl_val_involves_dims(__isl_keep isl_val *v, enum isl_dim_type type, unsigned first, unsigned n) { if (!v) - return -1; + return isl_bool_error; - return 0; + return isl_bool_false; } /* Insert "n" dimensions of type "type" at position "first". @@ -1485,19 +1521,6 @@ * does not do anything. */ __isl_give isl_val *isl_val_insert_dims(__isl_take isl_val *v, - enum isl_dim_type type, unsigned first, unsigned n) -{ - return v; -} - -/* Drop the "n" first dimensions of type "type" at position "first". - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * does not do anything. - */ -__isl_give isl_val *isl_val_drop_dims(__isl_take isl_val *v, enum isl_dim_type type, unsigned first, unsigned n) { return v; @@ -1512,74 +1535,7 @@ */ __isl_give isl_val *isl_val_set_dim_name(__isl_take isl_val *v, enum isl_dim_type type, unsigned pos, const char *s) -{ - return v; -} - -/* Return the space of "v". - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. The conditions surrounding the call to this function make sure - * that this function will never actually get called. We return a valid - * space anyway, just in case. - */ -__isl_give isl_space *isl_val_get_space(__isl_keep isl_val *v) -{ - if (!v) - return NULL; - - return isl_space_params_alloc(isl_val_get_ctx(v), 0); -} - -/* Reset the domain space of "v" to "space". - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * does not do anything, apart from error handling and cleaning up memory. - */ -__isl_give isl_val *isl_val_reset_domain_space(__isl_take isl_val *v, - __isl_take isl_space *space) -{ - if (!space) - return isl_val_free(v); - isl_space_free(space); - return v; -} - -/* Align the parameters of "v" to those of "space". - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * does not do anything, apart from error handling and cleaning up memory. - * Note that the conditions surrounding the call to this function make sure - * that this function will never actually get called. - */ -__isl_give isl_val *isl_val_align_params(__isl_take isl_val *v, - __isl_take isl_space *space) -{ - if (!space) - return isl_val_free(v); - isl_space_free(space); - return v; -} - -/* Reorder the dimensions of the domain of "v" according - * to the given reordering. - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * does not do anything, apart from error handling and cleaning up memory. - */ -__isl_give isl_val *isl_val_realign_domain(__isl_take isl_val *v, - __isl_take isl_reordering *r) { - if (!r) - return isl_val_free(v); - isl_reordering_free(r); return v; } @@ -1599,36 +1555,6 @@ ctx = isl_local_space_get_ctx(ls); isl_local_space_free(ls); return isl_val_zero(ctx); -} - -/* Do the parameters of "v" match those of "space"? - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * simply returns true, except if "v" or "space" are NULL. - */ -isl_bool isl_val_matching_params(__isl_keep isl_val *v, - __isl_keep isl_space *space) -{ - if (!v || !space) - return isl_bool_error; - return isl_bool_true; -} - -/* Check that the domain space of "v" matches "space". - * - * This function is only meant to be used in the generic isl_multi_* - * functions which have to deal with base objects that have an associated - * space. Since an isl_val does not have an associated space, this function - * simply returns 0, except if "v" or "space" are NULL. - */ -isl_stat isl_val_check_match_domain_space(__isl_keep isl_val *v, - __isl_keep isl_space *space) -{ - if (!v || !space) - return isl_stat_error; - return isl_stat_ok; } #define isl_val_involves_nan isl_val_is_nan @@ -1636,12 +1562,17 @@ #undef BASE #define BASE val -#define NO_DOMAIN -#define NO_IDENTITY -#define NO_FROM_BASE -#define NO_MOVE_DIMS +#include +#include #include +#include +#include #include +#include +#include +#include +#include +#include /* Apply "fn" to each of the elements of "mv" with as second argument "v". */ @@ -1658,8 +1589,8 @@ goto error; for (i = 0; i < mv->n; ++i) { - mv->p[i] = fn(mv->p[i], isl_val_copy(v)); - if (!mv->p[i]) + mv->u.p[i] = fn(mv->u.p[i], isl_val_copy(v)); + if (!mv->u.p[i]) goto error; } diff --git a/gcc/isl/isl_val_gmp.c b/gcc/isl/isl_val_gmp.c index 42e8d44..cd74709 100644 --- a/gcc/isl/isl_val_gmp.c +++ a/gcc/isl/isl_val_gmp.c @@ -86,14 +86,14 @@ /* Return the number of chunks of size "size" required to * store the absolute value of the numerator of "v". */ -size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) +isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) { if (!v) - return 0; + return isl_size_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return 0); + "expecting rational value", return isl_size_error); size *= 8; return (mpz_sizeinbase(v->n, 2) + size - 1) / size; @@ -110,19 +110,19 @@ * return one, while mpz_export will not fill in any chunks. We therefore * do it ourselves. */ -int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, +isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks) { if (!v || !chunks) - return -1; + return isl_stat_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return -1); + "expecting rational value", return isl_stat_error); mpz_export(chunks, NULL, -1, size, 0, 0, v->n); if (isl_val_is_zero(v)) memset(chunks, 0, size); - return 0; + return isl_stat_ok; } diff --git a/gcc/isl/isl_val_imath.c b/gcc/isl/isl_val_imath.c index 8f91700..dc4acc1 100644 --- a/gcc/isl/isl_val_imath.c +++ a/gcc/isl/isl_val_imath.c @@ -30,34 +30,34 @@ * return one, while impz_export will not fill in any chunks. We therefore * do it ourselves. */ -int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, +isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks) { if (!v || !chunks) - return -1; + return isl_stat_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return -1); + "expecting rational value", return isl_stat_error); impz_export(chunks, NULL, -1, size, 0, 0, v->n); if (isl_val_is_zero(v)) memset(chunks, 0, size); - return 0; + return isl_stat_ok; } /* Return the number of chunks of size "size" required to * store the absolute value of the numerator of "v". */ -size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) +isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) { if (!v) - return 0; + return isl_size_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return 0); + "expecting rational value", return isl_size_error); size *= 8; return (impz_sizeinbase(v->n, 2) + size - 1) / size; diff --git a/gcc/isl/isl_val_private.h b/gcc/isl/isl_val_private.h index 4276ddb..59d8519 100644 --- a/gcc/isl/isl_val_private.h +++ a/gcc/isl/isl_val_private.h @@ -34,24 +34,14 @@ isl_int n, isl_int d); __isl_give isl_val *isl_val_cow(__isl_take isl_val *val); -int isl_val_get_num_isl_int(__isl_keep isl_val *v, isl_int *n); +isl_stat isl_val_get_num_isl_int(__isl_keep isl_val *v, isl_int *n); -int isl_val_involves_dims(__isl_keep isl_val *v, enum isl_dim_type type, +isl_bool isl_val_involves_dims(__isl_keep isl_val *v, enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_val *isl_val_insert_dims(__isl_take isl_val *v, enum isl_dim_type type, unsigned first, unsigned n); -__isl_give isl_val *isl_val_drop_dims(__isl_take isl_val *v, - enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_val *isl_val_set_dim_name(__isl_take isl_val *v, enum isl_dim_type type, unsigned pos, const char *s); -__isl_give isl_space *isl_val_get_space(__isl_keep isl_val *v); -__isl_give isl_val *isl_val_reset_domain_space(__isl_take isl_val *v, - __isl_take isl_space *space); -__isl_give isl_val *isl_val_align_params(__isl_take isl_val *v, - __isl_take isl_space *space); -__isl_give isl_val *isl_val_realign_domain(__isl_take isl_val *v, - __isl_take isl_reordering *r); -__isl_give isl_val *isl_val_zero_on_domain(__isl_take isl_local_space *ls); __isl_give isl_val *isl_val_scale_val(__isl_take isl_val *v1, __isl_take isl_val *v2); @@ -59,13 +49,9 @@ __isl_take isl_val *v2); __isl_give isl_val *isl_val_mod_val(__isl_take isl_val *v1, __isl_take isl_val *v2); - -int isl_val_plain_is_equal(__isl_keep isl_val *val1, __isl_keep isl_val *val2); -isl_bool isl_val_matching_params(__isl_keep isl_val *v, - __isl_keep isl_space *space); -isl_stat isl_val_check_match_domain_space(__isl_keep isl_val *v, - __isl_keep isl_space *space); +isl_bool isl_val_plain_is_equal(__isl_keep isl_val *val1, + __isl_keep isl_val *val2); #undef BASE #define BASE val diff --git a/gcc/isl/isl_val_sioimath.c b/gcc/isl/isl_val_sioimath.c index 42f87e3..9b9e73d 100644 --- a/gcc/isl/isl_val_sioimath.c +++ a/gcc/isl/isl_val_sioimath.c @@ -31,37 +31,37 @@ * return one, while impz_export will not fill in any chunks. We therefore * do it ourselves. */ -int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, +isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks) { isl_sioimath_scratchspace_t scratch; if (!v || !chunks) - return -1; + return isl_stat_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return -1); + "expecting rational value", return isl_stat_error); impz_export(chunks, NULL, -1, size, 0, 0, isl_sioimath_bigarg_src(*v->n, &scratch)); if (isl_val_is_zero(v)) memset(chunks, 0, size); - return 0; + return isl_stat_ok; } /* Return the number of chunks of size "size" required to * store the absolute value of the numerator of "v". */ -size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) +isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size) { if (!v) - return 0; + return isl_size_error; if (!isl_val_is_rat(v)) isl_die(isl_val_get_ctx(v), isl_error_invalid, - "expecting rational value", return 0); + "expecting rational value", return isl_size_error); size *= 8; return (isl_sioimath_sizeinbase(*v->n, 2) + size - 1) / size; diff --git a/gcc/isl/isl_vec.c b/gcc/isl/isl_vec.c index 4d5bed7..da971c5 100644 --- a/gcc/isl/isl_vec.c +++ a/gcc/isl/isl_vec.c @@ -245,9 +245,9 @@ return NULL; } -int isl_vec_size(__isl_keep isl_vec *vec) +isl_size isl_vec_size(__isl_keep isl_vec *vec) { - return vec ? vec->size : -1; + return vec ? vec->size : isl_size_error; } /* Extract the element at position "pos" of "vec". @@ -334,7 +334,7 @@ { if (!vec) return isl_bool_error; - return isl_seq_first_non_zero(vec->el, vec->size) < 0; + return isl_bool_ok(isl_seq_first_non_zero(vec->el, vec->size) < 0); } isl_bool isl_vec_is_equal(__isl_keep isl_vec *vec1, __isl_keep isl_vec *vec2) @@ -345,7 +345,7 @@ if (vec1->size != vec2->size) return isl_bool_false; - return isl_seq_eq(vec1->el, vec2->el, vec1->size); + return isl_bool_ok(isl_seq_eq(vec1->el, vec2->el, vec1->size)); } __isl_give isl_printer *isl_printer_print_vec(__isl_take isl_printer *printer, @@ -583,6 +583,15 @@ isl_vec_free(vec); isl_vec_free(ext); return NULL; +} + +/* Add "n" elements at the end of "vec". + */ +__isl_give isl_vec *isl_vec_add_els(__isl_take isl_vec *vec, unsigned n) +{ + if (!vec) + return NULL; + return isl_vec_insert_els(vec, vec->size, n); } __isl_give isl_vec *isl_vec_insert_zero_els(__isl_take isl_vec *vec, diff --git a/gcc/isl/isl_vertices.c b/gcc/isl/isl_vertices.c index 594effc..120deab 100644 --- a/gcc/isl/isl_vertices.c +++ a/gcc/isl/isl_vertices.c @@ -122,13 +122,15 @@ static isl_bool add_vertex(struct isl_vertex_list **list, __isl_keep isl_basic_set *bset, struct isl_tab *tab) { - unsigned nvar; + isl_size nvar; struct isl_vertex_list *v = NULL; if (isl_tab_detect_implicit_equalities(tab) < 0) return isl_bool_error; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0) + return isl_bool_error; v = isl_calloc_type(tab->mat->ctx, struct isl_vertex_list); if (!v) @@ -232,20 +234,20 @@ /* Is the row pointed to by "f" linearly independent of the "n" first * rows in "facets"? */ -static int is_independent(__isl_keep isl_mat *facets, int n, isl_int *f) +static isl_bool is_independent(__isl_keep isl_mat *facets, int n, isl_int *f) { - int rank; + isl_size rank; if (isl_seq_first_non_zero(f, facets->n_col) < 0) - return 0; + return isl_bool_false; isl_seq_cpy(facets->row[n], f, facets->n_col); facets->n_row = n + 1; rank = isl_mat_rank(facets); if (rank < 0) - return -1; + return isl_bool_error; - return rank == n + 1; + return isl_bool_ok(rank == n + 1); } /* Check whether we can select constraint "level", given the current selection @@ -263,34 +265,32 @@ * deselected constraints turning into equalities, then the corresponding * vertices have already been generated, so the constraint cannot be selected. */ -static int can_select(__isl_keep isl_basic_set *bset, int level, +static isl_bool can_select(__isl_keep isl_basic_set *bset, int level, struct isl_tab *tab, __isl_keep isl_mat *facets, int selected, int *selection) { int i; - int indep; + isl_bool indep; unsigned ovar; struct isl_tab_undo *snap; if (isl_tab_is_redundant(tab, level)) - return 0; + return isl_bool_false; ovar = isl_space_offset(bset->dim, isl_dim_set); indep = is_independent(facets, selected, bset->ineq[level] + 1 + ovar); - if (indep < 0) - return -1; - if (!indep) - return 0; + if (indep < 0 || !indep) + return indep; snap = isl_tab_snap(tab); if (isl_tab_select_facet(tab, level) < 0) - return -1; + return isl_bool_error; if (tab->empty) { if (isl_tab_rollback(tab, snap) < 0) - return -1; - return 0; + return isl_bool_error; + return isl_bool_false; } for (i = 0; i < level; ++i) { @@ -306,15 +306,15 @@ else sgn = isl_tab_sign_of_max(tab, i); if (sgn < -1) - return -1; + return isl_bool_error; if (sgn <= 0) { if (isl_tab_rollback(tab, snap) < 0) - return -1; - return 0; + return isl_bool_error; + return isl_bool_false; } } - return 1; + return isl_bool_true; } /* Compute the parametric vertices and the chamber decomposition @@ -378,7 +378,7 @@ struct isl_tab *tab; int level; int init; - unsigned nvar; + isl_size nvar; int *selection = NULL; int selected; struct isl_tab_undo **snap = NULL; @@ -395,14 +395,15 @@ if (bset->n_eq != 0) return lower_dim_vertices(bset); - - isl_assert(bset->ctx, isl_basic_set_dim(bset, isl_dim_div) == 0, - return NULL); - if (isl_basic_set_dim(bset, isl_dim_set) == 0) - return vertices_0D(bset); + if (isl_basic_set_check_no_locals(bset) < 0) + return NULL; nvar = isl_basic_set_dim(bset, isl_dim_set); + if (nvar < 0) + return NULL; + if (nvar == 0) + return vertices_0D(bset); bset = isl_basic_set_copy(bset); bset = isl_basic_set_set_rational(bset); @@ -439,7 +440,7 @@ continue; } if (init) { - int ok; + isl_bool ok; snap[level] = isl_tab_snap(tab); ok = can_select(bset, level, tab, facets, selected, selection); @@ -580,7 +581,12 @@ snap = isl_tab_snap(tab); for (i = 0; i < bset->n_ineq; ++i) { - if (isl_tab_ineq_type(tab, bset->ineq[i]) == isl_ineq_redundant) + enum isl_ineq_type type; + + type = isl_tab_ineq_type(tab, bset->ineq[i]); + if (type < 0) + return isl_bool_error; + if (type == isl_ineq_redundant) continue; if (isl_tab_add_ineq(tab, bset->ineq[i]) < 0) return isl_bool_error; @@ -710,7 +716,7 @@ todo->bset = isl_basic_set_sort_constraints(todo->bset); if (!todo->bset) goto error; - ISL_F_SET(todo->bset, ISL_BASIC_SET_NORMALIZED); + ISL_F_SET(todo->bset, ISL_BASIC_SET_NO_REDUNDANT); todo->tab = isl_tab_dup(tab); if (!todo->tab) goto error; @@ -976,9 +982,9 @@ return vertex ? isl_vertices_get_ctx(vertex->vertices) : NULL; } -int isl_vertex_get_id(__isl_keep isl_vertex *vertex) +isl_size isl_vertex_get_id(__isl_keep isl_vertex *vertex) { - return vertex ? vertex->id : -1; + return vertex ? vertex->id : isl_size_error; } /* Return the activity domain of the vertex "vertex". @@ -1040,12 +1046,14 @@ return NULL; } -void isl_vertex_free(__isl_take isl_vertex *vertex) +__isl_null isl_vertex *isl_vertex_free(__isl_take isl_vertex *vertex) { if (!vertex) - return; + return NULL; isl_vertices_free(vertex->vertices); free(vertex); + + return NULL; } isl_ctx *isl_cell_get_ctx(__isl_keep isl_cell *cell) @@ -1088,15 +1096,17 @@ return NULL; } -void isl_cell_free(__isl_take isl_cell *cell) +__isl_null isl_cell *isl_cell_free(__isl_take isl_cell *cell) { if (!cell) - return; + return NULL; isl_vertices_free(cell->vertices); free(cell->ids); isl_basic_set_free(cell->dom); free(cell); + + return NULL; } /* Create a tableau of the cone obtained by first homogenizing the given @@ -1108,11 +1118,13 @@ int i; isl_vec *c = NULL; struct isl_tab *tab; + isl_size total; - if (!bset) + total = isl_basic_set_dim(bset, isl_dim_all); + if (total < 0) return NULL; tab = isl_tab_alloc(bset->ctx, bset->n_eq + bset->n_ineq + 1, - 1 + isl_basic_set_total_dim(bset), 0); + 1 + total, 0); if (!tab) return NULL; tab->rational = ISL_F_ISSET(bset, ISL_BASIC_SET_RATIONAL); @@ -1122,7 +1134,7 @@ return tab; } - c = isl_vec_alloc(bset->ctx, 1 + 1 + isl_basic_set_total_dim(bset)); + c = isl_vec_alloc(bset->ctx, 1 + 1 + total); if (!c) goto error; @@ -1323,9 +1335,9 @@ return vertices ? vertices->bset->ctx : NULL; } -int isl_vertices_get_n_vertices(__isl_keep isl_vertices *vertices) +isl_size isl_vertices_get_n_vertices(__isl_keep isl_vertices *vertices) { - return vertices ? vertices->n_vertices : -1; + return vertices ? vertices->n_vertices : isl_size_error; } __isl_give isl_vertices *isl_morph_vertices(__isl_take isl_morph *morph, @@ -1452,7 +1464,7 @@ isl_stat (*fn)(__isl_take isl_cell *simplex, void *user), void *user) { int i, j, k; - int d, nparam; + isl_size d, nparam; int *ids; isl_ctx *ctx; isl_basic_set *vertex; @@ -1461,6 +1473,8 @@ ctx = isl_cell_get_ctx(cell); d = isl_basic_set_dim(cell->vertices->bset, isl_dim_set); nparam = isl_basic_set_dim(cell->vertices->bset, isl_dim_param); + if (d < 0 || nparam < 0) + return isl_stat_error; if (n_simplex + n_other == d + 1) return call_on_simplex(cell, simplex_ids, n_simplex, @@ -1506,8 +1520,8 @@ isl_stat isl_cell_foreach_simplex(__isl_take isl_cell *cell, isl_stat (*fn)(__isl_take isl_cell *simplex, void *user), void *user) { - int d, total; - int r; + isl_size d, total; + isl_stat r; isl_ctx *ctx; isl_vec *v = NULL; int *simplex_ids = NULL; @@ -1516,7 +1530,9 @@ return isl_stat_error; d = isl_basic_set_dim(cell->vertices->bset, isl_dim_set); - total = isl_basic_set_total_dim(cell->vertices->bset); + total = isl_basic_set_dim(cell->vertices->bset, isl_dim_all); + if (d < 0 || total < 0) + return isl_stat_error; if (cell->n_vertices == d + 1) return fn(cell, user); diff --git a/gcc/isl/pip.c b/gcc/isl/pip.c index 002bc70..9e6c1ec 100644 --- a/gcc/isl/pip.c +++ a/gcc/isl/pip.c @@ -65,12 +65,14 @@ static __isl_give isl_basic_set *set_bounds(__isl_take isl_basic_set *bset) { - unsigned nparam; + isl_size nparam; int i, r; isl_point *pt, *pt2; isl_basic_set *box; nparam = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0) + return isl_basic_set_free(bset); r = nparam >= 8 ? 4 : nparam >= 5 ? 6 : 30; pt = isl_basic_set_sample_point(isl_basic_set_copy(bset)); @@ -86,14 +88,42 @@ return isl_basic_set_intersect(bset, box); } -static struct isl_basic_set *to_parameter_domain(struct isl_basic_set *context) +static __isl_give isl_basic_set *to_parameter_domain( + __isl_take isl_basic_set *context) { + isl_size dim; + + dim = isl_basic_set_dim(context, isl_dim_set); + if (dim < 0) + return isl_basic_set_free(context); context = isl_basic_set_move_dims(context, isl_dim_param, 0, - isl_dim_set, 0, isl_basic_set_dim(context, isl_dim_set)); + isl_dim_set, 0, dim); context = isl_basic_set_params(context); return context; } +/* If "context" has more parameters than "bset", then reinterpret + * the last dimensions of "bset" as parameters. + */ +static __isl_give isl_basic_set *move_parameters(__isl_take isl_basic_set *bset, + __isl_keep isl_basic_set *context) +{ + isl_size nparam, nparam_bset, dim; + + nparam = isl_basic_set_dim(context, isl_dim_param); + nparam_bset = isl_basic_set_dim(bset, isl_dim_param); + if (nparam < 0 | nparam_bset < 0) + return isl_basic_set_free(bset); + if (nparam == nparam_bset) + return bset; + dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + return isl_basic_set_free(bset); + bset = isl_basic_set_move_dims(bset, isl_dim_param, 0, + isl_dim_set, dim - nparam, nparam); + return bset; +} + /* Plug in the initial values of "params" for the parameters in "bset" and * return the result. The remaining entries in "params", if any, * correspond to the existentially quantified variables in the description @@ -102,9 +132,12 @@ static __isl_give isl_basic_set *plug_in_parameters( __isl_take isl_basic_set *bset, __isl_take isl_vec *params) { - int i, n; + int i; + isl_size n; n = isl_basic_set_dim(bset, isl_dim_param); + if (n < 0) + bset = isl_basic_set_free(bset); for (i = 0; i < n; ++i) bset = isl_basic_set_fix(bset, isl_dim_param, i, params->el[1 + i]); @@ -124,9 +157,12 @@ static __isl_give isl_set *set_plug_in_parameters(__isl_take isl_set *set, __isl_take isl_vec *params) { - int i, n; + int i; + isl_size n; n = isl_set_dim(set, isl_dim_param); + if (n < 0) + set = isl_set_free(set); for (i = 0; i < n; ++i) set = isl_set_fix(set, isl_dim_param, i, params->el[1 + i]); @@ -144,13 +180,15 @@ static __isl_give isl_vec *opt_at(__isl_take isl_basic_set *bset, __isl_take isl_vec *params, int max) { - unsigned dim; + isl_size dim; isl_ctx *ctx; struct isl_vec *opt; struct isl_vec *obj; int i; dim = isl_basic_set_dim(bset, isl_dim_set); + if (dim < 0) + goto error; bset = plug_in_parameters(bset, params); @@ -187,6 +225,10 @@ isl_vec_free(obj); return opt; +error: + isl_basic_set_free(bset); + isl_vec_free(params); + return NULL; empty: isl_vec_free(opt); opt = isl_vec_alloc(ctx, 0); @@ -305,7 +347,6 @@ int max = 0; int rational = 0; int n; - int nparam; struct options *options; options = options_new_with_defaults(); @@ -337,12 +378,7 @@ context = isl_basic_set_intersect(context, isl_basic_set_positive_orthant(isl_basic_set_get_space(context))); context = to_parameter_domain(context); - nparam = isl_basic_set_dim(context, isl_dim_param); - if (nparam != isl_basic_set_dim(bset, isl_dim_param)) { - int dim = isl_basic_set_dim(bset, isl_dim_set); - bset = isl_basic_set_move_dims(bset, isl_dim_param, 0, - isl_dim_set, dim - nparam, nparam); - } + bset = move_parameters(bset, context); if (!urs_unknowns) bset = isl_basic_set_intersect(bset, isl_basic_set_positive_orthant(isl_basic_set_get_space(bset))); diff --git a/gcc/isl/polyhedron_minimize.c b/gcc/isl/polyhedron_minimize.c index 526b373..87f6837 100644 --- a/gcc/isl/polyhedron_minimize.c +++ a/gcc/isl/polyhedron_minimize.c @@ -61,16 +61,16 @@ struct isl_vec *obj; struct isl_vec *sol; isl_int opt; - unsigned dim; + isl_size dim; enum isl_lp_result res; isl_printer *p; isl_int_init(opt); bset = isl_basic_set_read_from_file(ctx, stdin); - assert(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + assert(dim >= 0); obj = isl_vec_read_from_file(ctx, stdin); assert(obj); - dim = isl_basic_set_total_dim(bset); assert(obj->size >= dim && obj->size <= dim + 1); if (obj->size != dim + 1) obj = isl_vec_lin_to_aff(obj); diff --git a/gcc/isl/polytope_scan.c b/gcc/isl/polytope_scan.c index c787432..129a20d 100644 --- a/gcc/isl/polytope_scan.c +++ a/gcc/isl/polytope_scan.c @@ -48,14 +48,17 @@ return isl_stat_error; } -static struct isl_mat *isl_basic_set_scan_samples(struct isl_basic_set *bset) +static __isl_give isl_mat *isl_basic_set_scan_samples( + __isl_take isl_basic_set *bset) { isl_ctx *ctx; - unsigned dim; + isl_size dim; struct scan_samples ss; ctx = isl_basic_set_get_ctx(bset); - dim = isl_basic_set_total_dim(bset); + dim = isl_basic_set_dim(bset, isl_dim_all); + if (dim < 0) + goto error; ss.callback.add = scan_samples_add_sample; ss.samples = isl_mat_alloc(ctx, 0, 1 + dim); if (!ss.samples) diff --git a/gcc/isl/print.c b/gcc/isl/print.c index 44855a2..a87f922 100644 --- a/gcc/isl/print.c +++ a/gcc/isl/print.c @@ -17,6 +17,9 @@ #define BASE id #include #undef BASE +#define BASE multi_id +#include +#undef BASE #define BASE val #include #undef BASE diff --git a/gcc/isl/print_templ.c b/gcc/isl/print_templ.c index d6b0db7..9ed93f1 100644 --- a/gcc/isl/print_templ.c +++ a/gcc/isl/print_templ.c @@ -7,6 +7,10 @@ #define xFN(TYPE,NAME) TYPE ## _ ## NAME #define FN(TYPE,NAME) xFN(TYPE,NAME) +#ifndef PRINT_DUMP_DEFAULT +#define PRINT_DUMP_DEFAULT 1 +#endif + void FN(TYPE,dump)(__isl_keep TYPE *obj) { isl_printer *p; @@ -14,11 +18,13 @@ if (!obj) return; p = isl_printer_to_file(FN(TYPE,get_ctx)(obj), stderr); - p = isl_printer_set_dump(p, 1); + p = isl_printer_set_dump(p, PRINT_DUMP_DEFAULT); p = FN(isl_printer_print,BASE)(p, obj); p = isl_printer_end_line(p); isl_printer_free(p); } + +#undef PRINT_DUMP_DEFAULT __isl_give char *FN(TYPE,to_str)(__isl_keep TYPE *obj) { diff --git a/gcc/isl/schedule_test.sh.in b/gcc/isl/schedule_test.sh.in index afba802..16ae020 100644 --- a/gcc/isl/schedule_test.sh.in +++ a/gcc/isl/schedule_test.sh.in @@ -14,8 +14,14 @@ dir=`dirname $i` ref=$dir/$base.st options=`$GREP 'OPTIONS:' $i | $SED 's/.*://'` - (./isl_schedule$EXEEXT $options < $i > $test && - ./isl_schedule_cmp$EXEEXT $ref $test && rm $test) || failed=1 + for o in --schedule-whole-component --no-schedule-whole-component; do + ./isl_schedule$EXEEXT $o $options < $i > $test && + ./isl_schedule_cmp$EXEEXT $ref $test && rm $test + if [ $? -ne 0 ]; then + echo $o $options + failed=1 + fi + done done test $failed -eq 0 || exit diff --git a/gcc/isl/doc/Makefile.in b/gcc/isl/doc/Makefile.in index ba695d1..58831a1 100644 --- a/gcc/isl/doc/Makefile.in +++ a/gcc/isl/doc/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2014 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -95,6 +95,8 @@ $(top_srcdir)/m4/ax_compiler_vendor.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \ $(top_srcdir)/m4/ax_detect_clang.m4 \ $(top_srcdir)/m4/ax_detect_git_head.m4 \ $(top_srcdir)/m4/ax_detect_gmp.m4 \ @@ -150,12 +152,14 @@ CLANG_CXXFLAGS = @CLANG_CXXFLAGS@ CLANG_LDFLAGS = @CLANG_LDFLAGS@ CLANG_LIBS = @CLANG_LIBS@ +CLANG_RFLAG = @CLANG_RFLAG@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ +CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ @@ -172,6 +176,7 @@ GIT_HEAD_ID = @GIT_HEAD_ID@ GIT_HEAD_VERSION = @GIT_HEAD_VERSION@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -190,6 +195,7 @@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MP_CFLAGS = @MP_CFLAGS@ MP_CPPFLAGS = @MP_CPPFLAGS@ MP_LDFLAGS = @MP_LDFLAGS@ MP_LIBS = @MP_LIBS@ @@ -197,6 +203,7 @@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_SRCDIR = @OS_SRCDIR@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ diff --git a/gcc/isl/doc/manual.pdf b/gcc/isl/doc/manual.pdf index 3344d3237dc1239fe4027eda7131a9f9a2c88963..57ad13debc1f0b28884ee145b86185b403ca2246 100644 Binary files a/gcc/isl/doc/manual.pdf and a/gcc/isl/doc/manual.pdf differ diff --git a/gcc/isl/doc/user.pod b/gcc/isl/doc/user.pod index 30b3ca0..41f9d3e 100644 --- a/gcc/isl/doc/user.pod +++ a/gcc/isl/doc/user.pod @@ -270,6 +270,41 @@ =back +=head3 Changes since isl-0.19 + +=over + +=item * Zero-dimensional objects of type C or +C can now keep track of an explicit domain. +This explicit domain, if present, is taken into account +by various operations that take such objects as input. + +=back + +=head3 Changes since isl-0.20 + +=over + +=item * Several functions that used to return C +now return C. This means that these functions may +now return a negative value in case an error occurred. +The same holds for functions that used to return C, +although some of those were already returning +a negative value in case of error. + +=item * The C enumeration type has been +renamed to C. The corresponding +enumeration constants have been similarly renamed. +The old names are defined to the new names for backward +compatibility. + +=item * Several functions returning an extra boolean value +through an C argument now do so through an C +argument. The returned values are the same, only the type +of the pointer has been changed. + +=back + =head1 License C is released under the MIT license. @@ -524,6 +559,8 @@ #include 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_ctx *isl_local_space_get_ctx( @@ -595,28 +632,53 @@ __isl_keep isl_ast_expr *expr); isl_ctx *isl_ast_node_get_ctx( __isl_keep isl_ast_node *node); + + #include + isl_ctx *isl_stride_info_get_ctx( + __isl_keep isl_stride_info *si); + #include + isl_ctx *isl_fixed_box_get_ctx( + __isl_keep isl_fixed_box *box); + =head2 Return Types + +C uses the special return type C for functions +that return a non-negative value, typically a number or a position. +Besides the regular non-negative return values, a special (negative) +value C may be returned, indicating that something +went wrong. -C uses two special return types for functions that either return +C also uses two special return types for functions that either return a boolean or that in principle do not return anything. In particular, the C type has three possible values: C (a positive integer value), indicating I or I; C (the integer value zero), indicating I or I; and C (a negative integer value), indicating that something -went wrong. The following function can be used to negate an C, -where the negation of C is C again. +went wrong. The following operations are defined on C. The function +C can be used to negate an C, where the negation of +C is C again. The function C +converts an integer to an C. Any non-zero values yields +C and zero yields C. - #include + #include isl_bool isl_bool_not(isl_bool b); + isl_bool isl_bool_ok(int b); The C type has two possible values: C (the integer value zero), indicating a successful operation; and C (a negative integer value), indicating that something went wrong. +The function C converts an isl object pointer +to an C, returning C if the object pointer is valid and +C if it is C. + + #include + isl_stat isl_stat_non_null(void *obj); + See L for more information on -C and C. +C, C and C. =head2 Values @@ -660,9 +722,9 @@ __isl_give isl_val *isl_val_get_den_val( __isl_keep isl_val *v); double isl_val_get_d(__isl_keep isl_val *v); - size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, + isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size); - int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, + isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks); C returns the number of I @@ -733,9 +795,10 @@ __isl_keep isl_val *v2); An C can also be compared to an integer using the following -function. The result is undefined for NaN. +functions. The result of C undefined for NaN. #include + isl_bool isl_val_gt_si(__isl_keep isl_val *v, long i); int isl_val_cmp_si(__isl_keep isl_val *v, long i); The following unary operations are available on Cs. @@ -747,7 +810,6 @@ __isl_give isl_val *isl_val_ceil(__isl_take isl_val *v); __isl_give isl_val *isl_val_trunc(__isl_take isl_val *v); __isl_give isl_val *isl_val_inv(__isl_take isl_val *v); - __isl_give isl_val *isl_val_2exp(__isl_take isl_val *v); The following binary operations are available on Cs. @@ -776,6 +838,7 @@ On integer values, we additionally have the following operations. #include + __isl_give isl_val *isl_val_pow2(__isl_take isl_val *v); __isl_give isl_val *isl_val_2exp(__isl_take isl_val *v); __isl_give isl_val *isl_val_mod(__isl_take isl_val *v1, __isl_take isl_val *v2); @@ -785,6 +848,7 @@ __isl_take isl_val *v2, __isl_give isl_val **x, __isl_give isl_val **y); +C is an alternative name for C. The function C returns the greatest common divisor g of C and C as well as two integers C<*x> and C<*y> such that C<*x> * C + C<*y> * C = g. @@ -839,8 +903,9 @@ the last error in the corresponding C and the function in which the error was triggered returns a value indicating that some error has occurred. In case of functions returning a pointer, this value is -C. In case of functions returning an C or an -C, this value is C or C. +C. In case of functions returning an C, C or an +C, this value is C, +C or C. An error does not corrupt internal state, such that isl can continue to be used. C also provides functions to read the last error, including the specific error message, @@ -941,6 +1006,7 @@ parameters is discouraged. #include + __isl_give isl_space *isl_space_unit(isl_ctx *ctx); __isl_give isl_space *isl_space_alloc(isl_ctx *ctx, unsigned nparam, unsigned n_in, unsigned n_out); __isl_give isl_space *isl_space_params_alloc(isl_ctx *ctx, @@ -951,11 +1017,14 @@ __isl_null isl_space *isl_space_free(__isl_take isl_space *space); The space used for creating a parameter domain -needs to be created using C. +needs to be created using C or C. For other sets, the space needs to be created using C, while for a relation, the space needs to be created using C. +The use of C, +C and C is discouraged as they allow +for the introduction of unnamed parameters. To check whether a given space is that of a set or a map or whether it is a parameter space, use these functions: @@ -1059,6 +1128,10 @@ __isl_keep isl_union_pw_qpolynomial *upwqp); __isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space( __isl_keep isl_union_pw_qpolynomial_fold *upwf); + + #include + __isl_give isl_space *isl_multi_id_get_space( + __isl_keep isl_multi_id *mi); #include __isl_give isl_space *isl_multi_val_get_space( @@ -1100,6 +1173,10 @@ __isl_give isl_space *isl_point_get_space( __isl_keep isl_point *pnt); + #include + __isl_give isl_space *isl_fixed_box_get_space( + __isl_keep isl_fixed_box *box); + The number of dimensions of a given type of space may be read off from a space or an object that lives in a space using the following functions. @@ -1109,65 +1186,65 @@ (only for sets) or C. #include - unsigned isl_space_dim(__isl_keep isl_space *space, + isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type); #include - int isl_local_space_dim(__isl_keep isl_local_space *ls, + isl_size isl_local_space_dim(__isl_keep isl_local_space *ls, enum isl_dim_type type); #include - unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset, + isl_size isl_basic_set_dim(__isl_keep isl_basic_set *bset, enum isl_dim_type type); - unsigned isl_set_dim(__isl_keep isl_set *set, + isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type); #include - unsigned isl_union_set_dim(__isl_keep isl_union_set *uset, + isl_size isl_union_set_dim(__isl_keep isl_union_set *uset, enum isl_dim_type type); #include - unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap, + isl_size isl_basic_map_dim(__isl_keep isl_basic_map *bmap, enum isl_dim_type type); - unsigned isl_map_dim(__isl_keep isl_map *map, + isl_size isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type); #include - unsigned isl_union_map_dim(__isl_keep isl_union_map *umap, + isl_size isl_union_map_dim(__isl_keep isl_union_map *umap, enum isl_dim_type type); #include - unsigned isl_multi_val_dim(__isl_keep isl_multi_val *mv, + isl_size isl_multi_val_dim(__isl_keep isl_multi_val *mv, enum isl_dim_type type); #include - int isl_aff_dim(__isl_keep isl_aff *aff, + isl_size isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type); - unsigned isl_multi_aff_dim(__isl_keep isl_multi_aff *maff, + isl_size isl_multi_aff_dim(__isl_keep isl_multi_aff *maff, enum isl_dim_type type); - unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, + isl_size isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type); - unsigned isl_pw_multi_aff_dim( + isl_size isl_pw_multi_aff_dim( __isl_keep isl_pw_multi_aff *pma, enum isl_dim_type type); - unsigned isl_multi_pw_aff_dim( + isl_size isl_multi_pw_aff_dim( __isl_keep isl_multi_pw_aff *mpa, enum isl_dim_type type); - unsigned isl_union_pw_aff_dim( + isl_size isl_union_pw_aff_dim( __isl_keep isl_union_pw_aff *upa, enum isl_dim_type type); - unsigned isl_union_pw_multi_aff_dim( + isl_size isl_union_pw_multi_aff_dim( __isl_keep isl_union_pw_multi_aff *upma, enum isl_dim_type type); - unsigned isl_multi_union_pw_aff_dim( + isl_size isl_multi_union_pw_aff_dim( __isl_keep isl_multi_union_pw_aff *mupa, enum isl_dim_type type); #include - unsigned isl_union_pw_qpolynomial_dim( + isl_size isl_union_pw_qpolynomial_dim( __isl_keep isl_union_pw_qpolynomial *upwqp, enum isl_dim_type type); - unsigned isl_union_pw_qpolynomial_fold_dim( + isl_size isl_union_pw_qpolynomial_fold_dim( __isl_keep isl_union_pw_qpolynomial_fold *upwf, enum isl_dim_type type); @@ -1186,6 +1263,13 @@ If a parameter with the given identifier already appears in the space, then it is not added again. + +Conversely, all parameters can be removed from a space +using the following function. + + #include + __isl_give isl_space *isl_space_drop_all_params( + __isl_take isl_space *space); The identifiers or names of the individual dimensions of spaces may be set or read off using the following functions on spaces @@ -1194,6 +1278,9 @@ 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 as described in +L. #include __isl_give isl_space *isl_space_set_dim_id( @@ -1361,6 +1448,7 @@ isl_multi_union_pw_aff_set_dim_name( __isl_take isl_multi_union_pw_aff *mupa, enum isl_dim_type type, unsigned pos, + const char *s); const char *isl_aff_get_dim_name(__isl_keep isl_aff *aff, enum isl_dim_type type, unsigned pos); const char *isl_pw_aff_get_dim_name( @@ -1456,7 +1544,7 @@ __isl_keep isl_multi_pw_aff *mpa, enum isl_dim_type type, __isl_keep isl_id *id); int isl_multi_union_pw_aff_find_dim_by_id( - __isl_keep isl_union_multi_pw_aff *mupa, + __isl_keep isl_multi_union_pw_aff *mupa, enum isl_dim_type type, __isl_keep isl_id *id); int isl_aff_find_dim_by_name(__isl_keep isl_aff *aff, enum isl_dim_type type, const char *name); @@ -1710,6 +1798,10 @@ #include __isl_give isl_union_map *isl_union_map_reset_user( __isl_take isl_union_map *umap); + + #include + __isl_give isl_multi_id *isl_multi_id_reset_user( + __isl_take isl_multi_id *mi); #include __isl_give isl_multi_val *isl_multi_val_reset_user( @@ -1836,13 +1928,24 @@ __isl_take isl_space *space); __isl_give isl_map *isl_map_empty( __isl_take isl_space *space); + __isl_give isl_union_set *isl_union_set_empty_ctx( + isl_ctx *ctx); + __isl_give isl_union_set *isl_union_set_empty_space( + __isl_take isl_space *space); __isl_give isl_union_set *isl_union_set_empty( + __isl_take isl_space *space); + __isl_give isl_union_map *isl_union_map_empty_ctx( + isl_ctx *ctx); + __isl_give isl_union_map *isl_union_map_empty_space( __isl_take isl_space *space); __isl_give isl_union_map *isl_union_map_empty( __isl_take isl_space *space); For Cs and Cs, the space is only used to specify the parameters. +C is an alternative name for +C. +Similarly for the other pair of functions. =item * Universe sets and relations @@ -1940,8 +2043,15 @@ union set or relation is known to contain elements in exactly one space. + #include + isl_bool isl_union_set_isa_set( + __isl_keep isl_union_set *uset); __isl_give isl_set *isl_set_from_union_set( __isl_take isl_union_set *uset); + + #include + isl_bool isl_union_map_isa_map( + __isl_keep isl_union_map *umap); __isl_give isl_map *isl_map_from_union_map( __isl_take isl_union_map *umap); @@ -2009,7 +2119,7 @@ __isl_take isl_constraint *constraint); For example, to create a set containing the even integers -between 10 and 42, you would use the following code. +between 10 and 42, you could use the following code. isl_space *space; isl_local_space *ls; @@ -2036,9 +2146,42 @@ bset = isl_basic_set_add_constraint(bset, c); bset = isl_basic_set_project_out(bset, isl_dim_set, 1, 1); + +However, this is considered to be a fairly low-level approach. +It is more appropriate to construct a (basic) set by means +of affine expressions (defined below in L). +For example, the same set could be constructed as follows. -Or, alternatively, + isl_val *v, *two; + isl_space *space; + isl_multi_aff *ma; + isl_aff *var, *cst; + isl_basic_set *bset; + space = isl_space_unit(ctx); + space = isl_space_add_unnamed_tuple_ui(space, 1); + ma = isl_multi_aff_identity_on_domain_space( + isl_space_copy(space)); + var = isl_multi_aff_get_at(ma, 0); + v = isl_val_int_from_si(ctx, 10); + cst = isl_aff_val_on_domain_space(isl_space_copy(space), v); + bset = isl_aff_ge_basic_set(isl_aff_copy(var), cst); + + v = isl_val_int_from_si(ctx, 42); + cst = isl_aff_val_on_domain_space(space, v); + bset = isl_basic_set_intersect(bset, + isl_aff_le_basic_set(var, cst)); + + two = isl_val_int_from_si(ctx, 2); + ma = isl_multi_aff_scale_val(ma, isl_val_copy(two)); + bset = isl_basic_set_preimage_multi_aff(bset, + isl_multi_aff_copy(ma)); + ma = isl_multi_aff_scale_down_val(ma, isl_val_copy(two)); + ma = isl_multi_aff_scale_down_val(ma, two); + bset = isl_basic_set_preimage_multi_aff(bset, ma); + +Alternatively, the set can be parsed from a string representation. + isl_basic_set *bset; bset = isl_basic_set_read_from_str(ctx, "{[i] : exists (a : i = 2a and i >= 10 and i <= 42)}"); @@ -2061,8 +2204,8 @@ The C arguments indicate the order in which different kinds of variables appear in the input matrices -and should be a permutation of C, C, -C and C for sets and +and should be a permutation of C (the constant term), +C, C and C for sets and of C, C, C, C and C for relations. @@ -2071,15 +2214,18 @@ or a list of affine expressions (See L), provided these affine expressions do not involve any NaN. + + #include + __isl_give isl_basic_set *isl_basic_set_from_multi_aff( + __isl_take isl_multi_aff *ma); + __isl_give isl_set *isl_set_from_multi_aff( + __isl_take isl_multi_aff *ma); + #include __isl_give isl_basic_map *isl_basic_map_from_aff( __isl_take isl_aff *aff); __isl_give isl_map *isl_map_from_aff( __isl_take isl_aff *aff); - __isl_give isl_set *isl_set_from_pw_aff( - __isl_take isl_pw_aff *pwaff); - __isl_give isl_map *isl_map_from_pw_aff( - __isl_take isl_pw_aff *pwaff); __isl_give isl_basic_map *isl_basic_map_from_aff_list( __isl_take isl_space *domain_space, __isl_take isl_aff_list *list); @@ -2087,6 +2233,12 @@ __isl_take isl_multi_aff *maff) __isl_give isl_map *isl_map_from_multi_aff( __isl_take isl_multi_aff *maff) + + #include + __isl_give isl_set *isl_set_from_pw_aff( + __isl_take isl_pw_aff *pwaff); + __isl_give isl_map *isl_map_from_pw_aff( + __isl_take isl_pw_aff *pwaff); __isl_give isl_set *isl_set_from_pw_multi_aff( __isl_take isl_pw_multi_aff *pma); __isl_give isl_map *isl_map_from_pw_multi_aff( @@ -2194,6 +2346,11 @@ isl_stat isl_union_set_foreach_set( __isl_keep isl_union_set *uset, isl_stat (*fn)(__isl_take isl_set *set, void *user), + void *user); + isl_bool isl_union_set_every_set( + __isl_keep isl_union_set *uset, + isl_bool (*test)(__isl_keep isl_set *set, + void *user), void *user); #include @@ -2211,15 +2368,16 @@ (pair of) space(s) for which there are elements in the input. The argument to the callback contains all elements in the input with that (pair of) space(s). -The C variant check whether each +The C and +C variants check whether each call to the callback returns true and stops checking as soon as one of these calls returns false. The number of sets or maps in a union set or map can be obtained from - int isl_union_set_n_set(__isl_keep isl_union_set *uset); - int isl_union_map_n_map(__isl_keep isl_union_map *umap); + isl_size isl_union_set_n_set(__isl_keep isl_union_set *uset); + isl_size isl_union_map_n_map(__isl_keep isl_union_map *umap); To extract the set or map in a given space from a union, use @@ -2260,13 +2418,14 @@ from #include - int isl_set_n_basic_set(__isl_keep isl_set *set); + isl_size isl_set_n_basic_set(__isl_keep isl_set *set); #include - int isl_map_n_basic_map(__isl_keep isl_map *map); + isl_size isl_map_n_basic_map(__isl_keep isl_map *map); -It is also possible to obtain a list of basic sets from a set -or union set +It is also possible to obtain a list of (basic) sets from a set +or union set, a list of basic maps from a map and a list of maps from a union +map. #include __isl_give isl_basic_set_list *isl_set_get_basic_set_list( @@ -2275,7 +2434,17 @@ #include __isl_give isl_basic_set_list * isl_union_set_get_basic_set_list( + __isl_keep isl_union_set *uset); + __isl_give isl_set_list *isl_union_set_get_set_list( __isl_keep isl_union_set *uset); + + #include + __isl_give isl_basic_map_list *isl_map_get_basic_map_list( + __isl_keep isl_map *map); + + #include + __isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap); The returned list can be manipulated using the functions in L<"Lists">. @@ -2283,14 +2452,14 @@ #include - int isl_basic_set_n_constraint( + isl_size isl_basic_set_n_constraint( __isl_keep isl_basic_set *bset); isl_stat isl_basic_set_foreach_constraint( __isl_keep isl_basic_set *bset, isl_stat (*fn)(__isl_take isl_constraint *c, void *user), void *user); - int isl_basic_map_n_constraint( + isl_size isl_basic_map_n_constraint( __isl_keep isl_basic_map *bmap); isl_stat isl_basic_map_foreach_constraint( __isl_keep isl_basic_map *bmap, @@ -2379,7 +2548,8 @@ The C arguments dictate the order in which different kinds of variables appear in the resulting matrix. For set inputs, they should be a permutation of -C, C, C and C. +C (the constant term), C, C and +C. For map inputs, they should be a permutation of C, C, C, C and C. @@ -2479,6 +2649,9 @@ Each of these types is derived from the value type (see L) 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) 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. @@ -2534,6 +2707,9 @@ #include __isl_give isl_aff *isl_aff_zero_on_domain( __isl_take isl_local_space *ls); + __isl_give isl_aff *isl_aff_val_on_domain_space( + __isl_take isl_space *space, + __isl_take isl_val *val); __isl_give isl_aff *isl_aff_val_on_domain( __isl_take isl_local_space *ls, __isl_take isl_val *val); @@ -2690,15 +2866,16 @@ The terms themselves can be inspected and freed using these functions - unsigned isl_term_dim(__isl_keep isl_term *term, + isl_size isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type); __isl_give isl_val *isl_term_get_coefficient_val( __isl_keep isl_term *term); - int isl_term_get_exp(__isl_keep isl_term *term, + isl_size isl_term_get_exp(__isl_keep isl_term *term, enum isl_dim_type type, unsigned pos); __isl_give isl_aff *isl_term_get_div( __isl_keep isl_term *term, unsigned pos); - void isl_term_free(__isl_take isl_term *term); + __isl_null isl_term *isl_term_free( + __isl_take isl_term *term); Each term is a product of parameters, set variables and integer divisions. The function C @@ -2726,8 +2903,23 @@ __isl_give isl_qpolynomial_fold * isl_qpolynomial_fold_copy( __isl_keep isl_qpolynomial_fold *fold); - void isl_qpolynomial_fold_free( + __isl_null isl_qpolynomial_fold * + isl_qpolynomial_fold_free( __isl_take isl_qpolynomial_fold *fold); + +The type of a (union piecewise) reduction +can be obtained using the following functions. + + #include + enum isl_fold isl_qpolynomial_fold_get_type( + __isl_keep isl_qpolynomial_fold *fold); + enum isl_fold isl_pw_qpolynomial_fold_get_type( + __isl_keep isl_pw_qpolynomial_fold *pwf); + enum isl_fold isl_union_pw_qpolynomial_fold_get_type( + __isl_keep isl_union_pw_qpolynomial_fold *upwf); + +The type may be either C or C +(or C in case of error). To iterate over all quasipolynomials in a reduction, use @@ -2745,13 +2937,18 @@ 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 +a corresponding zero-dimensional multiple expression may +have an explicit domain that keeps track of the domain +outside of any base expressions. The multiple expression types defined by C -are C, C, C, +are C, C, C, C, C. A multiple expression with the value zero for @@ -2776,14 +2973,32 @@ to C needs to be zero-dimensional. An identity function can be created using the following -functions. The space needs to be that of a relation +functions. +For the first group of functions, the space needs to be that of a set. +For the second group, +the space needs to be that of a relation with the same number of input and output dimensions. +For the third group, the input function needs to live in a space +with the same number of input and output dimensions and +the identity function is created in that space. #include + __isl_give isl_multi_aff * + isl_multi_aff_identity_on_domain_space( + __isl_take isl_space *space); + __isl_give isl_multi_pw_aff * + isl_multi_pw_aff_identity_on_domain_space( + __isl_take isl_space *space); __isl_give isl_multi_aff *isl_multi_aff_identity( __isl_take isl_space *space); __isl_give isl_multi_pw_aff *isl_multi_pw_aff_identity( __isl_take isl_space *space); + __isl_give isl_multi_aff * + isl_multi_aff_identity_multi_aff( + __isl_take isl_multi_aff *ma); + __isl_give isl_multi_pw_aff * + isl_multi_pw_aff_identity_multi_pw_aff( + __isl_take isl_multi_pw_aff *mpa); A function that performs a projection on a universe relation or set can be created using the following functions. @@ -2823,6 +3038,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_give isl_multi_id *isl_multi_id_from_id_list( + __isl_take isl_space *space, + __isl_take isl_id_list *list); #include __isl_give isl_multi_val *isl_multi_val_from_val_list( @@ -2895,6 +3115,12 @@ Multiple expressions can be copied and freed using the following functions. + + #include + __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_give isl_multi_val *isl_multi_val_copy( @@ -2917,39 +3143,101 @@ __isl_null isl_multi_union_pw_aff * isl_multi_union_pw_aff_free( __isl_take isl_multi_union_pw_aff *mupa); + +The number of base expressions in a multiple +expression can be obtained using the following functions. + + #include + int isl_multi_id_size(__isl_keep isl_multi_id *mi); + + #include + isl_size isl_multi_val_size(__isl_keep isl_multi_val *mv); + #include + isl_size isl_multi_aff_size( + __isl_keep isl_multi_aff *multi); + isl_size isl_multi_pw_aff_size( + __isl_keep isl_multi_pw_aff *mpa); + isl_size isl_multi_union_pw_aff_size( + __isl_keep isl_multi_union_pw_aff *mupa); + The base expression at a given position of a multiple expression can be extracted using the following functions. + + #include + __isl_give isl_id *isl_multi_id_get_at( + __isl_keep isl_multi_id *mi, int pos); + __isl_give isl_id *isl_multi_id_get_id( + __isl_keep isl_multi_id *mi, int pos); #include + __isl_give isl_val *isl_multi_val_get_at( + __isl_keep isl_multi_val *mv, int pos); __isl_give isl_val *isl_multi_val_get_val( __isl_keep isl_multi_val *mv, int pos); #include + __isl_give isl_aff *isl_multi_aff_get_at( + __isl_keep isl_multi_aff *ma, int pos); __isl_give isl_aff *isl_multi_aff_get_aff( __isl_keep isl_multi_aff *multi, int pos); + __isl_give isl_pw_aff *isl_multi_pw_aff_get_at( + __isl_keep isl_multi_pw_aff *mpa, int pos); __isl_give isl_pw_aff *isl_multi_pw_aff_get_pw_aff( __isl_keep isl_multi_pw_aff *mpa, int pos); + __isl_give isl_union_pw_aff * + isl_multi_union_pw_aff_get_at( + __isl_keep isl_multi_union_pw_aff *mupa, int pos); __isl_give isl_union_pw_aff * isl_multi_union_pw_aff_get_union_pw_aff( __isl_keep isl_multi_union_pw_aff *mupa, int pos); + +C is an alternative name for C. +Similarly for the other pairs of functions. -It can be replaced using the following functions. +The base expression can be replaced using the following functions. + + #include + __isl_give isl_multi_id *isl_multi_id_set_at( + __isl_take isl_multi_id *mi, int pos, + __isl_take isl_id *id); + __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_give isl_multi_val *isl_multi_val_set_at( + __isl_take isl_multi_val *mv, int pos, + __isl_take isl_val *val); __isl_give isl_multi_val *isl_multi_val_set_val( __isl_take isl_multi_val *mv, int pos, __isl_take isl_val *val); #include + __isl_give isl_multi_aff *isl_multi_aff_set_at( + __isl_take isl_multi_aff *ma, int pos, + __isl_take isl_aff *aff); __isl_give isl_multi_aff *isl_multi_aff_set_aff( __isl_take isl_multi_aff *multi, int pos, __isl_take isl_aff *aff); + __isl_give isl_multi_pw_aff *isl_multi_pw_aff_set_at( + __isl_take isl_multi_pw_aff *mpa, int pos, + __isl_take isl_pw_aff *pa); + __isl_give isl_multi_pw_aff *isl_multi_pw_aff_set_pw_aff( + __isl_take isl_multi_pw_aff *mpa, int pos, + __isl_take isl_pw_aff *pa); + __isl_give isl_multi_union_pw_aff * + isl_multi_union_pw_aff_set_at( + __isl_take isl_multi_union_pw_aff *mupa, int pos, + __isl_take isl_union_pw_aff *upa); __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_set_union_pw_aff( __isl_take isl_multi_union_pw_aff *mupa, int pos, __isl_take isl_union_pw_aff *upa); +C is an alternative name for C. +Similarly for the other pairs of functions. + As a convenience, a sequence of base expressions that have their domains in a given space can be extracted from a sequence of union expressions using the following function. @@ -2969,10 +3257,7 @@ an C, which can therefore only live in a single space. This means that not every C can be converted to -an C. Conversely, a zero-dimensional -C carries no information -about any possible domain and therefore cannot be converted -to an C. Moreover, the elements +an C. Conversely, the elements of an C may be defined over different domains, while each multiple expression inside an C has a single domain. The conversion of an C @@ -3043,6 +3328,33 @@ __isl_give isl_pw_qpolynomial * isl_pw_qpolynomial_from_qpolynomial( __isl_take isl_qpolynomial *qp); + __isl_give isl_pw_qpolynomial_fold * + isl_pw_qpolynomial_fold_from_qpolynomial_fold( + __isl_take isl_qpolynomial_fold *fold); + +The inverse conversions below can only be used if the input +expression is known to be defined over a single universe domain. + + #include + isl_bool isl_pw_aff_isa_aff(__isl_keep isl_pw_aff *pa); + __isl_give isl_aff *isl_pw_aff_as_aff( + __isl_take isl_pw_aff *pa); + isl_bool isl_pw_multi_aff_isa_multi_aff( + __isl_keep isl_pw_multi_aff *pma); + __isl_give isl_multi_aff *isl_pw_multi_aff_as_multi_aff( + __isl_take isl_pw_multi_aff *pma); + + #include + isl_bool isl_pw_qpolynomial_isa_qpolynomial( + __isl_keep isl_pw_qpolynomial *pwqp); + __isl_give isl_qpolynomial * + isl_pw_qpolynomial_as_qpolynomial( + __isl_take isl_pw_qpolynomial *pwqp); + isl_bool isl_pw_qpolynomial_fold_isa_qpolynomial_fold( + __isl_keep isl_pw_qpolynomial_fold *pwf); + __isl_give isl_qpolynomial_fold * + isl_pw_qpolynomial_fold_as_qpolynomial_fold( + __isl_take isl_pw_qpolynomial_fold *pwf); A piecewise expression with a single specified cell can be created using the following functions. @@ -3097,6 +3409,9 @@ isl_pw_multi_aff_multi_val_on_domain( __isl_take isl_set *domain, __isl_take isl_multi_val *mv); + __isl_give isl_pw_aff *isl_pw_aff_param_on_domain_id( + __isl_take isl_set *domain, + __isl_take isl_id *id); As a convenience, a piecewise multiple expression can also be created from a piecewise expression. @@ -3145,13 +3460,13 @@ #include isl_bool isl_pw_aff_is_empty(__isl_keep isl_pw_aff *pwaff); - int isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff); + isl_size isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff); isl_stat isl_pw_aff_foreach_piece( __isl_keep isl_pw_aff *pwaff, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user), void *user); - int isl_pw_multi_aff_n_piece( + isl_size isl_pw_multi_aff_n_piece( __isl_keep isl_pw_multi_aff *pma); isl_stat isl_pw_multi_aff_foreach_piece( __isl_keep isl_pw_multi_aff *pma, @@ -3160,7 +3475,7 @@ void *user), void *user); #include - int isl_pw_qpolynomial_n_piece( + isl_size isl_pw_qpolynomial_n_piece( __isl_keep isl_pw_qpolynomial *pwqp); isl_stat isl_pw_qpolynomial_foreach_piece( __isl_keep isl_pw_qpolynomial *pwqp, @@ -3172,7 +3487,7 @@ isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp, void *user), void *user); - int isl_pw_qpolynomial_fold_n_piece( + isl_size isl_pw_qpolynomial_fold_n_piece( __isl_keep isl_pw_qpolynomial_fold *pwf); isl_stat isl_pw_qpolynomial_fold_foreach_piece( __isl_keep isl_pw_qpolynomial_fold *pwf, @@ -3256,7 +3571,19 @@ An empty union expression can be created using the following functions. #include + __isl_give isl_union_pw_aff * + isl_union_pw_aff_empty_ctx( + isl_ctx *ctx); + __isl_give isl_union_pw_aff * + isl_union_pw_aff_empty_space( + __isl_take isl_space *space); __isl_give isl_union_pw_aff *isl_union_pw_aff_empty( + __isl_take isl_space *space); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_empty_ctx( + isl_ctx *ctx); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_empty_space( __isl_take isl_space *space); __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_empty( @@ -3264,9 +3591,19 @@ #include __isl_give isl_union_pw_qpolynomial * + isl_union_pw_qpolynomial_zero_ctx( + isl_ctx *ctx); + __isl_give isl_union_pw_qpolynomial * + isl_union_pw_qpolynomial_zero_space( + __isl_take isl_space *space); + __isl_give isl_union_pw_qpolynomial * isl_union_pw_qpolynomial_zero( __isl_take isl_space *space); +C is an alternative name for +C. +Similarly for the other pairs of functions. + A union expression containing a single base expression can be created using the following functions. @@ -3285,6 +3622,16 @@ __isl_give isl_union_pw_qpolynomial * isl_union_pw_qpolynomial_from_pw_qpolynomial( __isl_take isl_pw_qpolynomial *pwqp); + +The inverse conversions below can only be used if the input +expression is known to live in exactly one space. + + #include + isl_bool isl_union_pw_multi_aff_isa_pw_multi_aff( + __isl_keep isl_union_pw_multi_aff *upma); + __isl_give isl_pw_multi_aff * + isl_union_pw_multi_aff_as_pw_multi_aff( + __isl_take isl_union_pw_multi_aff *upma); The following functions create a base expression on each of the sets in the union set and collect the results. @@ -3380,13 +3727,13 @@ use the following functions. #include - int isl_union_pw_aff_n_pw_aff( + isl_size isl_union_pw_aff_n_pw_aff( __isl_keep isl_union_pw_aff *upa); isl_stat isl_union_pw_aff_foreach_pw_aff( __isl_keep isl_union_pw_aff *upa, isl_stat (*fn)(__isl_take isl_pw_aff *pa, void *user), void *user); - int isl_union_pw_multi_aff_n_pw_multi_aff( + isl_size isl_union_pw_multi_aff_n_pw_multi_aff( __isl_keep isl_union_pw_multi_aff *upma); isl_stat isl_union_pw_multi_aff_foreach_pw_multi_aff( __isl_keep isl_union_pw_multi_aff *upma, @@ -3394,13 +3741,13 @@ void *user), void *user); #include - int isl_union_pw_qpolynomial_n_pw_qpolynomial( + isl_size isl_union_pw_qpolynomial_n_pw_qpolynomial( __isl_keep isl_union_pw_qpolynomial *upwqp); isl_stat isl_union_pw_qpolynomial_foreach_pw_qpolynomial( __isl_keep isl_union_pw_qpolynomial *upwqp, isl_stat (*fn)(__isl_take isl_pw_qpolynomial *pwqp, void *user), void *user); - int isl_union_pw_qpolynomial_fold_n_pw_qpolynomial_fold( + isl_size isl_union_pw_qpolynomial_fold_n_pw_qpolynomial_fold( __isl_keep isl_union_pw_qpolynomial_fold *upwf); isl_stat isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold( __isl_keep isl_union_pw_qpolynomial_fold *upwf, @@ -3424,6 +3771,27 @@ isl_union_pw_qpolynomial_extract_pw_qpolynomial( __isl_keep isl_union_pw_qpolynomial *upwqp, __isl_take isl_space *space); + +It is also possible to obtain a list of the base expressions using +the following functions. + + #include + __isl_give isl_pw_aff_list * + isl_union_pw_aff_get_pw_aff_list( + __isl_keep isl_union_pw_aff *upa); + __isl_give isl_pw_multi_aff_list * + isl_union_pw_multi_aff_get_pw_multi_aff_list( + __isl_keep isl_union_pw_multi_aff *upma); + + #include + __isl_give isl_pw_qpolynomial_list * + isl_union_pw_qpolynomial_get_pw_qpolynomial_list( + __isl_keep isl_union_pw_qpolynomial *upwqp); + __isl_give isl_pw_qpolynomial_fold_list * + isl_union_pw_qpolynomial_fold_get_pw_qpolynomial_fold_list( + __isl_keep isl_union_pw_qpolynomial_fold *upwf); + +The returned list can be manipulated using the functions in L<"Lists">. =head2 Input and Output @@ -3488,6 +3856,12 @@ =head3 Input Objects can be read from input using the following functions. + + #include + __isl_give isl_id *isl_id_read_from_str(isl_ctx *ctx, + const char *str); + __isl_give isl_multi_id *isl_multi_id_read_from_str( + isl_ctx *ctx, const char *str); #include __isl_give isl_val *isl_val_read_from_str(isl_ctx *ctx, @@ -3657,6 +4031,11 @@ __isl_give isl_printer *isl_printer_print_multi_val( __isl_take isl_printer *p, __isl_keep isl_multi_val *mv); + + #include + __isl_give isl_printer *isl_printer_print_multi_id( + __isl_take isl_printer *p, + __isl_keep isl_multi_id *mi); #include __isl_give isl_printer *isl_printer_print_aff( @@ -3775,6 +4154,8 @@ #include __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_give char *isl_space_to_str( @@ -3972,34 +4353,55 @@ __isl_keep isl_set *set, int pos); __isl_give isl_val *isl_set_get_stride( __isl_keep isl_set *set, int pos); + + #include + __isl_give isl_stride_info * + isl_map_get_range_stride_info( + __isl_keep isl_map *map, int pos); Check if the values of the given set dimension are equal to some affine expression of the other dimensions (the offset) +modulo some integer stride or +check if the values of the given output dimensions are equal to +some affine expression of the input dimensions (the offset) modulo some integer stride. If no more specific information can be found, then the stride is taken to be one and the offset is taken to be the zero expression. -The function C performs the same -computation but only returns the stride. -Otherwise, +The function C performs the same +computation as C but only returns the stride. +For the other functions, the stride and offset can be extracted from the returned object using the following functions. - #include + #include __isl_give isl_val *isl_stride_info_get_stride( __isl_keep isl_stride_info *si); __isl_give isl_aff *isl_stride_info_get_offset( __isl_keep isl_stride_info *si); -The stride info object can be released using the following function. +The stride info object can be copied and released using the following +functions. - #include + #include + __isl_give isl_stride_info *isl_stride_info_copy( + __isl_keep isl_stride_info *si); __isl_null isl_stride_info *isl_stride_info_free( __isl_take isl_stride_info *si); =item * Dependence +To check whether a function involves any local variables, +i.e., integer divisions, +the following functions can be used. + + #include + isl_bool isl_aff_involves_locals( + __isl_keep isl_aff *aff); + isl_bool isl_multi_aff_involves_locals( + __isl_keep isl_multi_aff *ma); + To check whether the description of a set, relation or function depends -on one or more given dimensions, +on a parameter or one or more given dimensions, the following functions can be used. #include @@ -4029,20 +4431,41 @@ #include isl_bool isl_aff_involves_dims(__isl_keep isl_aff *aff, enum isl_dim_type type, unsigned first, unsigned n); + isl_bool isl_pw_aff_involves_param_id( + __isl_keep isl_pw_aff *pa, + __isl_keep isl_id *id); isl_bool isl_pw_aff_involves_dims( __isl_keep isl_pw_aff *pwaff, enum isl_dim_type type, unsigned first, unsigned n); isl_bool isl_multi_aff_involves_dims( __isl_keep isl_multi_aff *ma, + enum isl_dim_type type, unsigned first, unsigned n); + isl_bool isl_pw_multi_aff_involves_param_id( + __isl_keep isl_pw_multi_aff *pma, + __isl_keep isl_id *id); + isl_bool isl_pw_multi_aff_involves_dims( + __isl_keep isl_pw_multi_aff *pma, enum isl_dim_type type, unsigned first, unsigned n); isl_bool isl_multi_pw_aff_involves_dims( __isl_keep isl_multi_pw_aff *mpa, enum isl_dim_type type, unsigned first, unsigned n); + isl_bool isl_multi_pw_aff_involves_param_id( + __isl_keep isl_multi_pw_aff *mpa, + __isl_keep isl_id *id); + isl_bool isl_multi_pw_aff_involves_param_id_list( + __isl_keep isl_multi_pw_aff *mpa, + __isl_keep isl_id_list *list); #include isl_bool isl_qpolynomial_involves_dims( __isl_keep isl_qpolynomial *qp, enum isl_dim_type type, unsigned first, unsigned n); + isl_bool isl_pw_qpolynomial_involves_param_id( + __isl_keep isl_pw_qpolynomial *pwqp, + __isl_keep isl_id *id); + isl_bool isl_pw_qpolynomial_fold_involves_param_id( + __isl_keep isl_pw_qpolynomial_fold *pwf, + __isl_keep isl_id *id); Similarly, the following functions can be used to check whether a given dimension is involved in any lower or upper bound. @@ -4102,6 +4525,10 @@ isl_bool isl_map_range_is_wrapping( __isl_keep isl_map *map); isl_bool isl_map_is_product(__isl_keep isl_map *map); + + #include + isl_bool isl_multi_id_range_is_wrapping( + __isl_keep isl_multi_id *mi); #include isl_bool isl_multi_val_range_is_wrapping( @@ -4269,6 +4696,16 @@ isl_bool isl_union_map_is_equal( __isl_keep isl_union_map *umap1, __isl_keep isl_union_map *umap2); + + #include + isl_bool isl_multi_id_plain_is_equal( + __isl_keep isl_multi_id *mi1, + __isl_keep isl_multi_id *mi2); + + #include + isl_bool isl_multi_val_plain_is_equal( + __isl_keep isl_multi_val *mv1, + __isl_keep isl_multi_val *mv2); #include isl_bool isl_aff_plain_is_equal( @@ -4449,6 +4886,8 @@ #include __isl_give isl_space *isl_space_reverse( + __isl_take isl_space *space); + __isl_give isl_space *isl_space_range_reverse( __isl_take isl_space *space); #include @@ -4456,10 +4895,109 @@ __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_reverse( __isl_take isl_map *map); + __isl_give isl_map *isl_map_range_reverse( + __isl_take isl_map *map); #include __isl_give isl_union_map *isl_union_map_reverse( + __isl_take isl_union_map *umap); + __isl_give isl_union_map *isl_union_map_range_reverse( __isl_take isl_union_map *umap); + +The function C reverses the relation +that is embedded in the range of the input map space. +The identifier of the range, if any, is only preserved +if this embedded relation has identical input and output tuples. + +=item * Tuple binding + +The following function binds +a tuple to a sequence of parameter identifiers, equating +the tuple dimensions to the parameters with those identifiers and +subsequently projecting out the tuple. +If the original object did not reference any such parameters, +then this means that the tuple dimensions are reinterpreted +as parameters. +The space of C needs to match that of the bound tuple. + + #include + __isl_give isl_set *isl_set_bind( + __isl_take isl_set *set, + __isl_take isl_multi_id *tuple); + + #include + __isl_give isl_set *isl_map_bind_domain( + __isl_take isl_map *map, + __isl_take isl_multi_id *tuple); + __isl_give isl_set *isl_map_bind_range( + __isl_take isl_map *map, + __isl_take isl_multi_id *tuple); + + #include + __isl_give isl_union_set *isl_union_map_bind_range( + __isl_take isl_union_map *umap, + __isl_take isl_multi_id *tuple); + + #include + __isl_give isl_pw_aff *isl_pw_aff_bind_domain( + __isl_take isl_pw_aff *pa, + __isl_take isl_multi_id *tuple); + __isl_give isl_multi_aff *isl_multi_aff_bind_domain( + __isl_take isl_multi_aff *ma, + __isl_take isl_multi_id *tuple); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_bind_domain( + __isl_take isl_pw_multi_aff *pma, + __isl_take isl_multi_id *tuple); + __isl_give isl_multi_pw_aff * + isl_multi_pw_aff_bind_domain( + __isl_take isl_multi_pw_aff *mpa, + __isl_take isl_multi_id *tuple); + __isl_give isl_pw_aff * + isl_pw_aff_bind_domain_wrapped_domain( + __isl_take isl_pw_aff *pa, + __isl_take isl_multi_id *tuple); + __isl_give isl_multi_aff * + isl_multi_aff_bind_domain_wrapped_domain( + __isl_take isl_multi_aff *ma, + __isl_take isl_multi_id *tuple); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_bind_domain_wrapped_domain( + __isl_take isl_pw_multi_aff *pma, + __isl_take isl_multi_id *tuple); + __isl_give isl_multi_pw_aff * + isl_multi_pw_aff_bind_domain_wrapped_domain( + __isl_take isl_multi_pw_aff *mpa, + __isl_take isl_multi_id *tuple); + __isl_give isl_basic_set *isl_aff_bind_id( + __isl_take isl_aff *aff, + __isl_take isl_id *id); + __isl_give isl_set *isl_pw_aff_bind_id( + __isl_take isl_pw_aff *pa, + __isl_take isl_id *id); + __isl_give isl_basic_set *isl_multi_aff_bind( + __isl_take isl_multi_aff *ma, + __isl_take isl_multi_id *tuple); + __isl_give isl_set *isl_multi_pw_aff_bind( + __isl_take isl_multi_pw_aff *mpa, + __isl_take isl_multi_id *tuple); + __isl_give isl_union_set *isl_union_pw_aff_bind_id( + __isl_take isl_union_pw_aff *upa, + __isl_take isl_id *id); + __isl_give isl_union_set * + isl_multi_union_pw_aff_bind( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_multi_id *tuple); + +Projecting out the domain of the wrapped relation in the domain +of a function leaves the range of that wrapped relation +in the domain of the resulting function. +In the case of C, C, +C, C, +C and +C, the parameters +are bound to the function values and the result lives +in the domain of the input function. =item * Projection @@ -4481,8 +5019,17 @@ __isl_give isl_basic_set *isl_basic_set_project_out( __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n); + __isl_give isl_set *isl_set_project_out_param_id( + __isl_take isl_set *set, + __isl_take isl_id *id); + __isl_give isl_set * + isl_set_project_out_param_id_list( + __isl_take isl_set *set, + __isl_take isl_id_list *list); __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n); + __isl_give isl_set *isl_set_project_out_all_params( + __isl_take isl_set *set); __isl_give isl_map *isl_set_project_onto_map( __isl_take isl_set *set, enum isl_dim_type type, unsigned first, @@ -4500,6 +5047,8 @@ enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n); + __isl_give isl_map *isl_map_project_out_all_params( + __isl_take isl_map *map); __isl_give isl_basic_set *isl_basic_map_domain( __isl_take isl_basic_map *bmap); __isl_give isl_basic_set *isl_basic_map_range( @@ -4515,6 +5064,9 @@ __isl_take isl_union_set *uset, enum isl_dim_type type, unsigned first, unsigned n); + __isl_give isl_union_set * + isl_union_set_project_out_all_params( + __isl_take isl_union_set *uset); __isl_give isl_set *isl_union_set_params( __isl_take isl_union_set *uset); @@ -4569,8 +5121,9 @@ __isl_give isl_set *isl_pw_aff_params( __isl_take isl_pw_aff *pwa); -The function C requires its -input to have at least one set dimension. +If no explicit domain was set on a zero-dimensional input to +C, then this function will +return a parameter set. #include __isl_give isl_qpolynomial * @@ -4643,7 +5196,29 @@ without removing the dimensions. =item * Constructing a set from a parameter domain + +A set space of a given dimension and with an optional name +can be created from a parameter space using the following functions. + #include + __isl_give isl_space *isl_space_add_unnamed_tuple_ui( + __isl_take isl_space *space, unsigned dim); + __isl_give isl_space * + isl_space_add_named_tuple_id_ui( + __isl_take isl_space *space, + __isl_take isl_id *tuple_id, unsigned dim); + +A set with a given tuple can be created from a parameter domain +using the following function. + + #include + __isl_give isl_set *isl_set_unbind_params( + __isl_take isl_set *set, + __isl_take isl_multi_id *tuple); + +Any parameters with identifiers in C are reinterpreted +as the corresponding set dimensions. + A zero-dimensional (local) space or (basic) set can be constructed on a given parameter domain using the following functions. @@ -4663,11 +5238,45 @@ __isl_take isl_set *set); =item * Constructing a relation from one or two sets + +A map space with a range of a given dimension and with an optional name +can be created from a domain space using the functions +C and C +described above. + +A relation with a given domain tuple can be created from a set +that will become the range of the relation +using the following function. + + #include + __isl_give isl_map * + isl_set_unbind_params_insert_domain( + __isl_take isl_set *set, + __isl_take isl_multi_id *domain); + +Any parameters with identifiers in C are reinterpreted +as the corresponding input dimensions. + +Similarly, a function defined over a parameter domain can +be converted into one defined over a set domain +using the following function. + + #include + __isl_give isl_aff * + isl_aff_unbind_params_insert_domain( + __isl_take isl_aff *aff, + __isl_take isl_multi_id *domain); +Again, +any parameters with identifiers in C are reinterpreted +as the corresponding input dimensions. + Create a relation with the given set(s) as domain and/or range. If only the domain or the range is specified, then the range or domain of the created relation is a zero-dimensional flat anonymous space. +If the case of C, the input space +specifies both the domain and the range of the result. #include __isl_give isl_space *isl_space_from_domain( @@ -4699,6 +5308,10 @@ isl_union_map_from_domain_and_range( __isl_take isl_union_set *domain, __isl_take isl_union_set *range); + + #include + __isl_give isl_multi_id *isl_multi_id_from_range( + __isl_take isl_multi_id *mi); #include __isl_give isl_multi_val *isl_multi_val_from_range( @@ -5042,6 +5655,17 @@ isl_ctx *ctx, int val); int isl_options_get_coalesce_bounded_wrapping( isl_ctx *ctx); + +One of the other methods tries to combine pairs of basic sets +with different local variables, treating them as existentially +quantified variables even if they have known (but different) +integer division expressions. The result may then also have +existentially quantified variables. Turning on the following +option prevents this from happening. + + isl_stat isl_options_set_coalesce_preserve_locals( + isl_ctx *ctx, int val); + int isl_options_get_coalesce_preserve_locals(isl_ctx *ctx); =item * Detecting equalities @@ -5183,7 +5807,55 @@ that contains the whole input set or relation. In case of union sets and relations, the polyhedral hull is computed per space. + +=item * Box hull + #include + __isl_give isl_fixed_box * + isl_map_get_range_simple_fixed_box_hull( + __isl_keep isl_map *map); + +This function tries to approximate the range of the map by a box of fixed size. +The box is described in terms of an offset living in the same space as +the input map and a size living in the range space. For any element +in the input map, the range value is greater than or equal to +the offset applied to the domain value and the difference with +this offset is strictly smaller than the size. +If no fixed-size approximation of the range can be found, +an I box is returned, i.e., one for which +C below returns false. + +The validity, the offset and the size of the box can be obtained using +the following functions. + + #include + isl_bool isl_fixed_box_is_valid( + __isl_keep isl_fixed_box *box); + __isl_give isl_multi_aff *isl_fixed_box_get_offset( + __isl_keep isl_fixed_box *box); + __isl_give isl_multi_val *isl_fixed_box_get_size( + __isl_keep isl_fixed_box *box); + +The box can be copied and freed using the following functions. + + #include + __isl_give isl_fixed_box *isl_fixed_box_copy( + __isl_keep isl_fixed_box *box); + __isl_null isl_fixed_box *isl_fixed_box_free( + __isl_take isl_fixed_box *box); + +A representation of the information contained in an object +of type C can be obtained using + + #include + __isl_give isl_printer *isl_printer_print_fixed_box( + __isl_take isl_printer *p, + __isl_keep isl_fixed_box *box); + __isl_give char *isl_fixed_box_to_str( + __isl_keep isl_fixed_box *box); + +C prints the information in flow format. + =item * Other approximations #include @@ -5273,11 +5945,29 @@ __isl_keep isl_aff *obj); __isl_give isl_multi_val * isl_union_set_min_multi_union_pw_aff( - __isl_keep isl_union_set *set, + __isl_keep isl_union_set *uset, __isl_keep isl_multi_union_pw_aff *obj); Compute the minimum or maximum of the integer affine expression C -over the points in C, returning the result in C. +over the points in C. +The result is C in case of an error, the optimal value in case +there is one, negative infinity or infinity if the problem is unbounded and +NaN if the problem is empty. + + #include + __isl_give isl_val *isl_union_pw_aff_min_val( + __isl_take isl_union_pw_aff *upa); + __isl_give isl_val *isl_union_pw_aff_max_val( + __isl_take isl_union_pw_aff *upa); + __isl_give isl_multi_val * + isl_multi_union_pw_aff_min_multi_val( + __isl_take isl_multi_union_pw_aff *mupa); + __isl_give isl_multi_val * + isl_multi_union_pw_aff_max_multi_val( + __isl_take isl_multi_union_pw_aff *mupa); + +Compute the minimum or maximum of the integer affine expression +over its definition domain. The result is C in case of an error, the optimal value in case there is one, negative infinity or infinity if the problem is unbounded and NaN if the problem is empty. @@ -5353,9 +6043,9 @@ of C is computed. __isl_give isl_map *isl_map_power(__isl_take isl_map *map, - int *exact); + isl_bool *exact); __isl_give isl_union_map *isl_union_map_power( - __isl_take isl_union_map *umap, int *exact); + __isl_take isl_union_map *umap, isl_bool *exact); Compute a parametric representation for all positive powers I of C. The result maps I to a nested relation corresponding to the @@ -5366,9 +6056,9 @@ =item * Transitive closure __isl_give isl_map *isl_map_transitive_closure( - __isl_take isl_map *map, int *exact); + __isl_take isl_map *map, isl_bool *exact); __isl_give isl_union_map *isl_union_map_transitive_closure( - __isl_take isl_union_map *umap, int *exact); + __isl_take isl_union_map *umap, isl_bool *exact); Compute the transitive closure of C. The result may be an overapproximation. If the result is known to be exact, @@ -5377,7 +6067,7 @@ =item * Reaching path lengths __isl_give isl_map *isl_map_reaching_path_lengths( - __isl_take isl_map *map, int *exact); + __isl_take isl_map *map, isl_bool *exact); Compute a relation that maps each element in the range of C to the lengths of all paths composed of edges in C that @@ -5470,6 +6160,10 @@ __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_flatten( __isl_take isl_map *map); + + #include + __isl_give isl_multi_id *isl_multi_id_flatten_range( + __isl_take isl_multi_id *mi); #include __isl_give isl_multi_val *isl_multi_val_flatten_range( @@ -5620,6 +6314,11 @@ __isl_take isl_space *model); __isl_give isl_map *isl_map_align_params( __isl_take isl_map *map, + __isl_take isl_space *model); + + #include + __isl_give isl_multi_id *isl_multi_id_align_params( + __isl_take isl_multi_id *mi, __isl_take isl_space *model); #include @@ -5658,6 +6357,40 @@ __isl_take isl_qpolynomial *qp, __isl_take isl_space *model); +=item * Drop unused parameters + +Drop parameters that are not referenced by the isl object. +All parameters need to be named. + + #include + __isl_give isl_basic_set * + isl_basic_set_drop_unused_params( + __isl_take isl_basic_set *bset); + __isl_give isl_set *isl_set_drop_unused_params( + __isl_take isl_set *set); + + #include + __isl_give isl_basic_map * + isl_basic_map_drop_unused_params( + __isl_take isl_basic_map *bmap); + __isl_give isl_map *isl_map_drop_unused_params( + __isl_take isl_map *map); + + #include + __isl_give isl_pw_aff *isl_pw_aff_drop_unused_params( + __isl_take isl_pw_aff *pa); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_drop_unused_params( + __isl_take isl_pw_multi_aff *pma); + + #include + __isl_give isl_pw_qpolynomial * + isl_pw_qpolynomial_drop_unused_params( + __isl_take isl_pw_qpolynomial *pwqp); + __isl_give isl_pw_qpolynomial_fold * + isl_pw_qpolynomial_fold_drop_unused_params( + __isl_take isl_pw_qpolynomial_fold *pwf); + =item * Unary Arithmetic Operations #include @@ -5737,6 +6470,14 @@ =item * Evaluation The following functions evaluate a function in a point. + + #include + __isl_give isl_val *isl_aff_eval( + __isl_take isl_aff *aff, + __isl_take isl_point *pnt); + __isl_give isl_val *isl_pw_aff_eval( + __isl_take isl_pw_aff *pa, + __isl_take isl_point *pnt); #include __isl_give isl_val *isl_pw_qpolynomial_eval( @@ -5753,6 +6494,9 @@ __isl_take isl_point *pnt); These functions return NaN when evaluated at a void point. +Note that C returns NaN when the function is evaluated outside +its definition domain, while C returns zero +when the function is evaluated outside its explicit domain. =item * Dimension manipulation @@ -5970,6 +6714,12 @@ __isl_give isl_set *isl_set_intersect( __isl_take isl_set *set1, __isl_take isl_set *set2); + __isl_give isl_set *isl_set_intersect_factor_domain( + __isl_take isl_set *set, + __isl_take isl_set *domain); + __isl_give isl_set *isl_set_intersect_factor_range( + __isl_take isl_set *set, + __isl_take isl_set *range); #include __isl_give isl_basic_map *isl_basic_map_intersect_domain( @@ -6000,6 +6750,10 @@ __isl_take isl_map *map, __isl_take isl_map *factor); __isl_give isl_map * + isl_map_intersect_range_factor_domain( + __isl_take isl_map *map, + __isl_take isl_map *factor); + __isl_give isl_map * isl_map_intersect_range_factor_range( __isl_take isl_map *map, __isl_take isl_map *factor); @@ -6025,6 +6779,14 @@ __isl_give isl_union_map *isl_union_map_intersect( __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); + __isl_give isl_union_map * + isl_union_map_intersect_domain_factor_range( + __isl_take isl_union_map *umap, + __isl_take isl_union_map *factor); + __isl_give isl_union_map * + isl_union_map_intersect_range_factor_domain( + __isl_take isl_union_map *umap, + __isl_take isl_union_map *factor); __isl_give isl_union_map * isl_union_map_intersect_range_factor_range( __isl_take isl_union_map *umap, @@ -6051,6 +6813,38 @@ __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_intersect_domain( __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_union_set *uset); + __isl_give isl_pw_aff * + isl_pw_aff_intersect_domain_wrapped_domain( + __isl_take isl_pw_aff *pa, + __isl_take isl_set *set); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_intersect_domain_wrapped_domain( + __isl_take isl_pw_multi_aff *pma, + __isl_take isl_set *set); + __isl_give isl_union_pw_aff * + isl_union_pw_aff_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_aff *upa, + __isl_take isl_union_set *uset); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_multi_aff *upma, + __isl_take isl_union_set *uset); + __isl_give isl_pw_aff * + isl_pw_aff_intersect_domain_wrapped_range( + __isl_take isl_pw_aff *pa, + __isl_take isl_set *set); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_intersect_domain_wrapped_range( + __isl_take isl_pw_multi_aff *pma, + __isl_take isl_set *set); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_intersect_domain_wrapped_range( + __isl_take isl_union_pw_multi_aff *upma, + __isl_take isl_union_set *uset); + __isl_give isl_union_pw_aff * + isl_union_pw_aff_intersect_domain_wrapped_range( + __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *uset); __isl_give isl_pw_aff *isl_pw_aff_intersect_params( __isl_take isl_pw_aff *pa, @@ -6065,6 +6859,7 @@ __isl_give isl_union_pw_aff * isl_union_pw_aff_intersect_params( __isl_take isl_union_pw_aff *upa, + __isl_take isl_set *set); __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_intersect_params( __isl_take isl_union_pw_multi_aff *upma, @@ -6073,6 +6868,7 @@ isl_multi_union_pw_aff_intersect_params( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_set *params); + __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_intersect_range( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_set *set); @@ -6088,6 +6884,38 @@ __isl_take isl_union_set *uset); __isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_intersect_domain( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + __isl_take isl_union_set *uset); + __isl_give isl_pw_qpolynomial * + isl_pw_qpolynomial_intersect_domain_wrapped_domain( + __isl_take isl_pw_qpolynomial *pwpq, + __isl_take isl_set *set); + __isl_give isl_pw_qpolynomial_fold * + isl_pw_qpolynomial_fold_intersect_domain_wrapped_domain( + __isl_take isl_pw_qpolynomial_fold *pwf, + __isl_take isl_set *set); + __isl_give isl_union_pw_qpolynomial * + isl_union_pw_qpolynomial_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_qpolynomial *upwpq, + __isl_take isl_union_set *uset); + __isl_give isl_union_pw_qpolynomial_fold * + isl_union_pw_qpolynomial_fold_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + __isl_take isl_union_set *uset); + __isl_give isl_pw_qpolynomial * + isl_pw_qpolynomial_intersect_domain_wrapped_range( + __isl_take isl_pw_qpolynomial *pwpq, + __isl_take isl_set *set); + __isl_give isl_pw_qpolynomial_fold * + isl_pw_qpolynomial_fold_intersect_domain_wrapped_range( + __isl_take isl_pw_qpolynomial_fold *pwf, + __isl_take isl_set *set); + __isl_give isl_union_pw_qpolynomial * + isl_union_pw_qpolynomial_intersect_domain_wrapped_range( + __isl_take isl_union_pw_qpolynomial *upwpq, + __isl_take isl_union_set *uset); + __isl_give isl_union_pw_qpolynomial_fold * + isl_union_pw_qpolynomial_fold_intersect_domain_wrapped_range( __isl_take isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_union_set *uset); __isl_give isl_pw_qpolynomial * @@ -6201,7 +7029,7 @@ __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_subtract_domain( __isl_take isl_union_pw_multi_aff *upma, - __isl_take isl_set *set); + __isl_take isl_union_set *uset); #include __isl_give isl_pw_qpolynomial * @@ -6291,22 +7119,22 @@ isl_set_apply_pw_qpolynomial_fold( __isl_take isl_set *set, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight); + isl_bool *tight); __isl_give isl_pw_qpolynomial_fold * isl_map_apply_pw_qpolynomial_fold( __isl_take isl_map *map, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight); + isl_bool *tight); __isl_give isl_union_pw_qpolynomial_fold * isl_union_set_apply_union_pw_qpolynomial_fold( __isl_take isl_union_set *uset, __isl_take isl_union_pw_qpolynomial_fold *upwf, - int *tight); + isl_bool *tight); __isl_give isl_union_pw_qpolynomial_fold * isl_union_map_apply_union_pw_qpolynomial_fold( __isl_take isl_union_map *umap, __isl_take isl_union_pw_qpolynomial_fold *upwf, - int *tight); + isl_bool *tight); The functions taking a map compose the given map with the given piecewise quasipolynomial reduction. @@ -6672,6 +7500,11 @@ __isl_give isl_union_map *isl_union_map_product( __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); + + #include + __isl_give isl_multi_id *isl_multi_id_range_product( + __isl_take isl_multi_id *mi1, + __isl_take isl_multi_id *mi2); #include __isl_give isl_multi_val *isl_multi_val_range_product( @@ -6748,10 +7581,16 @@ __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); + #include + __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_give isl_multi_val *isl_multi_val_flat_range_product( __isl_take isl_multi_val *mv1, - __isl_take isl_multi_aff *mv2); + __isl_take isl_multi_val *mv2); #include __isl_give isl_multi_aff *isl_multi_aff_flat_range_product( @@ -6827,6 +7666,16 @@ isl_union_map_range_factor_range( __isl_take isl_union_map *umap); + #include + __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_give isl_multi_val *isl_multi_val_factor_range( __isl_take isl_multi_val *mv); @@ -6855,6 +7704,18 @@ __isl_give isl_multi_pw_aff * isl_multi_pw_aff_range_factor_range( __isl_take isl_multi_pw_aff *mpa); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_range_factor_domain( + __isl_take isl_pw_multi_aff *pma); + __isl_give isl_pw_multi_aff * + isl_pw_multi_aff_range_factor_range( + __isl_take isl_pw_multi_aff *pma); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_range_factor_domain( + __isl_take isl_union_pw_multi_aff *upma); + __isl_give isl_union_pw_multi_aff * + isl_union_pw_multi_aff_range_factor_range( + __isl_take isl_union_pw_multi_aff *upma); __isl_give isl_multi_union_pw_aff * isl_multi_union_pw_aff_factor_range( __isl_take isl_multi_union_pw_aff *mupa); @@ -6873,6 +7734,11 @@ C and C take functions that live in a set space. + + #include + __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_give isl_multi_val *isl_multi_val_range_splice( @@ -7256,10 +8122,10 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_val( __isl_take isl_pw_multi_aff *pma, __isl_take isl_val *v); - __isl_give isl_union_pw_multi_aff * __isl_give isl_union_pw_aff *isl_union_pw_aff_scale_val( __isl_take isl_union_pw_aff *upa, __isl_take isl_val *f); + __isl_give isl_union_pw_multi_aff * isl_union_pw_multi_aff_scale_val( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_val *val); @@ -7634,8 +8500,11 @@ =head2 Lists Lists are defined over several element types, including -C, C, C, C, C, -C, C, +C, C, C, C, C, +C, +C, +C, C, +C, C, C, C, C, C, C, C and C. Here we take lists of Cs as an example. @@ -7657,6 +8526,13 @@ __isl_give isl_set_list *isl_set_list_drop( __isl_take isl_set_list *list, unsigned first, unsigned n); + __isl_give isl_set_list *isl_set_list_clear( + __isl_take isl_set_list *list); + __isl_give isl_set_list *isl_set_list_swap( + __isl_take isl_set_list *list, + unsigned pos1, unsigned pos2); + __isl_give isl_set_list *isl_set_list_reverse( + __isl_take isl_set_list *list); __isl_give isl_set_list *isl_set_list_set_set( __isl_take isl_set_list *list, int index, __isl_take isl_set *set); @@ -7680,11 +8556,17 @@ for C elements. C and C add elements to a list, increasing its capacity as needed. C creates a list with a single element. +C removes all elements from a list. +C swaps the elements at the specified locations. +C reverses the elements in the list. Lists can be inspected using the following functions. #include - int isl_set_list_n_set(__isl_keep isl_set_list *list); + isl_size isl_set_list_size(__isl_keep isl_set_list *list); + isl_size isl_set_list_n_set(__isl_keep isl_set_list *list); + __isl_give isl_set *isl_set_list_get_at( + __isl_keep isl_set_list *list, int index); __isl_give isl_set *isl_set_list_get_set( __isl_keep isl_set_list *list, int index); isl_stat isl_set_list_foreach(__isl_keep isl_set_list *list, @@ -7698,6 +8580,9 @@ isl_stat (*fn)(__isl_take isl_set *el, void *user), void *fn_user); +C is an alternative name for C. +Similarly, +C is an alternative name for C. The function C calls C on each of the strongly connected components of the graph with as vertices the elements of C and a directed edge from vertex C to vertex C @@ -7709,6 +8594,14 @@ #include __isl_give isl_printer *isl_printer_print_set_list( __isl_take isl_printer *p, + __isl_keep isl_set_list *list); + +Alternatively, a string representation can be obtained +directly using the following function, which always prints +in isl format. + + #include + __isl_give char *isl_set_list_to_str( __isl_keep isl_set_list *list); =head2 Associative arrays @@ -7802,7 +8695,7 @@ A vector created by C has elements with value zero. The elements can be changed and inspected using the following functions. - int isl_vec_size(__isl_keep isl_vec *vec); + isl_size isl_vec_size(__isl_keep isl_vec *vec); __isl_give isl_val *isl_vec_get_element_val( __isl_keep isl_vec *vec, int pos); __isl_give isl_vec *isl_vec_set_element_si( @@ -7838,8 +8731,8 @@ Note that the elements of a newly created matrix may have arbitrary values. The elements can be changed and inspected using the following functions. - int isl_mat_rows(__isl_keep isl_mat *mat); - int isl_mat_cols(__isl_keep isl_mat *mat); + isl_size isl_mat_rows(__isl_keep isl_mat *mat); + isl_size isl_mat_cols(__isl_keep isl_mat *mat); __isl_give isl_val *isl_mat_get_element_val( __isl_keep isl_mat *mat, int row, int col); __isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat, @@ -7852,7 +8745,7 @@ The return value may be -1 if some error occurred. #include - int isl_mat_rank(__isl_keep isl_mat *mat); + isl_size isl_mat_rank(__isl_keep isl_mat *mat); The following function can be used to compute the (right) inverse of a matrix, i.e., a matrix such that the product of the original @@ -7898,12 +8791,12 @@ __isl_give isl_pw_qpolynomial_fold * isl_pw_qpolynomial_bound( __isl_take isl_pw_qpolynomial *pwqp, - enum isl_fold type, int *tight); + enum isl_fold type, isl_bool *tight); __isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_bound( __isl_take isl_union_pw_qpolynomial *upwqp, - enum isl_fold type, int *tight); + enum isl_fold type, isl_bool *tight); The C argument may be either C or C. If C is not C, then C<*tight> is set to C<1> @@ -7949,19 +8842,20 @@ Other operations that can be performed on an C object are the following. - int isl_vertices_get_n_vertices( + isl_size isl_vertices_get_n_vertices( __isl_keep isl_vertices *vertices); __isl_null isl_vertices *isl_vertices_free( __isl_take isl_vertices *vertices); Vertices can be inspected and destroyed using the following functions. - int isl_vertex_get_id(__isl_keep isl_vertex *vertex); + isl_size isl_vertex_get_id(__isl_keep isl_vertex *vertex); __isl_give isl_basic_set *isl_vertex_get_domain( __isl_keep isl_vertex *vertex); __isl_give isl_multi_aff *isl_vertex_get_expr( __isl_keep isl_vertex *vertex); - void isl_vertex_free(__isl_take isl_vertex *vertex); + __isl_null isl_vertex *isl_vertex_free( + __isl_take isl_vertex *vertex); C returns a multiple quasi-affine expression describing the vertex in terms of the parameters, @@ -7972,7 +8866,8 @@ __isl_give isl_basic_set *isl_cell_get_domain( __isl_keep isl_cell *cell); - void isl_cell_free(__isl_take isl_cell *cell); + __isl_null isl_cell *isl_cell_free( + __isl_take isl_cell *cell); =head1 Polyhedral Compilation Library @@ -8354,7 +9249,7 @@ __isl_give isl_schedule_node *isl_schedule_node_ancestor( __isl_take isl_schedule_node *node, int generation); - int isl_schedule_node_n_children( + isl_size isl_schedule_node_n_children( __isl_keep isl_schedule_node *node); __isl_give isl_schedule_node *isl_schedule_node_child( __isl_take isl_schedule_node *node, int pos); @@ -8387,11 +9282,11 @@ C. #include - int isl_schedule_node_get_tree_depth( + isl_size isl_schedule_node_get_tree_depth( __isl_keep isl_schedule_node *node); - int isl_schedule_node_get_child_position( + isl_size isl_schedule_node_get_child_position( __isl_keep isl_schedule_node *node); - int isl_schedule_node_get_ancestor_child_position( + isl_size isl_schedule_node_get_ancestor_child_position( __isl_keep isl_schedule_node *node, __isl_keep isl_schedule_node *ancestor); __isl_give isl_schedule_node *isl_schedule_node_get_child( @@ -8533,7 +9428,7 @@ __isl_give isl_union_map * isl_schedule_node_band_get_partial_schedule_union_map( __isl_keep isl_schedule_node *node); - unsigned isl_schedule_node_band_n_member( + isl_size isl_schedule_node_band_n_member( __isl_keep isl_schedule_node *node); isl_bool isl_schedule_node_band_member_get_coincident( __isl_keep isl_schedule_node *node, int pos); @@ -8553,7 +9448,6 @@ isl_schedule_node_band_member_set_ast_loop_type( __isl_take isl_schedule_node *node, int pos, enum isl_ast_loop_type type); - __isl_give isl_union_set * enum isl_ast_loop_type isl_schedule_node_band_member_get_isolate_ast_loop_type( __isl_keep isl_schedule_node *node, int pos); @@ -8561,6 +9455,7 @@ isl_schedule_node_band_member_set_isolate_ast_loop_type( __isl_take isl_schedule_node *node, int pos, enum isl_ast_loop_type type); + __isl_give isl_union_set * isl_schedule_node_band_get_ast_build_options( __isl_keep isl_schedule_node *node); __isl_give isl_schedule_node * @@ -8700,7 +9595,7 @@ using the following function. #include - int isl_schedule_node_get_schedule_depth( + isl_size isl_schedule_node_get_schedule_depth( __isl_keep isl_schedule_node *node); The following functions return the elements that reach the given node @@ -9170,7 +10065,8 @@ void *user); __isl_give isl_map *isl_flow_get_no_source( __isl_keep isl_flow *deps, int must); - void isl_flow_free(__isl_take isl_flow *deps); + __isl_null isl_flow *isl_flow_free( + __isl_take isl_flow *deps); The function C performs the actual dependence analysis. The other functions are used to construct @@ -9564,6 +10460,7 @@ and may also prevent fusing of unrelated dimensions. A value of -1 means that this option does not introduce bounds on the variable or parameter coefficients. +This option has no effect on the Feautrier style scheduler. =item * schedule_max_constant_term @@ -9754,14 +10651,28 @@ #include __isl_give isl_ast_expr *isl_ast_node_if_get_cond( + __isl_keep isl_ast_node *node); + __isl_give isl_ast_node *isl_ast_node_if_get_then_node( __isl_keep isl_ast_node *node); __isl_give isl_ast_node *isl_ast_node_if_get_then( __isl_keep isl_ast_node *node); + isl_bool isl_ast_node_if_has_else_node( + __isl_keep isl_ast_node *node); isl_bool isl_ast_node_if_has_else( + __isl_keep isl_ast_node *node); + __isl_give isl_ast_node *isl_ast_node_if_get_else_node( __isl_keep isl_ast_node *node); __isl_give isl_ast_node *isl_ast_node_if_get_else( __isl_keep isl_ast_node *node); +C, +C and +C +are alternative names for +C, +C and +C, respectively. + __isl_give isl_ast_node_list * isl_ast_node_block_get_children( __isl_keep isl_ast_node *node); @@ -9811,98 +10722,127 @@ Each type of expression has its own additional properties. #include - enum isl_ast_op_type isl_ast_expr_get_op_type( + enum isl_ast_expr_op_type isl_ast_expr_op_get_type( + __isl_keep isl_ast_expr *expr); + enum isl_ast_expr_op_type isl_ast_expr_get_op_type( __isl_keep isl_ast_expr *expr); - int isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr); + isl_size isl_ast_expr_op_get_n_arg(__isl_keep isl_ast_expr *expr); + isl_size isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr); + __isl_give isl_ast_expr *isl_ast_expr_op_get_arg( + __isl_keep isl_ast_expr *expr, int pos); __isl_give isl_ast_expr *isl_ast_expr_get_op_arg( __isl_keep isl_ast_expr *expr, int pos); + isl_stat isl_ast_expr_foreach_ast_expr_op_type( + __isl_keep isl_ast_expr *expr, + isl_stat (*fn)(enum isl_ast_expr_op_type type, + void *user), void *user); isl_stat isl_ast_expr_foreach_ast_op_type( __isl_keep isl_ast_expr *expr, - isl_stat (*fn)(enum isl_ast_op_type type, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); + isl_stat isl_ast_node_foreach_ast_expr_op_type( + __isl_keep isl_ast_node *node, + isl_stat (*fn)(enum isl_ast_expr_op_type type, + void *user), void *user); isl_stat isl_ast_node_foreach_ast_op_type( __isl_keep isl_ast_node *node, - isl_stat (*fn)(enum isl_ast_op_type type, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); -C returns the type of the operation -performed. C returns the number of +C returns the type of the operation +performed. C returns the number of arguments. C returns the specified argument. -C calls C for each distinct -C that appears in C. -C does the same for each distinct -C that appears in C. +C is an alternative name for +C. +Similarly, +C is an alternative name for +C and +C is an alternative name for +C. + +C calls C for each distinct +C that appears in C. +C is an alternative name for +C. +C does the same for each distinct +C that appears in C. +C is an alternative name for +C. The operation type is one of the following. =over -=item C +=item C Logical I of two arguments. Both arguments can be evaluated. -=item C +=item C Logical I of two arguments. The second argument can only be evaluated if the first evaluates to true. -=item C +=item C Logical I of two arguments. Both arguments can be evaluated. -=item C +=item C Logical I of two arguments. The second argument can only be evaluated if the first evaluates to false. -=item C +=item C Maximum of two or more arguments. -=item C +=item C Minimum of two or more arguments. -=item C +=item C Change sign. -=item C +=item C Sum of two arguments. -=item C +=item C Difference of two arguments. -=item C +=item C Product of two arguments. -=item C +=item C Exact division. That is, the result is known to be an integer. -=item C +=item C Result of integer division, rounded towards negative infinity. +The divisor is known to be positive. -=item C +=item C Result of integer division, where dividend is known to be non-negative. +The divisor is known to be positive. -=item C +=item C Remainder of integer division, where dividend is known to be non-negative. +The divisor is known to be positive. -=item C +=item C Equal to zero iff the remainder on integer division is zero. +The divisor is known to be positive. -=item C +=item C Conditional operator defined on three arguments. If the first argument evaluates to true, then the result @@ -9912,7 +10852,7 @@ the first argument evaluates to true and false, respectively. Corresponds to C in C. -=item C +=item C Conditional operator defined on three arguments. If the first argument evaluates to true, then the result @@ -9922,41 +10862,41 @@ of the value of the first argument. Corresponds to C in C. -=item C +=item C Equality relation. -=item C +=item C Less than or equal relation. -=item C +=item C Less than relation. -=item C +=item C Greater than or equal relation. -=item C +=item C Greater than relation. -=item C +=item C A function call. The number of arguments of the C is one more than the number of arguments in the function call, the first argument representing the function being called. -=item C +=item C An array access. The number of arguments of the C is one more than the number of index expressions in the array access, the first argument representing the array being accessed. -=item C +=item C A member access. This operation has two arguments, a structure and the name of @@ -9965,16 +10905,24 @@ =back #include + __isl_give isl_id *isl_ast_expr_id_get_id( + __isl_keep isl_ast_expr *expr); __isl_give isl_id *isl_ast_expr_get_id( __isl_keep isl_ast_expr *expr); Return the identifier represented by the AST expression. +C is an alternative name for +C. #include + __isl_give isl_val *isl_ast_expr_int_get_val( + __isl_keep isl_ast_expr *expr); __isl_give isl_val *isl_ast_expr_get_val( __isl_keep isl_ast_expr *expr); Return the integer represented by the AST expression. +C is an alternative name for +C. =head3 Properties of ASTs @@ -10068,8 +11016,11 @@ __isl_take isl_ast_expr_list *arguments); The function C can be applied to an -C of type C only. It is meant -to represent the address of the C. The function +C of type C only. It is meant +to represent the address of the C. +The second argument of the functions C and +C should always evaluate to a positive number. +The function C as well as C are short-circuit versions of C and C, respectively. @@ -10097,7 +11048,7 @@ __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa); -The set and +The set C and the domains of C, C and C should correspond to the schedule space of C. The tuple id of C or C is used as the array being accessed or @@ -10161,15 +11112,23 @@ More advanced printing can be performed using the following functions. #include + __isl_give isl_printer * + isl_ast_expr_op_type_set_print_name( + __isl_take isl_printer *p, + enum isl_ast_expr_op_type type, + __isl_keep const char *name); __isl_give isl_printer *isl_ast_op_type_set_print_name( __isl_take isl_printer *p, - enum isl_ast_op_type type, + enum isl_ast_expr_op_type type, __isl_keep const char *name); isl_stat isl_options_set_ast_print_macro_once( isl_ctx *ctx, int val); int isl_options_get_ast_print_macro_once(isl_ctx *ctx); + __isl_give isl_printer *isl_ast_expr_op_type_print_macro( + enum isl_ast_expr_op_type type, + __isl_take isl_printer *p); __isl_give isl_printer *isl_ast_op_type_print_macro( - enum isl_ast_op_type type, + enum isl_ast_expr_op_type type, __isl_take isl_printer *p); __isl_give isl_printer *isl_ast_expr_print_macros( __isl_keep isl_ast_expr *expr, @@ -10194,17 +11153,22 @@ C may print out an AST that makes use of macros such as C, C and C. The names of these macros may be modified by a call -to C. The user-specified +to C. The user-specified names are associated to the printer object. -C prints out the macro -corresponding to a specific C. +C is an alternative name for +C. +C prints out the macro +corresponding to a specific C. If the print-macro-once option is set, then a given macro definition is only printed once to any given printer object. +C is an alternative name for +C. C scans the C for subexpressions where these macros would be used and prints out the required macro definitions. Essentially, C calls -C with C +C with +C as function argument. C does the same for expressions in its C argument. @@ -10293,6 +11257,10 @@ isl_stat isl_options_set_ast_build_group_coscheduled( isl_ctx *ctx, int val); int isl_options_get_ast_build_group_coscheduled( + isl_ctx *ctx); + isl_stat isl_options_set_ast_build_separation_bounds( + isl_ctx *ctx, int val); + int isl_options_get_ast_build_separation_bounds( isl_ctx *ctx); isl_stat isl_options_set_ast_build_scale_strides( isl_ctx *ctx, int val); @@ -10331,12 +11299,12 @@ =item * ast_build_prefer_pdiv If this option is turned off, then the AST generation will -produce ASTs that may only contain C -operators, but no C or -C operators. +produce ASTs that may only contain C +operators, but no C or +C operators. If this option is turned on, then C will try to convert -some of the C operators to (expressions containing) -C or C operators. +some of the C operators to (expressions containing) +C or C operators. =item * ast_build_detect_min_max @@ -10651,7 +11619,8 @@ The range of the options can consist of elements in one or more spaces, the names of which determine the effect of the option. The values of the range typically also refer to the schedule dimension -to which the option applies. In case of nested AST generation +to which the option applies, with value C<0> representing +the outermost schedule dimension. In case of nested AST generation (see L), these values refer to the position of the schedule dimension within the innermost AST generation. The constraints on the domain elements of diff --git a/gcc/isl/interface/Makefile.am b/gcc/isl/interface/Makefile.am index b61709a..b0cfb38 100644 --- a/gcc/isl/interface/Makefile.am +++ a/gcc/isl/interface/Makefile.am @@ -1,16 +1,6 @@ AUTOMAKE_OPTIONS = nostdinc noinst_PROGRAMS = extract_interface -TESTS = -if HAVE_PYTHON - TESTS += isl_test_python.py - isl_test_python.py: isl.py -endif -TEST_EXTENSIONS = .py -AM_TESTS_ENVIRONMENT = \ - export PYTHONPATH=.; \ - export LD_LIBRARY_PATH=../.libs; -PY_LOG_COMPILER = $(PYTHON) includes = -I$(top_builddir) -I$(top_srcdir) \ -I$(top_builddir)/include -I$(top_srcdir)/include @@ -22,28 +12,15 @@ generator.cc \ python.h \ python.cc \ + cpp.h \ + cpp.cc \ + cpp_conversion.h \ + cpp_conversion.cc \ extract_interface.h \ extract_interface.cc -extract_interface_LDFLAGS = $(CLANG_LDFLAGS) +extract_interface_LDFLAGS = $(CLANG_LDFLAGS) $(CLANG_RFLAG) extract_interface_LDADD = \ -lclangFrontend -lclangSerialization -lclangParse -lclangSema \ $(LIB_CLANG_EDIT) \ -lclangAnalysis -lclangAST -lclangLex -lclangBasic -lclangDriver \ $(CLANG_LIBS) $(CLANG_LDFLAGS) - -CLEANFILES = isl.py - -# dummy library that captures the dependencies on all headers -# that are relevant for the bindings -noinst_LIBRARIES = libdep.a -libdep_a_CPPFLAGS = $(includes) -libdep_a_SOURCES = all.c - -isl.py: extract_interface libdep.a isl.py.top - (cat $(srcdir)/isl.py.top; \ - ./extract_interface$(EXEEXT) --language=python $(includes) \ - $(srcdir)/all.h) \ - > isl.py - -dist-hook: isl.py - cp isl.py $(distdir)/ diff --git a/gcc/isl/interface/Makefile.in b/gcc/isl/interface/Makefile.in index 3702879..91fb252 100644 --- a/gcc/isl/interface/Makefile.in +++ a/gcc/isl/interface/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2014 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -14,7 +14,6 @@ @SET_MAKE@ - VPATH = @srcdir@ am__is_gnu_make = { \ if test -z '$(MAKELEVEL)'; then \ @@ -90,7 +89,6 @@ build_triplet = @build@ host_triplet = @host@ noinst_PROGRAMS = extract_interface$(EXEEXT) -@HAVE_PYTHON_TRUE@am__append_1 = isl_test_python.py subdir = interface ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_c___attribute__.m4 \ @@ -99,6 +97,8 @@ $(top_srcdir)/m4/ax_compiler_vendor.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_create_stdint_h.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx.m4 \ + $(top_srcdir)/m4/ax_cxx_compile_stdcxx_11.m4 \ $(top_srcdir)/m4/ax_detect_clang.m4 \ $(top_srcdir)/m4/ax_detect_git_head.m4 \ $(top_srcdir)/m4/ax_detect_gmp.m4 \ @@ -118,19 +118,11 @@ CONFIG_HEADER = $(top_builddir)/isl_config.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = -LIBRARIES = $(noinst_LIBRARIES) -ARFLAGS = cru -AM_V_AR = $(am__v_AR_@AM_V@) -am__v_AR_ = $(am__v_AR_@AM_DEFAULT_V@) -am__v_AR_0 = @echo " AR " $@; -am__v_AR_1 = -libdep_a_AR = $(AR) $(ARFLAGS) -libdep_a_LIBADD = -am_libdep_a_OBJECTS = libdep_a-all.$(OBJEXT) -libdep_a_OBJECTS = $(am_libdep_a_OBJECTS) PROGRAMS = $(noinst_PROGRAMS) am_extract_interface_OBJECTS = extract_interface-generator.$(OBJEXT) \ extract_interface-python.$(OBJEXT) \ + extract_interface-cpp.$(OBJEXT) \ + extract_interface-cpp_conversion.$(OBJEXT) \ extract_interface-extract_interface.$(OBJEXT) extract_interface_OBJECTS = $(am_extract_interface_OBJECTS) am__DEPENDENCIES_1 = @@ -160,24 +152,6 @@ depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles am__mv = mv -f -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_@AM_V@) -am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) -am__v_CC_0 = @echo " CC " $@; -am__v_CC_1 = -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_@AM_V@) -am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) -am__v_CCLD_0 = @echo " CCLD " $@; -am__v_CCLD_1 = CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ @@ -196,8 +170,26 @@ am__v_CXXLD_ = $(am__v_CXXLD_@AM_DEFAULT_V@) am__v_CXXLD_0 = @echo " CXXLD " $@; am__v_CXXLD_1 = -SOURCES = $(libdep_a_SOURCES) $(extract_interface_SOURCES) -DIST_SOURCES = $(libdep_a_SOURCES) $(extract_interface_SOURCES) +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_@AM_V@) +am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_@AM_V@) +am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(extract_interface_SOURCES) +DIST_SOURCES = $(extract_interface_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -222,208 +214,7 @@ done | $(am__uniquify_input)` ETAGS = etags CTAGS = ctags -am__tty_colors_dummy = \ - mgn= red= grn= lgn= blu= brg= std=; \ - am__color_tests=no -am__tty_colors = { \ - $(am__tty_colors_dummy); \ - if test "X$(AM_COLOR_TESTS)" = Xno; then \ - am__color_tests=no; \ - elif test "X$(AM_COLOR_TESTS)" = Xalways; then \ - am__color_tests=yes; \ - elif test "X$$TERM" != Xdumb && { test -t 1; } 2>/dev/null; then \ - am__color_tests=yes; \ - fi; \ - if test $$am__color_tests = yes; then \ - red=''; \ - grn=''; \ - lgn=''; \ - blu=''; \ - mgn=''; \ - brg=''; \ - std=''; \ - fi; \ -} -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__uninstall_files_from_dir = { \ - test -z "$$files" \ - || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ - || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ - $(am__cd) "$$dir" && rm -f $$files; }; \ - } -am__recheck_rx = ^[ ]*:recheck:[ ]* -am__global_test_result_rx = ^[ ]*:global-test-result:[ ]* -am__copy_in_global_log_rx = ^[ ]*:copy-in-global-log:[ ]* -# A command that, given a newline-separated list of test names on the -# standard input, print the name of the tests that are to be re-run -# upon "make recheck". -am__list_recheck_tests = $(AWK) '{ \ - recheck = 1; \ - while ((rc = (getline line < ($$0 ".trs"))) != 0) \ - { \ - if (rc < 0) \ - { \ - if ((getline line2 < ($$0 ".log")) < 0) \ - recheck = 0; \ - break; \ - } \ - else if (line ~ /$(am__recheck_rx)[nN][Oo]/) \ - { \ - recheck = 0; \ - break; \ - } \ - else if (line ~ /$(am__recheck_rx)[yY][eE][sS]/) \ - { \ - break; \ - } \ - }; \ - if (recheck) \ - print $$0; \ - close ($$0 ".trs"); \ - close ($$0 ".log"); \ -}' -# A command that, given a newline-separated list of test names on the -# standard input, create the global log from their .trs and .log files. -am__create_global_log = $(AWK) ' \ -function fatal(msg) \ -{ \ - print "fatal: making $@: " msg | "cat >&2"; \ - exit 1; \ -} \ -function rst_section(header) \ -{ \ - print header; \ - len = length(header); \ - for (i = 1; i <= len; i = i + 1) \ - printf "="; \ - printf "\n\n"; \ -} \ -{ \ - copy_in_global_log = 1; \ - global_test_result = "RUN"; \ - while ((rc = (getline line < ($$0 ".trs"))) != 0) \ - { \ - if (rc < 0) \ - fatal("failed to read from " $$0 ".trs"); \ - if (line ~ /$(am__global_test_result_rx)/) \ - { \ - sub("$(am__global_test_result_rx)", "", line); \ - sub("[ ]*$$", "", line); \ - global_test_result = line; \ - } \ - else if (line ~ /$(am__copy_in_global_log_rx)[nN][oO]/) \ - copy_in_global_log = 0; \ - }; \ - if (copy_in_global_log) \ - { \ - rst_section(global_test_result ": " $$0); \ - while ((rc = (getline line < ($$0 ".log"))) != 0) \ - { \ - if (rc < 0) \ - fatal("failed to read from " $$0 ".log"); \ - print line; \ - }; \ - printf "\n"; \ - }; \ - close ($$0 ".trs"); \ - close ($$0 ".log"); \ -}' -# Restructured Text title. -am__rst_title = { sed 's/.*/ & /;h;s/./=/g;p;x;s/ *$$//;p;g' && echo; } -# Solaris 10 'make', and several other traditional 'make' implementations, -# pass "-e" to $(SHELL), and POSIX 2008 even requires this. Work around it -# by disabling -e (using the XSI extension "set +e") if it's set. -am__sh_e_setup = case $$- in *e*) set +e;; esac -# Default flags passed to test drivers. -am__common_driver_flags = \ - --color-tests "$$am__color_tests" \ - --enable-hard-errors "$$am__enable_hard_errors" \ - --expect-failure "$$am__expect_failure" -# To be inserted before the command running the test. Creates the -# directory for the log if needed. Stores in $dir the directory -# containing $f, in $tst the test, in $log the log. Executes the -# developer- defined test setup AM_TESTS_ENVIRONMENT (if any), and -# passes TESTS_ENVIRONMENT. Set up options for the wrapper that -# will run the test scripts (or their associated LOG_COMPILER, if -# thy have one). -am__check_pre = \ -$(am__sh_e_setup); \ -$(am__vpath_adj_setup) $(am__vpath_adj) \ -$(am__tty_colors); \ -srcdir=$(srcdir); export srcdir; \ -case "$@" in \ - */*) am__odir=`echo "./$@" | sed 's|/[^/]*$$||'`;; \ - *) am__odir=.;; \ -esac; \ -test "x$$am__odir" = x"." || test -d "$$am__odir" \ - || $(MKDIR_P) "$$am__odir" || exit $$?; \ -if test -f "./$$f"; then dir=./; \ -elif test -f "$$f"; then dir=; \ -else dir="$(srcdir)/"; fi; \ -tst=$$dir$$f; log='$@'; \ -if test -n '$(DISABLE_HARD_ERRORS)'; then \ - am__enable_hard_errors=no; \ -else \ - am__enable_hard_errors=yes; \ -fi; \ -case " $(XFAIL_TESTS) " in \ - *[\ \ ]$$f[\ \ ]* | *[\ \ ]$$dir$$f[\ \ ]*) \ - am__expect_failure=yes;; \ - *) \ - am__expect_failure=no;; \ -esac; \ -$(AM_TESTS_ENVIRONMENT) $(TESTS_ENVIRONMENT) -# A shell command to get the names of the tests scripts with any registered -# extension removed (i.e., equivalently, the names of the test logs, with -# the '.log' extension removed). The result is saved in the shell variable -# '$bases'. This honors runtime overriding of TESTS and TEST_LOGS. Sadly, -# we cannot use something simpler, involving e.g., "$(TEST_LOGS:.log=)", -# since that might cause problem with VPATH rewrites for suffix-less tests. -# See also 'test-harness-vpath-rewrite.sh' and 'test-trs-basic.sh'. -am__set_TESTS_bases = \ - bases='$(TEST_LOGS)'; \ - bases=`for i in $$bases; do echo $$i; done | sed 's/\.log$$//'`; \ - bases=`echo $$bases` -RECHECK_LOGS = $(TEST_LOGS) -AM_RECURSIVE_TARGETS = check recheck -TEST_SUITE_LOG = test-suite.log -am__test_logs1 = $(TESTS:=.log) -am__test_logs2 = $(am__test_logs1:@EXEEXT@.log=.log) -TEST_LOGS = $(am__test_logs2:.py.log=.log) -PY_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver -PY_LOG_COMPILE = $(PY_LOG_COMPILER) $(AM_PY_LOG_FLAGS) $(PY_LOG_FLAGS) -am__set_b = \ - case '$@' in \ - */*) \ - case '$*' in \ - */*) b='$*';; \ - *) b=`echo '$@' | sed 's/\.log$$//'`; \ - esac;; \ - *) \ - b='$*';; \ - esac -am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \ - $(top_srcdir)/test-driver +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) ACLOCAL = @ACLOCAL@ AMTAR = @AMTAR@ @@ -439,12 +230,14 @@ CLANG_CXXFLAGS = @CLANG_CXXFLAGS@ CLANG_LDFLAGS = @CLANG_LDFLAGS@ CLANG_LIBS = @CLANG_LIBS@ +CLANG_RFLAG = @CLANG_RFLAG@ CPP = @CPP@ CPPFLAGS = @CPPFLAGS@ CXX = @CXX@ CXXCPP = @CXXCPP@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ +CYGPATH = @CYGPATH@ CYGPATH_W = @CYGPATH_W@ DEFS = @DEFS@ DEPDIR = @DEPDIR@ @@ -461,6 +254,7 @@ GIT_HEAD_ID = @GIT_HEAD_ID@ GIT_HEAD_VERSION = @GIT_HEAD_VERSION@ GREP = @GREP@ +HAVE_CXX11 = @HAVE_CXX11@ INSTALL = @INSTALL@ INSTALL_DATA = @INSTALL_DATA@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ @@ -479,6 +273,7 @@ MAKEINFO = @MAKEINFO@ MANIFEST_TOOL = @MANIFEST_TOOL@ MKDIR_P = @MKDIR_P@ +MP_CFLAGS = @MP_CFLAGS@ MP_CPPFLAGS = @MP_CPPFLAGS@ MP_LDFLAGS = @MP_LDFLAGS@ MP_LIBS = @MP_LIBS@ @@ -486,6 +281,7 @@ NMEDIT = @NMEDIT@ OBJDUMP = @OBJDUMP@ OBJEXT = @OBJEXT@ +OS_SRCDIR = @OS_SRCDIR@ OTOOL = @OTOOL@ OTOOL64 = @OTOOL64@ PACKAGE = @PACKAGE@ @@ -575,13 +371,6 @@ top_srcdir = @top_srcdir@ versioninfo = @versioninfo@ AUTOMAKE_OPTIONS = nostdinc -TESTS = $(am__append_1) -TEST_EXTENSIONS = .py -AM_TESTS_ENVIRONMENT = \ - export PYTHONPATH=.; \ - export LD_LIBRARY_PATH=../.libs; - -PY_LOG_COMPILER = $(PYTHON) includes = -I$(top_builddir) -I$(top_srcdir) \ -I$(top_builddir)/include -I$(top_srcdir)/include @@ -592,27 +381,24 @@ generator.cc \ python.h \ python.cc \ + cpp.h \ + cpp.cc \ + cpp_conversion.h \ + cpp_conversion.cc \ extract_interface.h \ extract_interface.cc -extract_interface_LDFLAGS = $(CLANG_LDFLAGS) +extract_interface_LDFLAGS = $(CLANG_LDFLAGS) $(CLANG_RFLAG) extract_interface_LDADD = \ -lclangFrontend -lclangSerialization -lclangParse -lclangSema \ $(LIB_CLANG_EDIT) \ -lclangAnalysis -lclangAST -lclangLex -lclangBasic -lclangDriver \ $(CLANG_LIBS) $(CLANG_LDFLAGS) - -CLEANFILES = isl.py -# dummy library that captures the dependencies on all headers -# that are relevant for the bindings -noinst_LIBRARIES = libdep.a -libdep_a_CPPFLAGS = $(includes) -libdep_a_SOURCES = all.c all: all-am .SUFFIXES: -.SUFFIXES: .c .cc .lo .log .o .obj .py .py$(EXEEXT) .trs +.SUFFIXES: .cc .lo .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -643,14 +429,6 @@ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh $(am__aclocal_m4_deps): -clean-noinstLIBRARIES: - -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) - -libdep.a: $(libdep_a_OBJECTS) $(libdep_a_DEPENDENCIES) $(EXTRA_libdep_a_DEPENDENCIES) - $(AM_V_at)-rm -f libdep.a - $(AM_V_AR)$(libdep_a_AR) libdep.a $(libdep_a_OBJECTS) $(libdep_a_LIBADD) - $(AM_V_at)$(RANLIB) libdep.a - clean-noinstPROGRAMS: @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ echo " rm -f" $$list; \ @@ -670,45 +448,11 @@ distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract_interface-cpp.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract_interface-cpp_conversion.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract_interface-extract_interface.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract_interface-generator.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract_interface-python.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libdep_a-all.Po@am__quote@ - -.c.o: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $< - -.c.obj: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.c.lo: -@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $< - -libdep_a-all.o: all.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdep_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libdep_a-all.o -MD -MP -MF $(DEPDIR)/libdep_a-all.Tpo -c -o libdep_a-all.o `test -f 'all.c' || echo '$(srcdir)/'`all.c -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdep_a-all.Tpo $(DEPDIR)/libdep_a-all.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='all.c' object='libdep_a-all.o' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdep_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libdep_a-all.o `test -f 'all.c' || echo '$(srcdir)/'`all.c - -libdep_a-all.obj: all.c -@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdep_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT libdep_a-all.obj -MD -MP -MF $(DEPDIR)/libdep_a-all.Tpo -c -o libdep_a-all.obj `if test -f 'all.c'; then $(CYGPATH_W) 'all.c'; else $(CYGPATH_W) '$(srcdir)/all.c'; fi` -@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libdep_a-all.Tpo $(DEPDIR)/libdep_a-all.Po -@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='all.c' object='libdep_a-all.obj' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libdep_a_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o libdep_a-all.obj `if test -f 'all.c'; then $(CYGPATH_W) 'all.c'; else $(CYGPATH_W) '$(srcdir)/all.c'; fi` .cc.o: @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< @@ -758,6 +502,34 @@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='python.cc' object='extract_interface-python.obj' libtool=no @AMDEPBACKSLASH@ @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -c -o extract_interface-python.obj `if test -f 'python.cc'; then $(CYGPATH_W) 'python.cc'; else $(CYGPATH_W) '$(srcdir)/python.cc'; fi` + +extract_interface-cpp.o: cpp.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -MT extract_interface-cpp.o -MD -MP -MF $(DEPDIR)/extract_interface-cpp.Tpo -c -o extract_interface-cpp.o `test -f 'cpp.cc' || echo '$(srcdir)/'`cpp.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/extract_interface-cpp.Tpo $(DEPDIR)/extract_interface-cpp.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='cpp.cc' object='extract_interface-cpp.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -c -o extract_interface-cpp.o `test -f 'cpp.cc' || echo '$(srcdir)/'`cpp.cc + +extract_interface-cpp.obj: cpp.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -MT extract_interface-cpp.obj -MD -MP -MF $(DEPDIR)/extract_interface-cpp.Tpo -c -o extract_interface-cpp.obj `if test -f 'cpp.cc'; then $(CYGPATH_W) 'cpp.cc'; else $(CYGPATH_W) '$(srcdir)/cpp.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/extract_interface-cpp.Tpo $(DEPDIR)/extract_interface-cpp.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='cpp.cc' object='extract_interface-cpp.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -c -o extract_interface-cpp.obj `if test -f 'cpp.cc'; then $(CYGPATH_W) 'cpp.cc'; else $(CYGPATH_W) '$(srcdir)/cpp.cc'; fi` + +extract_interface-cpp_conversion.o: cpp_conversion.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -MT extract_interface-cpp_conversion.o -MD -MP -MF $(DEPDIR)/extract_interface-cpp_conversion.Tpo -c -o extract_interface-cpp_conversion.o `test -f 'cpp_conversion.cc' || echo '$(srcdir)/'`cpp_conversion.cc +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/extract_interface-cpp_conversion.Tpo $(DEPDIR)/extract_interface-cpp_conversion.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='cpp_conversion.cc' object='extract_interface-cpp_conversion.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -c -o extract_interface-cpp_conversion.o `test -f 'cpp_conversion.cc' || echo '$(srcdir)/'`cpp_conversion.cc + +extract_interface-cpp_conversion.obj: cpp_conversion.cc +@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -MT extract_interface-cpp_conversion.obj -MD -MP -MF $(DEPDIR)/extract_interface-cpp_conversion.Tpo -c -o extract_interface-cpp_conversion.obj `if test -f 'cpp_conversion.cc'; then $(CYGPATH_W) 'cpp_conversion.cc'; else $(CYGPATH_W) '$(srcdir)/cpp_conversion.cc'; fi` +@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/extract_interface-cpp_conversion.Tpo $(DEPDIR)/extract_interface-cpp_conversion.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='cpp_conversion.cc' object='extract_interface-cpp_conversion.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -c -o extract_interface-cpp_conversion.obj `if test -f 'cpp_conversion.cc'; then $(CYGPATH_W) 'cpp_conversion.cc'; else $(CYGPATH_W) '$(srcdir)/cpp_conversion.cc'; fi` extract_interface-extract_interface.o: extract_interface.cc @am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(extract_interface_CPPFLAGS) $(CPPFLAGS) $(extract_interface_CXXFLAGS) $(CXXFLAGS) -MT extract_interface-extract_interface.o -MD -MP -MF $(DEPDIR)/extract_interface-extract_interface.Tpo -c -o extract_interface-extract_interface.o `test -f 'extract_interface.cc' || echo '$(srcdir)/'`extract_interface.cc @@ -831,162 +603,6 @@ distclean-tags: -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags -# Recover from deleted '.trs' file; this should ensure that -# "rm -f foo.log; make foo.trs" re-run 'foo.test', and re-create -# both 'foo.log' and 'foo.trs'. Break the recipe in two subshells -# to avoid problems with "make -n". -.log.trs: - rm -f $< $@ - $(MAKE) $(AM_MAKEFLAGS) $< - -# Leading 'am--fnord' is there to ensure the list of targets does not -# expand to empty, as could happen e.g. with make check TESTS=''. -am--fnord $(TEST_LOGS) $(TEST_LOGS:.log=.trs): $(am__force_recheck) -am--force-recheck: - @: - -$(TEST_SUITE_LOG): $(TEST_LOGS) - @$(am__set_TESTS_bases); \ - am__f_ok () { test -f "$$1" && test -r "$$1"; }; \ - redo_bases=`for i in $$bases; do \ - am__f_ok $$i.trs && am__f_ok $$i.log || echo $$i; \ - done`; \ - if test -n "$$redo_bases"; then \ - redo_logs=`for i in $$redo_bases; do echo $$i.log; done`; \ - redo_results=`for i in $$redo_bases; do echo $$i.trs; done`; \ - if $(am__make_dryrun); then :; else \ - rm -f $$redo_logs && rm -f $$redo_results || exit 1; \ - fi; \ - fi; \ - if test -n "$$am__remaking_logs"; then \ - echo "fatal: making $(TEST_SUITE_LOG): possible infinite" \ - "recursion detected" >&2; \ - elif test -n "$$redo_logs"; then \ - am__remaking_logs=yes $(MAKE) $(AM_MAKEFLAGS) $$redo_logs; \ - fi; \ - if $(am__make_dryrun); then :; else \ - st=0; \ - errmsg="fatal: making $(TEST_SUITE_LOG): failed to create"; \ - for i in $$redo_bases; do \ - test -f $$i.trs && test -r $$i.trs \ - || { echo "$$errmsg $$i.trs" >&2; st=1; }; \ - test -f $$i.log && test -r $$i.log \ - || { echo "$$errmsg $$i.log" >&2; st=1; }; \ - done; \ - test $$st -eq 0 || exit 1; \ - fi - @$(am__sh_e_setup); $(am__tty_colors); $(am__set_TESTS_bases); \ - ws='[ ]'; \ - results=`for b in $$bases; do echo $$b.trs; done`; \ - test -n "$$results" || results=/dev/null; \ - all=` grep "^$$ws*:test-result:" $$results | wc -l`; \ - pass=` grep "^$$ws*:test-result:$$ws*PASS" $$results | wc -l`; \ - fail=` grep "^$$ws*:test-result:$$ws*FAIL" $$results | wc -l`; \ - skip=` grep "^$$ws*:test-result:$$ws*SKIP" $$results | wc -l`; \ - xfail=`grep "^$$ws*:test-result:$$ws*XFAIL" $$results | wc -l`; \ - xpass=`grep "^$$ws*:test-result:$$ws*XPASS" $$results | wc -l`; \ - error=`grep "^$$ws*:test-result:$$ws*ERROR" $$results | wc -l`; \ - if test `expr $$fail + $$xpass + $$error` -eq 0; then \ - success=true; \ - else \ - success=false; \ - fi; \ - br='==================='; br=$$br$$br$$br$$br; \ - result_count () \ - { \ - if test x"$$1" = x"--maybe-color"; then \ - maybe_colorize=yes; \ - elif test x"$$1" = x"--no-color"; then \ - maybe_colorize=no; \ - else \ - echo "$@: invalid 'result_count' usage" >&2; exit 4; \ - fi; \ - shift; \ - desc=$$1 count=$$2; \ - if test $$maybe_colorize = yes && test $$count -gt 0; then \ - color_start=$$3 color_end=$$std; \ - else \ - color_start= color_end=; \ - fi; \ - echo "$${color_start}# $$desc $$count$${color_end}"; \ - }; \ - create_testsuite_report () \ - { \ - result_count $$1 "TOTAL:" $$all "$$brg"; \ - result_count $$1 "PASS: " $$pass "$$grn"; \ - result_count $$1 "SKIP: " $$skip "$$blu"; \ - result_count $$1 "XFAIL:" $$xfail "$$lgn"; \ - result_count $$1 "FAIL: " $$fail "$$red"; \ - result_count $$1 "XPASS:" $$xpass "$$red"; \ - result_count $$1 "ERROR:" $$error "$$mgn"; \ - }; \ - { \ - echo "$(PACKAGE_STRING): $(subdir)/$(TEST_SUITE_LOG)" | \ - $(am__rst_title); \ - create_testsuite_report --no-color; \ - echo; \ - echo ".. contents:: :depth: 2"; \ - echo; \ - for b in $$bases; do echo $$b; done \ - | $(am__create_global_log); \ - } >$(TEST_SUITE_LOG).tmp || exit 1; \ - mv $(TEST_SUITE_LOG).tmp $(TEST_SUITE_LOG); \ - if $$success; then \ - col="$$grn"; \ - else \ - col="$$red"; \ - test x"$$VERBOSE" = x || cat $(TEST_SUITE_LOG); \ - fi; \ - echo "$${col}$$br$${std}"; \ - echo "$${col}Testsuite summary for $(PACKAGE_STRING)$${std}"; \ - echo "$${col}$$br$${std}"; \ - create_testsuite_report --maybe-color; \ - echo "$$col$$br$$std"; \ - if $$success; then :; else \ - echo "$${col}See $(subdir)/$(TEST_SUITE_LOG)$${std}"; \ - if test -n "$(PACKAGE_BUGREPORT)"; then \ - echo "$${col}Please report to $(PACKAGE_BUGREPORT)$${std}"; \ - fi; \ - echo "$$col$$br$$std"; \ - fi; \ - $$success || exit 1 - -check-TESTS: - @list='$(RECHECK_LOGS)'; test -z "$$list" || rm -f $$list - @list='$(RECHECK_LOGS:.log=.trs)'; test -z "$$list" || rm -f $$list - @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) - @set +e; $(am__set_TESTS_bases); \ - log_list=`for i in $$bases; do echo $$i.log; done`; \ - trs_list=`for i in $$bases; do echo $$i.trs; done`; \ - log_list=`echo $$log_list`; trs_list=`echo $$trs_list`; \ - $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$log_list"; \ - exit $$?; -recheck: all - @test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) - @set +e; $(am__set_TESTS_bases); \ - bases=`for i in $$bases; do echo $$i; done \ - | $(am__list_recheck_tests)` || exit 1; \ - log_list=`for i in $$bases; do echo $$i.log; done`; \ - log_list=`echo $$log_list`; \ - $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) \ - am__force_recheck=am--force-recheck \ - TEST_LOGS="$$log_list"; \ - exit $$? -.py.log: - @p='$<'; \ - $(am__set_b); \ - $(am__check_pre) $(PY_LOG_DRIVER) --test-name "$$f" \ - --log-file $$b.log --trs-file $$b.trs \ - $(am__common_driver_flags) $(AM_PY_LOG_DRIVER_FLAGS) $(PY_LOG_DRIVER_FLAGS) -- $(PY_LOG_COMPILE) \ - "$$tst" $(AM_TESTS_FD_REDIRECT) -@am__EXEEXT_TRUE@.py$(EXEEXT).log: -@am__EXEEXT_TRUE@ @p='$<'; \ -@am__EXEEXT_TRUE@ $(am__set_b); \ -@am__EXEEXT_TRUE@ $(am__check_pre) $(PY_LOG_DRIVER) --test-name "$$f" \ -@am__EXEEXT_TRUE@ --log-file $$b.log --trs-file $$b.trs \ -@am__EXEEXT_TRUE@ $(am__common_driver_flags) $(AM_PY_LOG_DRIVER_FLAGS) $(PY_LOG_DRIVER_FLAGS) -- $(PY_LOG_COMPILE) \ -@am__EXEEXT_TRUE@ "$$tst" $(AM_TESTS_FD_REDIRECT) - distdir: $(DISTFILES) @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ @@ -1017,13 +633,9 @@ || exit 1; \ fi; \ done - $(MAKE) $(AM_MAKEFLAGS) \ - top_distdir="$(top_distdir)" distdir="$(distdir)" \ - dist-hook check-am: all-am - $(MAKE) $(AM_MAKEFLAGS) check-TESTS check: check-am -all-am: Makefile $(LIBRARIES) $(PROGRAMS) +all-am: Makefile $(PROGRAMS) installdirs: install: install-am install-exec: install-exec-am @@ -1045,12 +657,8 @@ "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ fi mostlyclean-generic: - -test -z "$(TEST_LOGS)" || rm -f $(TEST_LOGS) - -test -z "$(TEST_LOGS:.log=.trs)" || rm -f $(TEST_LOGS:.log=.trs) - -test -z "$(TEST_SUITE_LOG)" || rm -f $(TEST_SUITE_LOG) clean-generic: - -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -1061,8 +669,8 @@ @echo "it deletes files that may require special tools to rebuild." clean: clean-am -clean-am: clean-generic clean-libtool clean-noinstLIBRARIES \ - clean-noinstPROGRAMS mostlyclean-am +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am distclean: distclean-am -rm -rf ./$(DEPDIR) @@ -1130,12 +738,11 @@ uninstall-am: -.MAKE: check-am install-am install-strip +.MAKE: install-am install-strip -.PHONY: CTAGS GTAGS TAGS all all-am check check-TESTS check-am clean \ - clean-generic clean-libtool clean-noinstLIBRARIES \ - clean-noinstPROGRAMS cscopelist-am ctags ctags-am dist-hook \ - distclean distclean-compile distclean-generic \ +.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ + clean-libtool clean-noinstPROGRAMS cscopelist-am ctags \ + ctags-am distclean distclean-compile distclean-generic \ distclean-libtool distclean-tags distdir dvi dvi-am html \ html-am info info-am install install-am install-data \ install-data-am install-dvi install-dvi-am install-exec \ @@ -1145,20 +752,10 @@ installcheck-am installdirs maintainer-clean \ maintainer-clean-generic mostlyclean mostlyclean-compile \ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - recheck tags tags-am uninstall uninstall-am + tags tags-am uninstall uninstall-am .PRECIOUS: Makefile - -@HAVE_PYTHON_TRUE@ isl_test_python.py: isl.py - -isl.py: extract_interface libdep.a isl.py.top - (cat $(srcdir)/isl.py.top; \ - ./extract_interface$(EXEEXT) --language=python $(includes) \ - $(srcdir)/all.h) \ - > isl.py -dist-hook: isl.py - cp isl.py $(distdir)/ # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. diff --git a/gcc/isl/interface/all.c b/gcc/isl/interface/all.c deleted file mode 100644 index 3344a3c..0000000 100644 --- a/gcc/isl/interface/all.c +++ /dev/null @@ -1,1 +1,0 @@ -#include "all.h" diff --git a/gcc/isl/interface/all.h b/gcc/isl/interface/all.h deleted file mode 100644 index ea0b498..0000000 100644 --- a/gcc/isl/interface/all.h +++ /dev/null @@ -1,11 +1,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/gcc/isl/interface/extract_interface.cc b/gcc/isl/interface/extract_interface.cc index 1118688..34a7f40 100644 --- a/gcc/isl/interface/extract_interface.cc +++ a/gcc/isl/interface/extract_interface.cc @@ -32,20 +32,26 @@ */ #include "isl_config.h" +#undef PACKAGE #include #include +#include #ifdef HAVE_ADT_OWNINGPTR_H #include #else #include #endif +#ifdef HAVE_LLVM_OPTION_ARG_H +#include +#endif #include #include #include #include #include #include +#include #include #include #include @@ -76,10 +82,15 @@ #include "extract_interface.h" #include "generator.h" #include "python.h" +#include "cpp.h" +#include "cpp_conversion.h" using namespace std; using namespace clang; using namespace clang::driver; +#ifdef HAVE_LLVM_OPTION_ARG_H +using namespace llvm::opt; +#endif #ifdef HAVE_ADT_OWNINGPTR_H #define unique_ptr llvm::OwningPtr @@ -91,7 +102,7 @@ llvm::cl::desc("Header search path"), llvm::cl::value_desc("path"), llvm::cl::Prefix); -static llvm::cl::opt Language(llvm::cl::Required, +static llvm::cl::opt OutputLanguage(llvm::cl::Required, llvm::cl::ValueRequired, "language", llvm::cl::desc("Bindings to generate"), llvm::cl::value_desc("name")); @@ -199,6 +210,32 @@ static Job *command(Job &J) { return &J; } static Command *command(Command &C) { return &C; } }; + +#ifdef CREATE_FROM_ARGS_TAKES_ARRAYREF + +/* Call CompilerInvocation::CreateFromArgs with the right arguments. + * In this case, an ArrayRef. + */ +static void create_from_args(CompilerInvocation &invocation, + const ArgStringList *args, DiagnosticsEngine &Diags) +{ + CompilerInvocation::CreateFromArgs(invocation, *args, Diags); +} + +#else + +/* Call CompilerInvocation::CreateFromArgs with the right arguments. + * In this case, two "const char *" pointers. + */ +static void create_from_args(CompilerInvocation &invocation, + const ArgStringList *args, DiagnosticsEngine &Diags) +{ + CompilerInvocation::CreateFromArgs(invocation, args->data() + 1, + args->data() + args->size(), + Diags); +} + +#endif /* Create a CompilerInvocation object that stores the command line * arguments constructed by the driver. @@ -224,9 +261,7 @@ const ArgStringList *args = &cmd->getArguments(); CompilerInvocation *invocation = new CompilerInvocation; - CompilerInvocation::CreateFromArgs(*invocation, args->data() + 1, - args->data() + args->size(), - Diags); + create_from_args(*invocation, args, Diags); return invocation; } @@ -392,7 +427,74 @@ } #endif + +/* Helper function for ignore_error that only gets enabled if T + * (which is either const FileEntry * or llvm::ErrorOr) + * has getError method, i.e., if it is llvm::ErrorOr. + */ +template +static const FileEntry *ignore_error_helper(const T obj, int, + int[1][sizeof(obj.getError())]) +{ + return *obj; +} + +/* Helper function for ignore_error that is always enabled, + * but that only gets selected if the variant above is not enabled, + * i.e., if T is const FileEntry *. + */ +template +static const FileEntry *ignore_error_helper(const T obj, long, void *) +{ + return obj; +} +/* Given either a const FileEntry * or a llvm::ErrorOr, + * extract out the const FileEntry *. + */ +template +static const FileEntry *ignore_error(const T obj) +{ + return ignore_error_helper(obj, 0, NULL); +} + +/* Return the FileEntry corresponding to the given file name + * in the given compiler instances, ignoring any error. + */ +static const FileEntry *getFile(CompilerInstance *Clang, std::string Filename) +{ + return ignore_error(Clang->getFileManager().getFile(Filename)); +} + +/* Create an interface generator for the selected language and + * then use it to generate the interface. + */ +static void generate(MyASTConsumer &consumer, SourceManager &SM) +{ + generator *gen; + + if (OutputLanguage.compare("python") == 0) { + gen = new python_generator(SM, consumer.exported_types, + consumer.exported_functions, consumer.functions); + } else if (OutputLanguage.compare("cpp") == 0) { + gen = new cpp_generator(SM, consumer.exported_types, + consumer.exported_functions, consumer.functions); + } else if (OutputLanguage.compare("cpp-checked") == 0) { + gen = new cpp_generator(SM, consumer.exported_types, + consumer.exported_functions, consumer.functions, true); + } else if (OutputLanguage.compare("cpp-checked-conversion") == 0) { + gen = new cpp_conversion_generator(SM, consumer.exported_types, + consumer.exported_functions, consumer.functions); + } else { + cerr << "Language '" << OutputLanguage + << "' not recognized." << endl + << "Not generating bindings." << endl; + exit(EXIT_FAILURE); + } + + gen->generate(); +} + int main(int argc, char *argv[]) { llvm::cl::ParseCommandLineOptions(argc, argv); @@ -401,15 +503,15 @@ create_diagnostics(Clang); DiagnosticsEngine &Diags = Clang->getDiagnostics(); Diags.setSuppressSystemWarnings(true); + TargetInfo *target = create_target_info(Clang, Diags); + Clang->setTarget(target); + set_lang_defaults(Clang); CompilerInvocation *invocation = construct_invocation(InputFilename.c_str(), Diags); if (invocation) set_invocation(Clang, invocation); Clang->createFileManager(); Clang->createSourceManager(Clang->getFileManager()); - TargetInfo *target = create_target_info(Clang, Diags); - Clang->setTarget(target); - set_lang_defaults(Clang); HeaderSearchOptions &HSO = Clang->getHeaderSearchOpts(); LangOptions &LO = Clang->getLangOpts(); PreprocessorOptions &PO = Clang->getPreprocessorOpts(); @@ -433,7 +535,7 @@ PP.getBuiltinInfo().initializeBuiltins(PP.getIdentifierTable(), LO); - const FileEntry *file = Clang->getFileManager().getFile(InputFilename); + const FileEntry *file = getFile(Clang, InputFilename); assert(file); create_main_file_id(Clang->getSourceManager(), file); @@ -444,21 +546,14 @@ Diags.getClient()->BeginSourceFile(LO, &PP); ParseAST(*sema); Diags.getClient()->EndSourceFile(); - - generator *gen = NULL; - if (Language.compare("python") == 0) - gen = new python_generator(consumer.exported_types, - consumer.exported_functions, consumer.functions); - else - cerr << "Language '" << Language << "' not recognized." << endl - << "Not generating bindings." << endl; - if (gen) - gen->generate(); + generate(consumer, Clang->getSourceManager()); delete sema; delete Clang; llvm::llvm_shutdown(); - return 0; + if (Diags.hasErrorOccurred()) + return EXIT_FAILURE; + return EXIT_SUCCESS; } diff --git a/gcc/isl/interface/generator.cc b/gcc/isl/interface/generator.cc index 01704f8..075a3d6 100644 --- a/gcc/isl/interface/generator.cc +++ a/gcc/isl/interface/generator.cc @@ -32,26 +32,70 @@ */ #include +#include +#include #include #include +#include #include "isl_config.h" #include "extract_interface.h" #include "generator.h" +const char *isl_class::get_prefix = "get_"; +const char *isl_class::set_callback_prefix = "set_"; + /* Should "method" be considered to be a static method? * That is, is the first argument something other than * an instance of the class? */ -bool generator::is_static(const isl_class &clazz, FunctionDecl *method) +bool isl_class::is_static(FunctionDecl *method) const { - ParmVarDecl *param = method->getParamDecl(0); - QualType type = param->getOriginalType(); + ParmVarDecl *param; + QualType type; + + if (method->getNumParams() < 1) + return true; - if (!is_isl_type(type)) + param = method->getParamDecl(0); + type = param->getOriginalType(); + if (!generator::is_isl_type(type)) return true; - return extract_type(type) != clazz.name; + return generator::extract_type(type) != name; +} + +/* Should "method" be considered to be a static method? + * That is, is the first argument something other than + * an instance of the class? + */ +bool generator::is_static(const isl_class &clazz, FunctionDecl *method) +{ + return clazz.is_static(method); +} + +/* Does "fd" modify an object of "clazz"? + * That is, is it an object method that takes the object and + * returns (gives) an object of the same type? + */ +bool generator::is_mutator(const isl_class &clazz, FunctionDecl *fd) +{ + ParmVarDecl *param; + QualType type, return_type; + + if (fd->getNumParams() < 1) + return false; + if (is_static(clazz, fd)) + return false; + + if (!gives(fd)) + return false; + param = fd->getParamDecl(0); + if (!takes(param)) + return false; + type = param->getOriginalType(); + return_type = fd->getReturnType(); + return return_type == type; } /* Find the FunctionDecl with name "name", @@ -68,50 +112,293 @@ if (required) die("No " + name + " function found"); return NULL; +} + +/* List of conversion functions that are used to automatically convert + * the second argument of the conversion function to its function result. + */ +const std::set generator::automatic_conversion_functions = { + "isl_id_read_from_str", + "isl_val_int_from_si", +}; + +/* Extract information about the automatic conversion function "fd", + * storing the results in this->conversions. + * + * A function used for automatic conversion has exactly two arguments, + * an isl_ctx and a non-isl object, and it returns an isl object. + * Store a mapping from the isl object return type + * to the non-isl object source type. + */ +void generator::extract_automatic_conversion(FunctionDecl *fd) +{ + QualType return_type = fd->getReturnType(); + const Type *type = return_type.getTypePtr(); + + if (fd->getNumParams() != 2) + die("Expecting two arguments"); + if (!is_isl_ctx(fd->getParamDecl(0)->getOriginalType())) + die("Expecting isl_ctx first argument"); + if (!is_isl_type(return_type)) + die("Expecting isl object return type"); + conversions[type] = fd->getParamDecl(1); +} + +/* Extract information about all automatic conversion functions + * for the given class, storing the results in this->conversions. + * + * In particular, look through all exported constructors for the class and + * check if any of them is explicitly marked as a conversion function. + */ +void generator::extract_class_automatic_conversions(const isl_class &clazz) +{ + const function_set &constructors = clazz.constructors; + function_set::iterator fi; + + for (fi = constructors.begin(); fi != constructors.end(); ++fi) { + FunctionDecl *fd = *fi; + string name = fd->getName(); + if (automatic_conversion_functions.count(name) != 0) + extract_automatic_conversion(fd); + } +} + +/* Extract information about all automatic conversion functions, + * storing the results in this->conversions. + */ +void generator::extract_automatic_conversions() +{ + map::iterator ci; + + for (ci = classes.begin(); ci != classes.end(); ++ci) + extract_class_automatic_conversions(ci->second); +} + +/* Add a subclass derived from "decl" called "sub_name" to the set of classes, + * keeping track of the _to_str, _copy and _free functions, if any, separately. + * "sub_name" is either the name of the class itself or + * the name of a type based subclass. + * If the class is a proper subclass, then "super_name" is the name + * of its immediate superclass. + */ +void generator::add_subclass(RecordDecl *decl, const string &super_name, + const string &sub_name) +{ + string name = decl->getName(); + + classes[sub_name].name = name; + classes[sub_name].superclass_name = super_name; + classes[sub_name].subclass_name = sub_name; + classes[sub_name].type = decl; + classes[sub_name].fn_to_str = find_by_name(name + "_to_str", false); + classes[sub_name].fn_copy = find_by_name(name + "_copy", true); + classes[sub_name].fn_free = find_by_name(name + "_free", true); +} + +/* Add a class derived from "decl" to the set of classes, + * keeping track of the _to_str, _copy and _free functions, if any, separately. + */ +void generator::add_class(RecordDecl *decl) +{ + return add_subclass(decl, "", decl->getName()); +} + +/* Given a function "fn_type" that returns the subclass type + * of a C object, create subclasses for each of the (non-negative) + * return values. + * + * The function "fn_type" is also stored in the superclass, + * along with all pairs of type values and subclass names. + */ +void generator::add_type_subclasses(FunctionDecl *fn_type) +{ + QualType return_type = fn_type->getReturnType(); + const EnumType *enum_type = return_type->getAs(); + EnumDecl *decl = enum_type->getDecl(); + isl_class *c = method2class(fn_type); + DeclContext::decl_iterator i; + + c->fn_type = fn_type; + for (i = decl->decls_begin(); i != decl->decls_end(); ++i) { + EnumConstantDecl *ecd = dyn_cast(*i); + int val = (int) ecd->getInitVal().getSExtValue(); + string name = ecd->getNameAsString(); + + if (val < 0) + continue; + c->type_subclasses[val] = name; + add_subclass(c->type, c->subclass_name, name); + } +} + +/* Add information about the enum values in "decl", set by "fd", + * to c->set_enums. "prefix" is the prefix of the generated method names. + * In particular, it has the name of the enum type removed. + * + * In particular, for each non-negative enum value, keep track of + * the value, the name and the corresponding method name. + */ +static void add_set_enum(isl_class *c, const string &prefix, EnumDecl *decl, + FunctionDecl *fd) +{ + DeclContext::decl_iterator i; + + for (i = decl->decls_begin(); i != decl->decls_end(); ++i) { + EnumConstantDecl *ecd = dyn_cast(*i); + int val = (int) ecd->getInitVal().getSExtValue(); + string name = ecd->getNameAsString(); + string method_name; + + if (val < 0) + continue; + method_name = prefix + name.substr(4); + c->set_enums[fd].push_back(set_enum(val, name, method_name)); + } +} + +/* Check if "fd" sets an enum value and, if so, add information + * about the enum values to c->set_enums. + * + * A function is considered to set an enum value if: + * - the function returns an object of the same type + * - the last argument is of type enum + * - the name of the function ends with the name of the enum + */ +static bool handled_sets_enum(isl_class *c, FunctionDecl *fd) +{ + unsigned n; + ParmVarDecl *param; + const EnumType *enum_type; + EnumDecl *decl; + string enum_name; + string fd_name; + string prefix; + size_t pos; + + if (!generator::is_mutator(*c, fd)) + return false; + n = fd->getNumParams(); + if (n < 2) + return false; + param = fd->getParamDecl(n - 1); + enum_type = param->getType()->getAs(); + if (!enum_type) + return false; + decl = enum_type->getDecl(); + enum_name = decl->getName(); + enum_name = enum_name.substr(4); + fd_name = c->method_name(fd); + pos = fd_name.find(enum_name); + if (pos == std::string::npos) + return false; + prefix = fd_name.substr(0, pos); + + add_set_enum(c, prefix, decl, fd); + + return true; +} + +/* Return the callback argument of a function setting + * a persistent callback. + * This callback is in the second argument (position 1). + */ +ParmVarDecl *generator::persistent_callback_arg(FunctionDecl *fd) +{ + return fd->getParamDecl(1); +} + +/* Does the given function set a persistent callback? + * The following heuristics are used to determine this property: + * - the function returns an object of the same type + * - its name starts with "set_" + * - it has exactly three arguments + * - the second (position 1) of which is a callback + */ +static bool sets_persistent_callback(isl_class *c, FunctionDecl *fd) +{ + ParmVarDecl *param; + + if (!generator::is_mutator(*c, fd)) + return false; + if (fd->getNumParams() != 3) + return false; + param = generator::persistent_callback_arg(fd); + if (!generator::is_callback(param->getType())) + return false; + return prefixcmp(c->method_name(fd).c_str(), + c->set_callback_prefix) == 0; +} + +/* Sorting function that places declaration of functions + * with a shorter name first. + */ +static bool less_name(const FunctionDecl *a, const FunctionDecl *b) +{ + return a->getName().size() < b->getName().size(); } /* Collect all functions that belong to a certain type, separating - * constructors from regular methods and keeping track of the _to_str, + * constructors from methods that set persistent callback and + * from regular methods, while keeping track of the _to_str, * _copy and _free functions, if any, separately. If there are any overloaded * functions, then they are grouped based on their name after removing the * argument type suffix. + * Check for functions that describe subclasses before considering + * any other functions in order to be able to detect those other + * functions as belonging to the subclasses. + * Sort the names of the functions based on their lengths + * to ensure that nested subclasses are handled later. */ -generator::generator(set &exported_types, - set exported_functions, set functions) +generator::generator(SourceManager &SM, set &exported_types, + set exported_functions, set functions) : + SM(SM) { - map::iterator ci; - set::iterator in; + set::iterator it; + vector type_subclasses; + vector::iterator iv; + for (in = functions.begin(); in != functions.end(); ++in) { FunctionDecl *decl = *in; functions_by_name[decl->getName()] = decl; } - set::iterator it; - for (it = exported_types.begin(); it != exported_types.end(); ++it) { - RecordDecl *decl = *it; - string name = decl->getName(); - classes[name].name = name; - classes[name].type = decl; - classes[name].fn_to_str = find_by_name(name + "_to_str", false); - classes[name].fn_copy = find_by_name(name + "_copy", true); - classes[name].fn_free = find_by_name(name + "_free", true); + for (it = exported_types.begin(); it != exported_types.end(); ++it) + add_class(*it); + + for (in = exported_functions.begin(); in != exported_functions.end(); + ++in) { + if (is_subclass(*in)) + type_subclasses.push_back(*in); } + std::sort(type_subclasses.begin(), type_subclasses.end(), &less_name); + for (iv = type_subclasses.begin(); iv != type_subclasses.end(); ++iv) { + add_type_subclasses(*iv); + } for (in = exported_functions.begin(); in != exported_functions.end(); ++in) { - isl_class *c = method2class(*in); + FunctionDecl *method = *in; + isl_class *c; + + if (is_subclass(method)) + continue; + + c = method2class(method); if (!c) continue; - if (is_constructor(*in)) { - c->constructors.insert(*in); + if (is_constructor(method)) { + c->constructors.insert(method); + } else if (handled_sets_enum(c, method)) { + } else if (sets_persistent_callback(c, method)) { + c->persistent_callbacks.insert(method); } else { - FunctionDecl *method = *in; - string fullname = method->getName(); - fullname = drop_type_suffix(fullname, method); + string fullname = c->name_without_type_suffixes(method); c->methods[fullname].insert(method); } } + + extract_automatic_conversions(); } /* Print error message "msg" and abort. @@ -135,10 +422,20 @@ * appear in the source. In particular, the first annotation * is the one that is closest to the annotated type and the corresponding * type is then also the first that will appear in the sequence of types. + * This is also the order in which the annotations appear + * in the AttrVec returned by Decl::getAttrs() in older versions of clang. + * In newer versions of clang, the order is that in which + * the attribute appears in the source. + * Use the position of the "isl_export" attribute to determine + * whether this is an old (with reversed order) or a new version. + * The "isl_export" attribute is automatically added + * after each "isl_subclass" attribute. If it appears in the list before + * any "isl_subclass" is encountered, then this must be a reversed list. */ -std::vector generator::find_superclasses(RecordDecl *decl) +std::vector generator::find_superclasses(Decl *decl) { vector super; + bool reversed = false; if (!decl->hasAttrs()) return super; @@ -151,13 +448,25 @@ if (!ann) continue; string s = ann->getAnnotation().str(); + if (s == "isl_export" && super.size() == 0) + reversed = true; if (s.substr(0, len) == sub) { s = s.substr(len + 1, s.length() - len - 2); - super.push_back(s); + if (reversed) + super.push_back(s); + else + super.insert(super.begin(), s); } } return super; +} + +/* Is "decl" marked as describing subclasses? + */ +bool generator::is_subclass(FunctionDecl *decl) +{ + return find_superclasses(decl).size() > 0; } /* Is decl marked as being part of an overloaded method? @@ -195,7 +504,7 @@ return has_annotation(decl, "isl_give"); } -/* Return the class that has a name that matches the initial part +/* Return the class that has a name that best matches the initial part * of the name of function "fd" or NULL if no such class could be found. */ isl_class *generator::method2class(FunctionDecl *fd) @@ -205,7 +514,9 @@ string name = fd->getNameAsString(); for (ci = classes.begin(); ci != classes.end(); ++ci) { - if (name.substr(0, ci->first.length()) == ci->first) + size_t len = ci->first.length(); + if (len > best.length() && name.substr(0, len) == ci->first && + name[len] == '_') best = ci->first; } @@ -222,7 +533,7 @@ bool generator::is_isl_ctx(QualType type) { if (!type->isPointerType()) - return 0; + return false; type = type->getPointeeType(); if (type.getAsString() != "isl_ctx") return false; @@ -241,6 +552,82 @@ param = fd->getParamDecl(0); return is_isl_ctx(param->getOriginalType()); +} + +namespace { + +struct ClangAPI { + /* Return the first location in the range returned by + * clang::SourceManager::getImmediateExpansionRange. + * Older versions of clang return a pair of SourceLocation objects. + * More recent versions return a CharSourceRange. + */ + static SourceLocation range_begin( + const std::pair &p) { + return p.first; + } + static SourceLocation range_begin(const CharSourceRange &range) { + return range.getBegin(); + } +}; + +} + +/* Does the callback argument "param" take its argument at position "pos"? + * + * The memory management annotations of arguments to function pointers + * are not recorded by clang, so the information cannot be extracted + * from the type of "param". + * Instead, go to the location in the source where the callback argument + * is declared, look for the right argument of the callback itself and + * then check if it has an "__isl_take" memory management annotation. + * + * If the return value of the function has a memory management annotation, + * then the spelling of "param" will point to the spelling + * of this memory management annotation. Since the macro is defined + * on the command line (in main), this location does not have a file entry. + * In this case, move up one level in the macro expansion to the location + * where the memory management annotation is used. + */ +bool generator::callback_takes_argument(ParmVarDecl *param, + int pos) +{ + SourceLocation loc; + const char *s, *end, *next; + bool takes, keeps; + + loc = param->getSourceRange().getBegin(); + if (!SM.getFileEntryForID(SM.getFileID(SM.getSpellingLoc(loc)))) + loc = ClangAPI::range_begin(SM.getImmediateExpansionRange(loc)); + s = SM.getCharacterData(loc); + if (!s) + die("No character data"); + s = strchr(s, '('); + if (!s) + die("Cannot find function pointer"); + s = strchr(s + 1, '('); + if (!s) + die("Cannot find function pointer arguments"); + end = strchr(s + 1, ')'); + if (!end) + die("Cannot find end of function pointer arguments"); + while (pos-- > 0) { + s = strchr(s + 1, ','); + if (!s || s > end) + die("Cannot find function pointer argument"); + } + next = strchr(s + 1, ','); + if (next && next < end) + end = next; + s = strchr(s + 1, '_'); + if (!s || s > end) + die("Cannot find function pointer argument annotation"); + takes = prefixcmp(s, "__isl_take") == 0; + keeps = prefixcmp(s, "__isl_keep") == 0; + if (!takes && !keeps) + die("Cannot find function pointer argument annotation"); + + return takes; } /* Is "type" that of a pointer to an isl_* structure? @@ -260,9 +647,17 @@ return false; } -/* Is "type" the type isl_bool? +/* Is "type" one of the integral types with a negative value + * indicating an error condition? */ -bool generator::is_isl_bool(QualType type) +bool generator::is_isl_neg_error(QualType type) +{ + return is_isl_bool(type) || is_isl_stat(type) || is_isl_size(type); +} + +/* Is "type" the primitive type with the given name? + */ +static bool is_isl_primitive(QualType type, const char *name) { string s; @@ -270,22 +665,29 @@ return false; s = type.getAsString(); - return s == "isl_bool"; + return s == name; +} + +/* Is "type" the type isl_bool? + */ +bool generator::is_isl_bool(QualType type) +{ + return is_isl_primitive(type, "isl_bool"); } /* Is "type" the type isl_stat? */ bool generator::is_isl_stat(QualType type) { - string s; - - if (type->isPointerType()) - return false; - - s = type.getAsString(); - return s == "isl_stat"; + return is_isl_primitive(type, "isl_stat"); } +/* Is "type" the type isl_size? + */ +bool generator::is_isl_size(QualType type) +{ + return is_isl_primitive(type, "isl_size"); +} /* Is "type" that of a pointer to a function? */ @@ -315,6 +717,14 @@ { const BuiltinType *builtin = type->getAs(); return builtin && builtin->getKind() == BuiltinType::Long; +} + +/* Is "type" that of "unsigned int"? + */ +static bool is_unsigned_int(QualType type) +{ + const BuiltinType *builtin = type->getAs(); + return builtin && builtin->getKind() == BuiltinType::UInt; } /* Return the name of the type that "type" points to. @@ -325,32 +735,100 @@ if (type->isPointerType()) return type->getPointeeType().getAsString(); die("Cannot extract type from non-pointer type"); +} + +/* Given the type of a function pointer, return the corresponding + * function prototype. + */ +const FunctionProtoType *generator::extract_prototype(QualType type) +{ + return type->getPointeeType()->getAs(); +} + +/* Return the function name suffix for the type of "param". + * + * If the type of "param" is an isl object type, + * then the suffix is the name of the type with the "isl" prefix removed, + * but keeping the "_". + * If the type is an unsigned integer, then the type suffix is "_ui". + */ +static std::string type_suffix(ParmVarDecl *param) +{ + QualType type; + + type = param->getOriginalType(); + if (generator::is_isl_type(type)) + return generator::extract_type(type).substr(3); + else if (is_unsigned_int(type)) + return "_ui"; + generator::die("Unsupported type suffix"); +} + +/* If "suffix" is a suffix of "s", then return "s" with the suffix removed. + * Otherwise, simply return "s". + */ +static std::string drop_suffix(const std::string &s, const std::string &suffix) +{ + size_t len, suffix_len; + + len = s.length(); + suffix_len = suffix.length(); + + if (len >= suffix_len && s.substr(len - suffix_len) == suffix) + return s.substr(0, len - suffix_len); + else + return s; } -/* If "method" is overloaded, then drop the suffix of "name" - * corresponding to the type of the final argument and - * return the modified name (or the original name if - * no modifications were made). +/* If "method" is overloaded, then return its name with the suffixes + * corresponding to the types of the final arguments removed. + * Otherwise, simply return the name of the function. + * Start from the final argument and keep removing suffixes + * matching arguments, independently of whether previously considered + * arguments matched. */ -string generator::drop_type_suffix(string name, FunctionDecl *method) +string isl_class::name_without_type_suffixes(FunctionDecl *method) { int num_params; - ParmVarDecl *param; - string type; - size_t name_len, type_len; + string name; - if (!is_overload(method)) + name = method->getName(); + if (!generator::is_overload(method)) return name; num_params = method->getNumParams(); - param = method->getParamDecl(num_params - 1); - type = extract_type(param->getOriginalType()); - type = type.substr(4); - name_len = name.length(); - type_len = type.length(); - - if (name_len > type_len && name.substr(name_len - type_len) == type) - name = name.substr(0, name_len - type_len - 1); + for (int i = num_params - 1; i >= 0; --i) { + ParmVarDecl *param; + string type; + param = method->getParamDecl(i); + type = type_suffix(param); + + name = drop_suffix(name, type); + } + return name; +} + +/* Is function "fd" with the given name a "get" method? + * + * A "get" method is an instance method + * with a name that starts with the get method prefix. + */ +bool isl_class::is_get_method_name(FunctionDecl *fd, const string &name) const +{ + return !is_static(fd) && prefixcmp(name.c_str(), get_prefix) == 0; +} + +/* Extract the method name corresponding to "fd". + * + * If "fd" is a "get" method, then drop the "get" method prefix. + */ +string isl_class::method_name(FunctionDecl *fd) const +{ + string base = base_method_name(fd); + + if (is_get_method_name(fd, base)) + return base.substr(strlen(get_prefix)); + return base; } diff --git a/gcc/isl/interface/generator.h b/gcc/isl/interface/generator.h index 6376084..e829f26 100644 --- a/gcc/isl/interface/generator.h +++ a/gcc/isl/interface/generator.h @@ -1,42 +1,136 @@ #ifndef ISL_INTERFACE_GENERATOR_H #define ISL_INTERFACE_GENERATOR_H #include #include #include +#include #include using namespace std; using namespace clang; +/* Compare the prefix of "s" to "prefix" up to the length of "prefix". + */ +inline int prefixcmp(const char *s, const char *prefix) +{ + return strncmp(s, prefix, strlen(prefix)); +} + +/* Information about a single enum value of an enum set by a function. + * "value" is the enum value. + * "name" is the corresponding name. + * "method_name" is the the name of the method that sets this value. + */ +struct set_enum { + int value; + string name; + string method_name; + set_enum(int value, string name, string method_name) : + value(value), name(name), method_name(method_name) {} +}; + +/* Helper structure for sorting FunctionDecl pointers + * on the corresponding function names. + */ +struct function_name_less { + bool operator()(FunctionDecl *x, FunctionDecl *y) { + return x->getName() < y->getName(); + } +}; + +/* Set of FunctionDecl pointers sorted on function name. + */ +typedef std::set function_set; + /* isl_class collects all constructors and methods for an isl "class". * "name" is the name of the class. + * If this object describes a subclass of a C type, then + * "subclass_name" is the name of that subclass and "superclass_name" + * is the name of the immediate superclass of that subclass. Otherwise, + * "subclass_name" is equal to "name" and "superclass_name" is undefined. * "type" is the declaration that introduces the type. + * "persistent_callbacks" contains the set of functions that + * set a persistent callback. + * "set_enums" maps the set of functions that set an enum value + * to information associated to each value. + * A function is considered to set an enum value if it returns + * an object of the same type and if its last argument is of an enum type. * "methods" contains the set of methods, grouped by method name. * "fn_to_str" is a reference to the *_to_str method of this class, if any. * "fn_copy" is a reference to the *_copy method of this class, if any. * "fn_free" is a reference to the *_free method of this class, if any. + * "fn_type" is a reference to a function that described subclasses, if any. + * If "fn_type" is set, then "type_subclasses" maps the values returned + * by that function to the names of the corresponding subclasses. */ struct isl_class { string name; + string superclass_name; + string subclass_name; RecordDecl *type; - set constructors; - map > methods; + function_set constructors; + set persistent_callbacks; + map > set_enums; + map methods; + map type_subclasses; + FunctionDecl *fn_type; FunctionDecl *fn_to_str; FunctionDecl *fn_copy; FunctionDecl *fn_free; + + /* Does "method" correspond to a static method? */ + bool is_static(FunctionDecl *method) const; + /* Is this class a subclass based on a type function? */ + bool is_type_subclass() const { return name != subclass_name; } + /* Return name of "fd" without type suffixes, if any. */ + static string name_without_type_suffixes(FunctionDecl *fd); + /* Extract the method name corresponding to "fd" + * (including "get" method prefix if any). + */ + string base_method_name(FunctionDecl *fd) const { + string m_name = name_without_type_suffixes(fd); + return m_name.substr(subclass_name.length() + 1); + } + /* The prefix of a "get" method. */ + static const char *get_prefix; + /* Is function "fd" with the given name a "get" method? */ + bool is_get_method_name(FunctionDecl *fd, const string &name) const; + /* Is function "fd" a "get" method? */ + bool is_get_method(FunctionDecl *fd) const { + return is_get_method_name(fd, base_method_name(fd)); + } + /* Extract the method name corresponding to "fd". */ + string method_name(FunctionDecl *fd) const; + /* The prefix of any method that may set a (persistent) callback. */ + static const char *set_callback_prefix; + /* Given a function that sets a persistent callback, + * return the name of the callback. + */ + string persistent_callback_name(FunctionDecl *fd) const { + return method_name(fd).substr(strlen(set_callback_prefix)); + } + /* Does this class have any functions that set a persistent callback? + */ + bool has_persistent_callbacks() const { + return persistent_callbacks.size() != 0; + } }; /* Base class for interface generators. + * + * "conversions" maps the target type of automatic conversion + * to the second input argument of the conversion function. */ class generator { protected: + SourceManager &SM; map classes; map functions_by_name; public: - generator(set &exported_types, + generator(SourceManager &SM, set &exported_types, set exported_functions, set functions); @@ -44,29 +138,44 @@ virtual ~generator() {}; protected: - void print_class_header(const isl_class &clazz, const string &name, - const vector &super); - string drop_type_suffix(string name, FunctionDecl *method); - void die(const char *msg) __attribute__((noreturn)); - void die(string msg) __attribute__((noreturn)); - vector find_superclasses(RecordDecl *decl); - bool is_overload(Decl *decl); - bool is_constructor(Decl *decl); - bool takes(Decl *decl); - bool keeps(Decl *decl); - bool gives(Decl *decl); + void add_subclass(RecordDecl *decl, const string &name, + const string &sub_name); + void add_class(RecordDecl *decl); + void add_type_subclasses(FunctionDecl *method); isl_class *method2class(FunctionDecl *fd); - bool is_isl_ctx(QualType type); - bool first_arg_is_isl_ctx(FunctionDecl *fd); - bool is_isl_type(QualType type); - bool is_isl_bool(QualType type); - bool is_isl_stat(QualType type); - bool is_long(QualType type); - bool is_callback(QualType type); - bool is_string(QualType type); - bool is_static(const isl_class &clazz, FunctionDecl *method); - string extract_type(QualType type); + bool callback_takes_argument(ParmVarDecl *param, int pos); FunctionDecl *find_by_name(const string &name, bool required); + std::map conversions; +private: + static const std::set automatic_conversion_functions; + void extract_automatic_conversion(FunctionDecl *fd); + void extract_class_automatic_conversions(const isl_class &clazz); + void extract_automatic_conversions(); +public: + static void die(const char *msg) __attribute__((noreturn)); + static void die(string msg) __attribute__((noreturn)); + static vector find_superclasses(Decl *decl); + static bool is_subclass(FunctionDecl *decl); + static bool is_overload(Decl *decl); + static bool is_constructor(Decl *decl); + static bool takes(Decl *decl); + static bool keeps(Decl *decl); + static bool gives(Decl *decl); + static bool is_isl_ctx(QualType type); + static bool first_arg_is_isl_ctx(FunctionDecl *fd); + static bool is_isl_type(QualType type); + static bool is_isl_neg_error(QualType type); + static bool is_isl_bool(QualType type); + static bool is_isl_stat(QualType type); + static bool is_isl_size(QualType type); + static bool is_long(QualType type); + static bool is_callback(QualType type); + static bool is_string(QualType type); + static bool is_static(const isl_class &clazz, FunctionDecl *method); + static bool is_mutator(const isl_class &clazz, FunctionDecl *fd); + static string extract_type(QualType type); + static const FunctionProtoType *extract_prototype(QualType type); + static ParmVarDecl *persistent_callback_arg(FunctionDecl *fd); }; #endif /* ISL_INTERFACE_GENERATOR_H */ diff --git a/gcc/isl/interface/isl.py b/gcc/isl/interface/isl.py index 7e0c73d..099528a 100644 --- a/gcc/isl/interface/isl.py +++ a/gcc/isl/interface/isl.py @@ -1,7 +1,16 @@ +isl_dlname='libisl.so.22' +import os from ctypes import * +from ctypes.util import find_library -isl = cdll.LoadLibrary("libisl.so") -libc = cdll.LoadLibrary("libc.so.6") +isl_dyld_library_path = os.environ.get('ISL_DYLD_LIBRARY_PATH') +if isl_dyld_library_path != None: + os.environ['DYLD_LIBRARY_PATH'] = isl_dyld_library_path +try: + isl = cdll.LoadLibrary(isl_dlname) +except: + isl = cdll.LoadLibrary(find_library("isl")) +libc = cdll.LoadLibrary(find_library("c")) class Error(Exception): pass @@ -38,13 +47,13 @@ self.ctx = Context.getDefaultInstance() self.ptr = isl.isl_union_pw_multi_aff_from_pw_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr)) return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_pw_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) - return if len(args) == 1 and args[0].__class__ is union_pw_aff: self.ctx = Context.getDefaultInstance() self.ptr = isl.isl_union_pw_multi_aff_from_union_pw_aff(isl.isl_union_pw_aff_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_pw_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): @@ -79,7 +88,51 @@ raise ctx = arg0.ctx res = isl.isl_union_pw_multi_aff_add(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_pw_multi_aff(ctx=ctx, ptr=res) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def as_pw_multi_aff(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_as_pw_multi_aff(isl.isl_union_pw_multi_aff_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def domain(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_domain(isl.isl_union_pw_multi_aff_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + @staticmethod + def empty(*args): + if len(args) == 0: + ctx = Context.getDefaultInstance() + res = isl.isl_union_pw_multi_aff_empty_ctx(ctx) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def extract_pw_multi_aff(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is space: + arg1 = space(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_extract_pw_multi_aff(arg0.ptr, isl.isl_space_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj def flat_range_product(arg0, arg1): try: if not arg0.__class__ is union_pw_multi_aff: @@ -93,11 +146,163 @@ raise ctx = arg0.ctx res = isl.isl_union_pw_multi_aff_flat_range_product(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_pw_multi_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is union_pw_multi_aff: - res = isl.isl_union_pw_multi_aff_pullback_union_pw_multi_aff(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_pw_multi_aff(ctx=arg0.ctx, ptr=res) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def space(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_gist(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_intersect_domain(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain_wrapped_domain(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_intersect_domain_wrapped_domain(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain_wrapped_range(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_intersect_domain_wrapped_range(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_intersect_params(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def isa_pw_multi_aff(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_isa_pw_multi_aff(arg0.ptr) + if res < 0: + raise + return bool(res) + def pullback(*args): + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_pw_multi_aff_pullback_union_pw_multi_aff(isl.isl_union_pw_multi_aff_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def range_factor_domain(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_range_factor_domain(isl.isl_union_pw_multi_aff_copy(arg0.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def range_factor_range(arg0): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_range_factor_range(isl.isl_union_pw_multi_aff_copy(arg0.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def sub(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_pw_multi_aff: + arg1 = union_pw_multi_aff(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_sub(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def subtract_domain(arg0, arg1): + try: + if not arg0.__class__ is union_pw_multi_aff: + arg0 = union_pw_multi_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_pw_multi_aff_subtract_domain(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj def union_add(arg0, arg1): try: if not arg0.__class__ is union_pw_multi_aff: @@ -111,20 +316,50 @@ raise ctx = arg0.ctx res = isl.isl_union_pw_multi_aff_union_add(isl.isl_union_pw_multi_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_pw_multi_aff(ctx=ctx, ptr=res) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj isl.isl_union_pw_multi_aff_from_pw_multi_aff.restype = c_void_p isl.isl_union_pw_multi_aff_from_pw_multi_aff.argtypes = [c_void_p] -isl.isl_union_pw_multi_aff_read_from_str.restype = c_void_p -isl.isl_union_pw_multi_aff_read_from_str.argtypes = [Context, c_char_p] isl.isl_union_pw_multi_aff_from_union_pw_aff.restype = c_void_p isl.isl_union_pw_multi_aff_from_union_pw_aff.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_read_from_str.restype = c_void_p +isl.isl_union_pw_multi_aff_read_from_str.argtypes = [Context, c_char_p] isl.isl_union_pw_multi_aff_add.restype = c_void_p isl.isl_union_pw_multi_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_as_pw_multi_aff.restype = c_void_p +isl.isl_union_pw_multi_aff_as_pw_multi_aff.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_domain.restype = c_void_p +isl.isl_union_pw_multi_aff_domain.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_empty_ctx.restype = c_void_p +isl.isl_union_pw_multi_aff_empty_ctx.argtypes = [Context] +isl.isl_union_pw_multi_aff_extract_pw_multi_aff.restype = c_void_p +isl.isl_union_pw_multi_aff_extract_pw_multi_aff.argtypes = [c_void_p, c_void_p] isl.isl_union_pw_multi_aff_flat_range_product.restype = c_void_p isl.isl_union_pw_multi_aff_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_get_space.restype = c_void_p +isl.isl_union_pw_multi_aff_get_space.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_gist.restype = c_void_p +isl.isl_union_pw_multi_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_intersect_domain.restype = c_void_p +isl.isl_union_pw_multi_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_intersect_domain_wrapped_domain.restype = c_void_p +isl.isl_union_pw_multi_aff_intersect_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_intersect_domain_wrapped_range.restype = c_void_p +isl.isl_union_pw_multi_aff_intersect_domain_wrapped_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_intersect_params.restype = c_void_p +isl.isl_union_pw_multi_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_isa_pw_multi_aff.argtypes = [c_void_p] isl.isl_union_pw_multi_aff_pullback_union_pw_multi_aff.restype = c_void_p isl.isl_union_pw_multi_aff_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_range_factor_domain.restype = c_void_p +isl.isl_union_pw_multi_aff_range_factor_domain.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_range_factor_range.restype = c_void_p +isl.isl_union_pw_multi_aff_range_factor_range.argtypes = [c_void_p] +isl.isl_union_pw_multi_aff_sub.restype = c_void_p +isl.isl_union_pw_multi_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_multi_aff_subtract_domain.restype = c_void_p +isl.isl_union_pw_multi_aff_subtract_domain.argtypes = [c_void_p, c_void_p] isl.isl_union_pw_multi_aff_union_add.restype = c_void_p isl.isl_union_pw_multi_aff_union_add.argtypes = [c_void_p, c_void_p] isl.isl_union_pw_multi_aff_copy.restype = c_void_p @@ -139,14 +374,18 @@ if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is multi_pw_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_union_pw_aff_from_multi_pw_aff(isl.isl_multi_pw_aff_copy(args[0].ptr)) return if len(args) == 1 and args[0].__class__ is union_pw_aff: self.ctx = Context.getDefaultInstance() self.ptr = isl.isl_multi_union_pw_aff_from_union_pw_aff(isl.isl_union_pw_aff_copy(args[0].ptr)) return - if len(args) == 1 and args[0].__class__ is multi_pw_aff: + if len(args) == 2 and args[0].__class__ is space and args[1].__class__ is union_pw_aff_list: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_union_pw_aff_from_multi_pw_aff(isl.isl_multi_pw_aff_copy(args[0].ptr)) + self.ptr = isl.isl_multi_union_pw_aff_from_union_pw_aff_list(isl.isl_space_copy(args[0].ptr), isl.isl_union_pw_aff_list_copy(args[1].ptr)) return if len(args) == 1 and type(args[0]) == str: self.ctx = Context.getDefaultInstance() @@ -185,26 +424,34 @@ raise ctx = arg0.ctx res = isl.isl_multi_union_pw_aff_add(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) - return multi_union_pw_aff(ctx=ctx, ptr=res) - def flat_range_product(arg0, arg1): + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def bind(arg0, arg1): try: if not arg0.__class__ is multi_union_pw_aff: arg0 = multi_union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is multi_union_pw_aff: - arg1 = multi_union_pw_aff(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: raise ctx = arg0.ctx - res = isl.isl_multi_union_pw_aff_flat_range_product(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) - return multi_union_pw_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is union_pw_multi_aff: - res = isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return multi_union_pw_aff(ctx=arg0.ctx, ptr=res) - def range_product(arg0, arg1): + res = isl.isl_multi_union_pw_aff_bind(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def domain(arg0): + try: + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_domain(isl.isl_multi_union_pw_aff_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def flat_range_product(arg0, arg1): try: if not arg0.__class__ is multi_union_pw_aff: arg0 = multi_union_pw_aff(arg0) @@ -216,269 +463,288 @@ except: raise ctx = arg0.ctx - res = isl.isl_multi_union_pw_aff_range_product(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) - return multi_union_pw_aff(ctx=ctx, ptr=res) - def union_add(arg0, arg1): + res = isl.isl_multi_union_pw_aff_flat_range_product(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def at(arg0, arg1): try: if not arg0.__class__ is multi_union_pw_aff: arg0 = multi_union_pw_aff(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_get_at(arg0.ptr, arg1) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def space(arg0): try: - if not arg1.__class__ is multi_union_pw_aff: - arg1 = multi_union_pw_aff(arg1) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_multi_union_pw_aff_union_add(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) - return multi_union_pw_aff(ctx=ctx, ptr=res) - -isl.isl_multi_union_pw_aff_from_union_pw_aff.restype = c_void_p -isl.isl_multi_union_pw_aff_from_union_pw_aff.argtypes = [c_void_p] -isl.isl_multi_union_pw_aff_from_multi_pw_aff.restype = c_void_p -isl.isl_multi_union_pw_aff_from_multi_pw_aff.argtypes = [c_void_p] -isl.isl_multi_union_pw_aff_read_from_str.restype = c_void_p -isl.isl_multi_union_pw_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_multi_union_pw_aff_add.restype = c_void_p -isl.isl_multi_union_pw_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_multi_union_pw_aff_flat_range_product.restype = c_void_p -isl.isl_multi_union_pw_aff_flat_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff.restype = c_void_p -isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_multi_union_pw_aff_range_product.restype = c_void_p -isl.isl_multi_union_pw_aff_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_union_pw_aff_union_add.restype = c_void_p -isl.isl_multi_union_pw_aff_union_add.argtypes = [c_void_p, c_void_p] -isl.isl_multi_union_pw_aff_copy.restype = c_void_p -isl.isl_multi_union_pw_aff_copy.argtypes = [c_void_p] -isl.isl_multi_union_pw_aff_free.restype = c_void_p -isl.isl_multi_union_pw_aff_free.argtypes = [c_void_p] -isl.isl_multi_union_pw_aff_to_str.restype = POINTER(c_char) -isl.isl_multi_union_pw_aff_to_str.argtypes = [c_void_p] - -class union_pw_aff(union_pw_multi_aff, multi_union_pw_aff): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 1 and args[0].__class__ is pw_aff: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_pw_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_union_pw_aff_free(self.ptr) - def __str__(arg0): + res = isl.isl_multi_union_pw_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): try: - if not arg0.__class__ is union_pw_aff: - arg0 = union_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise - ptr = isl.isl_union_pw_aff_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.union_pw_aff("""%s""")' % s - else: - return 'isl.union_pw_aff("%s")' % s - def add(arg0, arg1): try: - if not arg0.__class__ is union_pw_aff: - arg0 = union_pw_aff(arg0) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: raise - try: - if not arg1.__class__ is union_pw_aff: - arg1 = union_pw_aff(arg1) - except: - return union_pw_multi_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_union_pw_aff_add(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) - return union_pw_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is union_pw_multi_aff: - res = isl.isl_union_pw_aff_pullback_union_pw_multi_aff(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_pw_aff(ctx=arg0.ctx, ptr=res) - def union_add(arg0, arg1): + res = isl.isl_multi_union_pw_aff_gist(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): try: - if not arg0.__class__ is union_pw_aff: - arg0 = union_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_pw_aff: - arg1 = union_pw_aff(arg1) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: - return union_pw_multi_aff(arg0).union_add(arg1) + raise ctx = arg0.ctx - res = isl.isl_union_pw_aff_union_add(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) - return union_pw_aff(ctx=ctx, ptr=res) - -isl.isl_union_pw_aff_from_pw_aff.restype = c_void_p -isl.isl_union_pw_aff_from_pw_aff.argtypes = [c_void_p] -isl.isl_union_pw_aff_read_from_str.restype = c_void_p -isl.isl_union_pw_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_union_pw_aff_add.restype = c_void_p -isl.isl_union_pw_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_union_pw_aff_pullback_union_pw_multi_aff.restype = c_void_p -isl.isl_union_pw_aff_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_union_pw_aff_union_add.restype = c_void_p -isl.isl_union_pw_aff_union_add.argtypes = [c_void_p, c_void_p] -isl.isl_union_pw_aff_copy.restype = c_void_p -isl.isl_union_pw_aff_copy.argtypes = [c_void_p] -isl.isl_union_pw_aff_free.restype = c_void_p -isl.isl_union_pw_aff_free.argtypes = [c_void_p] -isl.isl_union_pw_aff_to_str.restype = POINTER(c_char) -isl.isl_union_pw_aff_to_str.argtypes = [c_void_p] - -class multi_pw_aff(multi_union_pw_aff): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 1 and args[0].__class__ is multi_aff: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_pw_aff_from_multi_aff(isl.isl_multi_aff_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is pw_aff: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_pw_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is pw_multi_aff: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_pw_aff_from_pw_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr)) - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_multi_pw_aff_free(self.ptr) - def __str__(arg0): + res = isl.isl_multi_union_pw_aff_intersect_domain(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): try: - if not arg0.__class__ is multi_pw_aff: - arg0 = multi_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise - ptr = isl.isl_multi_pw_aff_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.multi_pw_aff("""%s""")' % s - else: - return 'isl.multi_pw_aff("%s")' % s - def add(arg0, arg1): try: - if not arg0.__class__ is multi_pw_aff: - arg0 = multi_pw_aff(arg0) + if not arg1.__class__ is set: + arg1 = set(arg1) except: raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_intersect_params(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def neg(arg0): try: - if not arg1.__class__ is multi_pw_aff: - arg1 = multi_pw_aff(arg1) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: - return multi_union_pw_aff(arg0).add(arg1) + raise ctx = arg0.ctx - res = isl.isl_multi_pw_aff_add(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=ctx, ptr=res) - def flat_range_product(arg0, arg1): + res = isl.isl_multi_union_pw_aff_neg(isl.isl_multi_union_pw_aff_copy(arg0.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def plain_is_equal(arg0, arg1): try: - if not arg0.__class__ is multi_pw_aff: - arg0 = multi_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is multi_pw_aff: - arg1 = multi_pw_aff(arg1) + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) except: - return multi_union_pw_aff(arg0).flat_range_product(arg1) + raise ctx = arg0.ctx - res = isl.isl_multi_pw_aff_flat_range_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=ctx, ptr=res) - def product(arg0, arg1): + res = isl.isl_multi_union_pw_aff_plain_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def pullback(*args): + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff(isl.isl_multi_union_pw_aff_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def range_product(arg0, arg1): try: - if not arg0.__class__ is multi_pw_aff: - arg0 = multi_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is multi_pw_aff: - arg1 = multi_pw_aff(arg1) + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) except: - return multi_union_pw_aff(arg0).product(arg1) + raise ctx = arg0.ctx - res = isl.isl_multi_pw_aff_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_multi_pw_aff_pullback_multi_aff(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is pw_multi_aff: - res = isl.isl_multi_pw_aff_pullback_pw_multi_aff(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is multi_pw_aff: - res = isl.isl_multi_pw_aff_pullback_multi_pw_aff(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=arg0.ctx, ptr=res) - def range_product(arg0, arg1): + res = isl.isl_multi_union_pw_aff_range_product(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def scale(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_union_pw_aff_scale_multi_val(isl.isl_multi_union_pw_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_union_pw_aff_scale_val(isl.isl_multi_union_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_union_pw_aff_scale_down_multi_val(isl.isl_multi_union_pw_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_union_pw_aff_scale_down_val(isl.isl_multi_union_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def set_at(arg0, arg1, arg2): try: - if not arg0.__class__ is multi_pw_aff: - arg0 = multi_pw_aff(arg0) + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is multi_pw_aff: - arg1 = multi_pw_aff(arg1) + if not arg2.__class__ is union_pw_aff: + arg2 = union_pw_aff(arg2) except: - return multi_union_pw_aff(arg0).range_product(arg1) + raise ctx = arg0.ctx - res = isl.isl_multi_pw_aff_range_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return multi_pw_aff(ctx=ctx, ptr=res) + res = isl.isl_multi_union_pw_aff_set_at(isl.isl_multi_union_pw_aff_copy(arg0.ptr), arg1, isl.isl_union_pw_aff_copy(arg2.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def size(arg0): + try: + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_size(arg0.ptr) + if res < 0: + raise + return int(res) + def sub(arg0, arg1): + try: + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_sub(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def union_add(arg0, arg1): + try: + if not arg0.__class__ is multi_union_pw_aff: + arg0 = multi_union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_union_add(isl.isl_multi_union_pw_aff_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def zero(arg0): + try: + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_union_pw_aff_zero(isl.isl_space_copy(arg0.ptr)) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj -isl.isl_multi_pw_aff_from_multi_aff.restype = c_void_p -isl.isl_multi_pw_aff_from_multi_aff.argtypes = [c_void_p] -isl.isl_multi_pw_aff_from_pw_aff.restype = c_void_p -isl.isl_multi_pw_aff_from_pw_aff.argtypes = [c_void_p] -isl.isl_multi_pw_aff_from_pw_multi_aff.restype = c_void_p -isl.isl_multi_pw_aff_from_pw_multi_aff.argtypes = [c_void_p] -isl.isl_multi_pw_aff_read_from_str.restype = c_void_p -isl.isl_multi_pw_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_multi_pw_aff_add.restype = c_void_p -isl.isl_multi_pw_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_flat_range_product.restype = c_void_p -isl.isl_multi_pw_aff_flat_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_product.restype = c_void_p -isl.isl_multi_pw_aff_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_pullback_multi_aff.restype = c_void_p -isl.isl_multi_pw_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_pullback_pw_multi_aff.restype = c_void_p -isl.isl_multi_pw_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_pullback_multi_pw_aff.restype = c_void_p -isl.isl_multi_pw_aff_pullback_multi_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_range_product.restype = c_void_p -isl.isl_multi_pw_aff_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_pw_aff_copy.restype = c_void_p -isl.isl_multi_pw_aff_copy.argtypes = [c_void_p] -isl.isl_multi_pw_aff_free.restype = c_void_p -isl.isl_multi_pw_aff_free.argtypes = [c_void_p] -isl.isl_multi_pw_aff_to_str.restype = POINTER(c_char) -isl.isl_multi_pw_aff_to_str.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_from_multi_pw_aff.restype = c_void_p +isl.isl_multi_union_pw_aff_from_multi_pw_aff.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_from_union_pw_aff.restype = c_void_p +isl.isl_multi_union_pw_aff_from_union_pw_aff.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_from_union_pw_aff_list.restype = c_void_p +isl.isl_multi_union_pw_aff_from_union_pw_aff_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_read_from_str.restype = c_void_p +isl.isl_multi_union_pw_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_multi_union_pw_aff_add.restype = c_void_p +isl.isl_multi_union_pw_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_bind.restype = c_void_p +isl.isl_multi_union_pw_aff_bind.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_domain.restype = c_void_p +isl.isl_multi_union_pw_aff_domain.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_flat_range_product.restype = c_void_p +isl.isl_multi_union_pw_aff_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_get_at.restype = c_void_p +isl.isl_multi_union_pw_aff_get_at.argtypes = [c_void_p, c_int] +isl.isl_multi_union_pw_aff_get_space.restype = c_void_p +isl.isl_multi_union_pw_aff_get_space.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_gist.restype = c_void_p +isl.isl_multi_union_pw_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_intersect_domain.restype = c_void_p +isl.isl_multi_union_pw_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_intersect_params.restype = c_void_p +isl.isl_multi_union_pw_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_neg.restype = c_void_p +isl.isl_multi_union_pw_aff_neg.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_plain_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff.restype = c_void_p +isl.isl_multi_union_pw_aff_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_range_product.restype = c_void_p +isl.isl_multi_union_pw_aff_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_scale_multi_val.restype = c_void_p +isl.isl_multi_union_pw_aff_scale_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_scale_val.restype = c_void_p +isl.isl_multi_union_pw_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_scale_down_multi_val.restype = c_void_p +isl.isl_multi_union_pw_aff_scale_down_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_scale_down_val.restype = c_void_p +isl.isl_multi_union_pw_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_set_at.restype = c_void_p +isl.isl_multi_union_pw_aff_set_at.argtypes = [c_void_p, c_int, c_void_p] +isl.isl_multi_union_pw_aff_size.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_sub.restype = c_void_p +isl.isl_multi_union_pw_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_union_add.restype = c_void_p +isl.isl_multi_union_pw_aff_union_add.argtypes = [c_void_p, c_void_p] +isl.isl_multi_union_pw_aff_zero.restype = c_void_p +isl.isl_multi_union_pw_aff_zero.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_copy.restype = c_void_p +isl.isl_multi_union_pw_aff_copy.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_free.restype = c_void_p +isl.isl_multi_union_pw_aff_free.argtypes = [c_void_p] +isl.isl_multi_union_pw_aff_to_str.restype = POINTER(c_char) +isl.isl_multi_union_pw_aff_to_str.argtypes = [c_void_p] -class pw_multi_aff(union_pw_multi_aff, multi_pw_aff): +class union_pw_aff(union_pw_multi_aff, multi_union_pw_aff): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] @@ -486,3793 +752,11105 @@ return if len(args) == 1 and args[0].__class__ is pw_aff: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_pw_multi_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) + self.ptr = isl.isl_union_pw_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) return if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_pw_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) - return - if len(args) == 1 and args[0].__class__ is multi_aff: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_pw_multi_aff_from_multi_aff(isl.isl_multi_aff_copy(args[0].ptr)) + self.ptr = isl.isl_union_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_pw_multi_aff_free(self.ptr) + isl.isl_union_pw_aff_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise - ptr = isl.isl_pw_multi_aff_to_str(arg0.ptr) + ptr = isl.isl_union_pw_aff_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.pw_multi_aff("""%s""")' % s + return 'isl.union_pw_aff("""%s""")' % s else: - return 'isl.pw_multi_aff("%s")' % s + return 'isl.union_pw_aff("%s")' % s def add(arg0, arg1): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_multi_aff: - arg1 = pw_multi_aff(arg1) + if not arg1.__class__ is union_pw_aff: + arg1 = union_pw_aff(arg1) except: return union_pw_multi_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_pw_multi_aff_add(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=ctx, ptr=res) - def flat_range_product(arg0, arg1): + res = isl.isl_union_pw_aff_add(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def bind(*args): + if len(args) == 2 and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_union_pw_aff_bind_id(isl.isl_union_pw_aff_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + raise Error + def domain(arg0): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_union_pw_aff_domain(isl.isl_union_pw_aff_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def space(arg0): try: - if not arg1.__class__ is pw_multi_aff: - arg1 = pw_multi_aff(arg1) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: - return union_pw_multi_aff(arg0).flat_range_product(arg1) + raise ctx = arg0.ctx - res = isl.isl_pw_multi_aff_flat_range_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=ctx, ptr=res) - def product(arg0, arg1): + res = isl.isl_union_pw_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_multi_aff: - arg1 = pw_multi_aff(arg1) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: - return union_pw_multi_aff(arg0).product(arg1) + return union_pw_multi_aff(arg0).gist(arg1) ctx = arg0.ctx - res = isl.isl_pw_multi_aff_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_pw_multi_aff_pullback_multi_aff(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is pw_multi_aff: - res = isl.isl_pw_multi_aff_pullback_pw_multi_aff(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=arg0.ctx, ptr=res) - def range_product(arg0, arg1): + res = isl.isl_union_pw_aff_gist(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_multi_aff: - arg1 = pw_multi_aff(arg1) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: - return union_pw_multi_aff(arg0).range_product(arg1) + return union_pw_multi_aff(arg0).intersect_domain(arg1) ctx = arg0.ctx - res = isl.isl_pw_multi_aff_range_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=ctx, ptr=res) + res = isl.isl_union_pw_aff_intersect_domain(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain_wrapped_domain(arg0, arg1): + try: + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + return union_pw_multi_aff(arg0).intersect_domain_wrapped_domain(arg1) + ctx = arg0.ctx + res = isl.isl_union_pw_aff_intersect_domain_wrapped_domain(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain_wrapped_range(arg0, arg1): + try: + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + return union_pw_multi_aff(arg0).intersect_domain_wrapped_range(arg1) + ctx = arg0.ctx + res = isl.isl_union_pw_aff_intersect_domain_wrapped_range(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_pw_multi_aff(arg0).intersect_params(arg1) + ctx = arg0.ctx + res = isl.isl_union_pw_aff_intersect_params(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def pullback(*args): + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_pw_aff_pullback_union_pw_multi_aff(isl.isl_union_pw_aff_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def sub(arg0, arg1): + try: + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_pw_aff: + arg1 = union_pw_aff(arg1) + except: + return union_pw_multi_aff(arg0).sub(arg1) + ctx = arg0.ctx + res = isl.isl_union_pw_aff_sub(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def subtract_domain(arg0, arg1): + try: + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + return union_pw_multi_aff(arg0).subtract_domain(arg1) + ctx = arg0.ctx + res = isl.isl_union_pw_aff_subtract_domain(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj def union_add(arg0, arg1): try: - if not arg0.__class__ is pw_multi_aff: - arg0 = pw_multi_aff(arg0) + if not arg0.__class__ is union_pw_aff: + arg0 = union_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_multi_aff: - arg1 = pw_multi_aff(arg1) + if not arg1.__class__ is union_pw_aff: + arg1 = union_pw_aff(arg1) except: return union_pw_multi_aff(arg0).union_add(arg1) ctx = arg0.ctx - res = isl.isl_pw_multi_aff_union_add(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_multi_aff(ctx=ctx, ptr=res) + res = isl.isl_union_pw_aff_union_add(isl.isl_union_pw_aff_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj -isl.isl_pw_multi_aff_from_pw_aff.restype = c_void_p -isl.isl_pw_multi_aff_from_pw_aff.argtypes = [c_void_p] -isl.isl_pw_multi_aff_read_from_str.restype = c_void_p -isl.isl_pw_multi_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_pw_multi_aff_from_multi_aff.restype = c_void_p -isl.isl_pw_multi_aff_from_multi_aff.argtypes = [c_void_p] -isl.isl_pw_multi_aff_add.restype = c_void_p -isl.isl_pw_multi_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_flat_range_product.restype = c_void_p -isl.isl_pw_multi_aff_flat_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_product.restype = c_void_p -isl.isl_pw_multi_aff_product.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_pullback_multi_aff.restype = c_void_p -isl.isl_pw_multi_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_pullback_pw_multi_aff.restype = c_void_p -isl.isl_pw_multi_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_range_product.restype = c_void_p -isl.isl_pw_multi_aff_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_union_add.restype = c_void_p -isl.isl_pw_multi_aff_union_add.argtypes = [c_void_p, c_void_p] -isl.isl_pw_multi_aff_copy.restype = c_void_p -isl.isl_pw_multi_aff_copy.argtypes = [c_void_p] -isl.isl_pw_multi_aff_free.restype = c_void_p -isl.isl_pw_multi_aff_free.argtypes = [c_void_p] -isl.isl_pw_multi_aff_to_str.restype = POINTER(c_char) -isl.isl_pw_multi_aff_to_str.argtypes = [c_void_p] +isl.isl_union_pw_aff_from_pw_aff.restype = c_void_p +isl.isl_union_pw_aff_from_pw_aff.argtypes = [c_void_p] +isl.isl_union_pw_aff_read_from_str.restype = c_void_p +isl.isl_union_pw_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_union_pw_aff_add.restype = c_void_p +isl.isl_union_pw_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_bind_id.restype = c_void_p +isl.isl_union_pw_aff_bind_id.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_domain.restype = c_void_p +isl.isl_union_pw_aff_domain.argtypes = [c_void_p] +isl.isl_union_pw_aff_get_space.restype = c_void_p +isl.isl_union_pw_aff_get_space.argtypes = [c_void_p] +isl.isl_union_pw_aff_gist.restype = c_void_p +isl.isl_union_pw_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_intersect_domain.restype = c_void_p +isl.isl_union_pw_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_intersect_domain_wrapped_domain.restype = c_void_p +isl.isl_union_pw_aff_intersect_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_intersect_domain_wrapped_range.restype = c_void_p +isl.isl_union_pw_aff_intersect_domain_wrapped_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_intersect_params.restype = c_void_p +isl.isl_union_pw_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_pullback_union_pw_multi_aff.restype = c_void_p +isl.isl_union_pw_aff_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_sub.restype = c_void_p +isl.isl_union_pw_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_subtract_domain.restype = c_void_p +isl.isl_union_pw_aff_subtract_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_union_add.restype = c_void_p +isl.isl_union_pw_aff_union_add.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_copy.restype = c_void_p +isl.isl_union_pw_aff_copy.argtypes = [c_void_p] +isl.isl_union_pw_aff_free.restype = c_void_p +isl.isl_union_pw_aff_free.argtypes = [c_void_p] +isl.isl_union_pw_aff_to_str.restype = POINTER(c_char) +isl.isl_union_pw_aff_to_str.argtypes = [c_void_p] -class pw_aff(union_pw_aff, pw_multi_aff, multi_pw_aff): +class multi_pw_aff(multi_union_pw_aff): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return - if len(args) == 1 and args[0].__class__ is aff: + if len(args) == 1 and args[0].__class__ is multi_aff: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_pw_aff_from_aff(isl.isl_aff_copy(args[0].ptr)) + self.ptr = isl.isl_multi_pw_aff_from_multi_aff(isl.isl_multi_aff_copy(args[0].ptr)) + return + if len(args) == 1 and args[0].__class__ is pw_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_pw_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) + return + if len(args) == 2 and args[0].__class__ is space and args[1].__class__ is pw_aff_list: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_pw_aff_from_pw_aff_list(isl.isl_space_copy(args[0].ptr), isl.isl_pw_aff_list_copy(args[1].ptr)) + return + if len(args) == 1 and args[0].__class__ is pw_multi_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_pw_aff_from_pw_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr)) return if len(args) == 1 and type(args[0]) == str: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) + self.ptr = isl.isl_multi_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_pw_aff_free(self.ptr) + isl.isl_multi_pw_aff_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise - ptr = isl.isl_pw_aff_to_str(arg0.ptr) + ptr = isl.isl_multi_pw_aff_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.pw_aff("""%s""")' % s + return 'isl.multi_pw_aff("""%s""")' % s else: - return 'isl.pw_aff("%s")' % s + return 'isl.multi_pw_aff("%s")' % s def add(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise - try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) - except: - return union_pw_aff(arg0).add(arg1) - ctx = arg0.ctx - res = isl.isl_pw_aff_add(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def ceil(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) except: - raise + return multi_union_pw_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_ceil(isl.isl_pw_aff_copy(arg0.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def cond(arg0, arg1, arg2): + res = isl.isl_multi_pw_aff_add(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def bind(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise - try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) - except: - return union_pw_aff(arg0).cond(arg1, arg2) try: - if not arg2.__class__ is pw_aff: - arg2 = pw_aff(arg2) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - return union_pw_aff(arg0).cond(arg1, arg2) + return multi_union_pw_aff(arg0).bind(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_cond(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr), isl.isl_pw_aff_copy(arg2.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def div(arg0, arg1): + res = isl.isl_multi_pw_aff_bind(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def bind_domain(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - return union_pw_aff(arg0).div(arg1) + return multi_union_pw_aff(arg0).bind_domain(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_div(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def eq_set(arg0, arg1): + res = isl.isl_multi_pw_aff_bind_domain(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def bind_domain_wrapped_domain(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - return union_pw_aff(arg0).eq_set(arg1) + return multi_union_pw_aff(arg0).bind_domain_wrapped_domain(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_eq_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def floor(arg0): + res = isl.isl_multi_pw_aff_bind_domain_wrapped_domain(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def domain(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_pw_aff_floor(isl.isl_pw_aff_copy(arg0.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def ge_set(arg0, arg1): + res = isl.isl_multi_pw_aff_domain(isl.isl_multi_pw_aff_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def flat_range_product(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) except: - return union_pw_aff(arg0).ge_set(arg1) + return multi_union_pw_aff(arg0).flat_range_product(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_ge_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def gt_set(arg0, arg1): + res = isl.isl_multi_pw_aff_flat_range_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def at(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_multi_pw_aff_get_at(arg0.ptr, arg1) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def space(arg0): try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: - return union_pw_aff(arg0).gt_set(arg1) + raise ctx = arg0.ctx - res = isl.isl_pw_aff_gt_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def le_set(arg0, arg1): + res = isl.isl_multi_pw_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return union_pw_aff(arg0).le_set(arg1) - ctx = arg0.ctx - res = isl.isl_pw_aff_le_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def lt_set(arg0, arg1): + return multi_union_pw_aff(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_multi_pw_aff_gist(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def identity(*args): + if len(args) == 1: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_identity_multi_pw_aff(isl.isl_multi_pw_aff_copy(args[0].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + @staticmethod + def identity_on_domain(*args): + if len(args) == 1 and args[0].__class__ is space: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_identity_on_domain_space(isl.isl_space_copy(args[0].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def intersect_domain(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return union_pw_aff(arg0).lt_set(arg1) + return multi_union_pw_aff(arg0).intersect_domain(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_lt_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def max(arg0, arg1): + res = isl.isl_multi_pw_aff_intersect_domain(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return union_pw_aff(arg0).max(arg1) - ctx = arg0.ctx - res = isl.isl_pw_aff_max(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def min(arg0, arg1): + return multi_union_pw_aff(arg0).intersect_params(arg1) + ctx = arg0.ctx + res = isl.isl_multi_pw_aff_intersect_params(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def involves_param(*args): + if len(args) == 2 and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_involves_param_id(args[0].ptr, args[1].ptr) + if res < 0: + raise + return bool(res) + if len(args) == 2 and args[1].__class__ is id_list: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_involves_param_id_list(args[0].ptr, args[1].ptr) + if res < 0: + raise + return bool(res) + raise Error + def neg(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise - try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) - except: - return union_pw_aff(arg0).min(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_min(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def mod(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_pw_aff_mod_val(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - def mul(arg0, arg1): + res = isl.isl_multi_pw_aff_neg(isl.isl_multi_pw_aff_copy(arg0.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def plain_is_equal(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) except: - return union_pw_aff(arg0).mul(arg1) + return multi_union_pw_aff(arg0).plain_is_equal(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_mul(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def ne_set(arg0, arg1): + res = isl.isl_multi_pw_aff_plain_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def product(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) except: - return union_pw_aff(arg0).ne_set(arg1) + return multi_union_pw_aff(arg0).product(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_ne_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def neg(arg0): + res = isl.isl_multi_pw_aff_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def pullback(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_pullback_multi_aff(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_pullback_multi_pw_aff(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_multi_pw_aff_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_pullback_pw_multi_aff(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def range_product(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) + except: + return multi_union_pw_aff(arg0).range_product(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_neg(isl.isl_pw_aff_copy(arg0.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_pw_aff_pullback_multi_aff(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is pw_multi_aff: - res = isl.isl_pw_aff_pullback_pw_multi_aff(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is multi_pw_aff: - res = isl.isl_pw_aff_pullback_multi_pw_aff(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - def scale(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_pw_aff_scale_val(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - def scale_down(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_pw_aff_scale_down_val(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return pw_aff(ctx=arg0.ctx, ptr=res) - def sub(arg0, arg1): + res = isl.isl_multi_pw_aff_range_product(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def scale(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_scale_multi_val(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_scale_val(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_scale_down_multi_val(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_pw_aff_scale_down_val(isl.isl_multi_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def set_at(arg0, arg1, arg2): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg2.__class__ is pw_aff: + arg2 = pw_aff(arg2) except: - return union_pw_aff(arg0).sub(arg1) + return multi_union_pw_aff(arg0).set_at(arg1, arg2) ctx = arg0.ctx - res = isl.isl_pw_aff_sub(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def tdiv_q(arg0, arg1): + res = isl.isl_multi_pw_aff_set_at(isl.isl_multi_pw_aff_copy(arg0.ptr), arg1, isl.isl_pw_aff_copy(arg2.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + def size(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise - try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) - except: - return union_pw_aff(arg0).tdiv_q(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_tdiv_q(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def tdiv_r(arg0, arg1): + res = isl.isl_multi_pw_aff_size(arg0.ptr) + if res < 0: + raise + return int(res) + def sub(arg0, arg1): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is multi_pw_aff: + arg0 = multi_pw_aff(arg0) except: raise try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) + if not arg1.__class__ is multi_pw_aff: + arg1 = multi_pw_aff(arg1) except: - return union_pw_aff(arg0).tdiv_r(arg1) + return multi_union_pw_aff(arg0).sub(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_tdiv_r(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) - def union_add(arg0, arg1): + res = isl.isl_multi_pw_aff_sub(isl.isl_multi_pw_aff_copy(arg0.ptr), isl.isl_multi_pw_aff_copy(arg1.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def zero(arg0): try: - if not arg0.__class__ is pw_aff: - arg0 = pw_aff(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise - try: - if not arg1.__class__ is pw_aff: - arg1 = pw_aff(arg1) - except: - return union_pw_aff(arg0).union_add(arg1) ctx = arg0.ctx - res = isl.isl_pw_aff_union_add(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) - return pw_aff(ctx=ctx, ptr=res) + res = isl.isl_multi_pw_aff_zero(isl.isl_space_copy(arg0.ptr)) + obj = multi_pw_aff(ctx=ctx, ptr=res) + return obj -isl.isl_pw_aff_from_aff.restype = c_void_p -isl.isl_pw_aff_from_aff.argtypes = [c_void_p] -isl.isl_pw_aff_read_from_str.restype = c_void_p -isl.isl_pw_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_pw_aff_add.restype = c_void_p -isl.isl_pw_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_ceil.restype = c_void_p -isl.isl_pw_aff_ceil.argtypes = [c_void_p] -isl.isl_pw_aff_cond.restype = c_void_p -isl.isl_pw_aff_cond.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_pw_aff_div.restype = c_void_p -isl.isl_pw_aff_div.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_eq_set.restype = c_void_p -isl.isl_pw_aff_eq_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_floor.restype = c_void_p -isl.isl_pw_aff_floor.argtypes = [c_void_p] -isl.isl_pw_aff_ge_set.restype = c_void_p -isl.isl_pw_aff_ge_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_gt_set.restype = c_void_p -isl.isl_pw_aff_gt_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_le_set.restype = c_void_p -isl.isl_pw_aff_le_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_lt_set.restype = c_void_p -isl.isl_pw_aff_lt_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_max.restype = c_void_p -isl.isl_pw_aff_max.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_min.restype = c_void_p -isl.isl_pw_aff_min.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_mod_val.restype = c_void_p -isl.isl_pw_aff_mod_val.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_mul.restype = c_void_p -isl.isl_pw_aff_mul.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_ne_set.restype = c_void_p -isl.isl_pw_aff_ne_set.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_neg.restype = c_void_p -isl.isl_pw_aff_neg.argtypes = [c_void_p] -isl.isl_pw_aff_pullback_multi_aff.restype = c_void_p -isl.isl_pw_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_pullback_pw_multi_aff.restype = c_void_p -isl.isl_pw_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_pullback_multi_pw_aff.restype = c_void_p -isl.isl_pw_aff_pullback_multi_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_scale_val.restype = c_void_p -isl.isl_pw_aff_scale_val.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_scale_down_val.restype = c_void_p -isl.isl_pw_aff_scale_down_val.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_sub.restype = c_void_p -isl.isl_pw_aff_sub.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_tdiv_q.restype = c_void_p -isl.isl_pw_aff_tdiv_q.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_tdiv_r.restype = c_void_p -isl.isl_pw_aff_tdiv_r.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_union_add.restype = c_void_p -isl.isl_pw_aff_union_add.argtypes = [c_void_p, c_void_p] -isl.isl_pw_aff_copy.restype = c_void_p -isl.isl_pw_aff_copy.argtypes = [c_void_p] -isl.isl_pw_aff_free.restype = c_void_p -isl.isl_pw_aff_free.argtypes = [c_void_p] -isl.isl_pw_aff_to_str.restype = POINTER(c_char) -isl.isl_pw_aff_to_str.argtypes = [c_void_p] +isl.isl_multi_pw_aff_from_multi_aff.restype = c_void_p +isl.isl_multi_pw_aff_from_multi_aff.argtypes = [c_void_p] +isl.isl_multi_pw_aff_from_pw_aff.restype = c_void_p +isl.isl_multi_pw_aff_from_pw_aff.argtypes = [c_void_p] +isl.isl_multi_pw_aff_from_pw_aff_list.restype = c_void_p +isl.isl_multi_pw_aff_from_pw_aff_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_from_pw_multi_aff.restype = c_void_p +isl.isl_multi_pw_aff_from_pw_multi_aff.argtypes = [c_void_p] +isl.isl_multi_pw_aff_read_from_str.restype = c_void_p +isl.isl_multi_pw_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_multi_pw_aff_add.restype = c_void_p +isl.isl_multi_pw_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_bind.restype = c_void_p +isl.isl_multi_pw_aff_bind.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_bind_domain.restype = c_void_p +isl.isl_multi_pw_aff_bind_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_bind_domain_wrapped_domain.restype = c_void_p +isl.isl_multi_pw_aff_bind_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_domain.restype = c_void_p +isl.isl_multi_pw_aff_domain.argtypes = [c_void_p] +isl.isl_multi_pw_aff_flat_range_product.restype = c_void_p +isl.isl_multi_pw_aff_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_get_at.restype = c_void_p +isl.isl_multi_pw_aff_get_at.argtypes = [c_void_p, c_int] +isl.isl_multi_pw_aff_get_space.restype = c_void_p +isl.isl_multi_pw_aff_get_space.argtypes = [c_void_p] +isl.isl_multi_pw_aff_gist.restype = c_void_p +isl.isl_multi_pw_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_identity_multi_pw_aff.restype = c_void_p +isl.isl_multi_pw_aff_identity_multi_pw_aff.argtypes = [c_void_p] +isl.isl_multi_pw_aff_identity_on_domain_space.restype = c_void_p +isl.isl_multi_pw_aff_identity_on_domain_space.argtypes = [c_void_p] +isl.isl_multi_pw_aff_intersect_domain.restype = c_void_p +isl.isl_multi_pw_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_intersect_params.restype = c_void_p +isl.isl_multi_pw_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_involves_param_id.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_involves_param_id_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_neg.restype = c_void_p +isl.isl_multi_pw_aff_neg.argtypes = [c_void_p] +isl.isl_multi_pw_aff_plain_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_product.restype = c_void_p +isl.isl_multi_pw_aff_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_pullback_multi_aff.restype = c_void_p +isl.isl_multi_pw_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_pullback_multi_pw_aff.restype = c_void_p +isl.isl_multi_pw_aff_pullback_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_pullback_pw_multi_aff.restype = c_void_p +isl.isl_multi_pw_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_range_product.restype = c_void_p +isl.isl_multi_pw_aff_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_scale_multi_val.restype = c_void_p +isl.isl_multi_pw_aff_scale_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_scale_val.restype = c_void_p +isl.isl_multi_pw_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_scale_down_multi_val.restype = c_void_p +isl.isl_multi_pw_aff_scale_down_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_scale_down_val.restype = c_void_p +isl.isl_multi_pw_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_set_at.restype = c_void_p +isl.isl_multi_pw_aff_set_at.argtypes = [c_void_p, c_int, c_void_p] +isl.isl_multi_pw_aff_size.argtypes = [c_void_p] +isl.isl_multi_pw_aff_sub.restype = c_void_p +isl.isl_multi_pw_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_multi_pw_aff_zero.restype = c_void_p +isl.isl_multi_pw_aff_zero.argtypes = [c_void_p] +isl.isl_multi_pw_aff_copy.restype = c_void_p +isl.isl_multi_pw_aff_copy.argtypes = [c_void_p] +isl.isl_multi_pw_aff_free.restype = c_void_p +isl.isl_multi_pw_aff_free.argtypes = [c_void_p] +isl.isl_multi_pw_aff_to_str.restype = POINTER(c_char) +isl.isl_multi_pw_aff_to_str.argtypes = [c_void_p] -class multi_aff(pw_multi_aff, multi_pw_aff): +class pw_multi_aff(union_pw_multi_aff, multi_pw_aff): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return - if len(args) == 1 and type(args[0]) == str: + if len(args) == 1 and args[0].__class__ is multi_aff: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) + self.ptr = isl.isl_pw_multi_aff_from_multi_aff(isl.isl_multi_aff_copy(args[0].ptr)) return - if len(args) == 1 and args[0].__class__ is aff: + if len(args) == 1 and args[0].__class__ is pw_aff: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_multi_aff_from_aff(isl.isl_aff_copy(args[0].ptr)) + self.ptr = isl.isl_pw_multi_aff_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_multi_aff_free(self.ptr) + isl.isl_pw_multi_aff_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is multi_aff: - arg0 = multi_aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise - ptr = isl.isl_multi_aff_to_str(arg0.ptr) + ptr = isl.isl_pw_multi_aff_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.multi_aff("""%s""")' % s + return 'isl.pw_multi_aff("""%s""")' % s else: - return 'isl.multi_aff("%s")' % s + return 'isl.pw_multi_aff("%s")' % s def add(arg0, arg1): try: - if not arg0.__class__ is multi_aff: - arg0 = multi_aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is multi_aff: - arg1 = multi_aff(arg1) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - return pw_multi_aff(arg0).add(arg1) + return union_pw_multi_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_multi_aff_add(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_aff(ctx=ctx, ptr=res) - def flat_range_product(arg0, arg1): + res = isl.isl_pw_multi_aff_add(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def as_multi_aff(arg0): try: - if not arg0.__class__ is multi_aff: - arg0 = multi_aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise - try: - if not arg1.__class__ is multi_aff: - arg1 = multi_aff(arg1) - except: - return pw_multi_aff(arg0).flat_range_product(arg1) ctx = arg0.ctx - res = isl.isl_multi_aff_flat_range_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_aff(ctx=ctx, ptr=res) - def product(arg0, arg1): + res = isl.isl_pw_multi_aff_as_multi_aff(isl.isl_pw_multi_aff_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def bind_domain(arg0, arg1): try: - if not arg0.__class__ is multi_aff: - arg0 = multi_aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is multi_aff: - arg1 = multi_aff(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - return pw_multi_aff(arg0).product(arg1) + return union_pw_multi_aff(arg0).bind_domain(arg1) ctx = arg0.ctx - res = isl.isl_multi_aff_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_multi_aff_pullback_multi_aff(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_aff(ctx=arg0.ctx, ptr=res) - def range_product(arg0, arg1): + res = isl.isl_pw_multi_aff_bind_domain(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def bind_domain_wrapped_domain(arg0, arg1): try: - if not arg0.__class__ is multi_aff: - arg0 = multi_aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is multi_aff: - arg1 = multi_aff(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - return pw_multi_aff(arg0).range_product(arg1) + return union_pw_multi_aff(arg0).bind_domain_wrapped_domain(arg1) ctx = arg0.ctx - res = isl.isl_multi_aff_range_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return multi_aff(ctx=ctx, ptr=res) - -isl.isl_multi_aff_read_from_str.restype = c_void_p -isl.isl_multi_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_multi_aff_from_aff.restype = c_void_p -isl.isl_multi_aff_from_aff.argtypes = [c_void_p] -isl.isl_multi_aff_add.restype = c_void_p -isl.isl_multi_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_multi_aff_flat_range_product.restype = c_void_p -isl.isl_multi_aff_flat_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_aff_product.restype = c_void_p -isl.isl_multi_aff_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_aff_pullback_multi_aff.restype = c_void_p -isl.isl_multi_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_multi_aff_range_product.restype = c_void_p -isl.isl_multi_aff_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_aff_copy.restype = c_void_p -isl.isl_multi_aff_copy.argtypes = [c_void_p] -isl.isl_multi_aff_free.restype = c_void_p -isl.isl_multi_aff_free.argtypes = [c_void_p] -isl.isl_multi_aff_to_str.restype = POINTER(c_char) -isl.isl_multi_aff_to_str.argtypes = [c_void_p] - -class aff(pw_aff, multi_aff): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_aff_read_from_str(self.ctx, args[0].encode('ascii')) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_aff_free(self.ptr) - def __str__(arg0): + res = isl.isl_pw_multi_aff_bind_domain_wrapped_domain(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def domain(arg0): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise - ptr = isl.isl_aff_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.aff("""%s""")' % s - else: - return 'isl.aff("%s")' % s - def add(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_domain(isl.isl_pw_multi_aff_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def flat_range_product(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - return pw_aff(arg0).add(arg1) + return union_pw_multi_aff(arg0).flat_range_product(arg1) ctx = arg0.ctx - res = isl.isl_aff_add(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return aff(ctx=ctx, ptr=res) - def ceil(arg0): + res = isl.isl_pw_multi_aff_flat_range_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def foreach_piece(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1, cb_arg2): + cb_arg0 = set(ctx=arg0.ctx, ptr=(cb_arg0)) + cb_arg1 = multi_aff(ctx=arg0.ctx, ptr=(cb_arg1)) + try: + arg1(cb_arg0, cb_arg1) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_aff_ceil(isl.isl_aff_copy(arg0.ptr)) - return aff(ctx=ctx, ptr=res) - def div(arg0, arg1): - try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) - except: + res = isl.isl_pw_multi_aff_foreach_piece(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: raise + def space(arg0): try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: - return pw_aff(arg0).div(arg1) + raise ctx = arg0.ctx - res = isl.isl_aff_div(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return aff(ctx=ctx, ptr=res) - def eq_set(arg0, arg1): + res = isl.isl_pw_multi_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return pw_aff(arg0).eq_set(arg1) + return union_pw_multi_aff(arg0).gist(arg1) ctx = arg0.ctx - res = isl.isl_aff_eq_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def floor(arg0): + res = isl.isl_pw_multi_aff_gist(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_pw_multi_aff(arg0).intersect_domain(arg1) ctx = arg0.ctx - res = isl.isl_aff_floor(isl.isl_aff_copy(arg0.ptr)) - return aff(ctx=ctx, ptr=res) - def ge_set(arg0, arg1): + res = isl.isl_pw_multi_aff_intersect_domain(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return pw_aff(arg0).ge_set(arg1) + return union_pw_multi_aff(arg0).intersect_params(arg1) ctx = arg0.ctx - res = isl.isl_aff_ge_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def gt_set(arg0, arg1): + res = isl.isl_pw_multi_aff_intersect_params(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def isa_multi_aff(arg0): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: + raise + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_isa_multi_aff(arg0.ptr) + if res < 0: raise + return bool(res) + def n_piece(arg0): try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: - return pw_aff(arg0).gt_set(arg1) + raise ctx = arg0.ctx - res = isl.isl_aff_gt_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def le_set(arg0, arg1): + res = isl.isl_pw_multi_aff_n_piece(arg0.ptr) + if res < 0: + raise + return int(res) + def product(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - return pw_aff(arg0).le_set(arg1) + return union_pw_multi_aff(arg0).product(arg1) ctx = arg0.ctx - res = isl.isl_aff_le_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def lt_set(arg0, arg1): + res = isl.isl_pw_multi_aff_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def pullback(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_pw_multi_aff_pullback_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_pw_multi_aff_pullback_pw_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def range_factor_domain(arg0): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_range_factor_domain(isl.isl_pw_multi_aff_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def range_factor_range(arg0): try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: - return pw_aff(arg0).lt_set(arg1) + raise ctx = arg0.ctx - res = isl.isl_aff_lt_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def mod(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_aff_mod_val(isl.isl_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return aff(ctx=arg0.ctx, ptr=res) - def mul(arg0, arg1): + res = isl.isl_pw_multi_aff_range_factor_range(isl.isl_pw_multi_aff_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def range_product(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - return pw_aff(arg0).mul(arg1) + return union_pw_multi_aff(arg0).range_product(arg1) ctx = arg0.ctx - res = isl.isl_aff_mul(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return aff(ctx=ctx, ptr=res) - def ne_set(arg0, arg1): + res = isl.isl_pw_multi_aff_range_product(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def scale(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_multi_aff_scale_val(isl.isl_pw_multi_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_multi_aff_scale_down_val(isl.isl_pw_multi_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def sub(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - return pw_aff(arg0).ne_set(arg1) + return union_pw_multi_aff(arg0).sub(arg1) ctx = arg0.ctx - res = isl.isl_aff_ne_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def neg(arg0): + res = isl.isl_pw_multi_aff_sub(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def subtract_domain(arg0, arg1): try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) - except: - raise - ctx = arg0.ctx - res = isl.isl_aff_neg(isl.isl_aff_copy(arg0.ptr)) - return aff(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_aff_pullback_multi_aff(isl.isl_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return aff(ctx=arg0.ctx, ptr=res) - def scale(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_aff_scale_val(isl.isl_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return aff(ctx=arg0.ctx, ptr=res) - def scale_down(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_aff_scale_down_val(isl.isl_aff_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return aff(ctx=arg0.ctx, ptr=res) - def sub(arg0, arg1): - try: - if not arg0.__class__ is aff: - arg0 = aff(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - return pw_aff(arg0).sub(arg1) + return union_pw_multi_aff(arg0).subtract_domain(arg1) ctx = arg0.ctx - res = isl.isl_aff_sub(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) - return aff(ctx=ctx, ptr=res) - -isl.isl_aff_read_from_str.restype = c_void_p -isl.isl_aff_read_from_str.argtypes = [Context, c_char_p] -isl.isl_aff_add.restype = c_void_p -isl.isl_aff_add.argtypes = [c_void_p, c_void_p] -isl.isl_aff_ceil.restype = c_void_p -isl.isl_aff_ceil.argtypes = [c_void_p] -isl.isl_aff_div.restype = c_void_p -isl.isl_aff_div.argtypes = [c_void_p, c_void_p] -isl.isl_aff_eq_set.restype = c_void_p -isl.isl_aff_eq_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_floor.restype = c_void_p -isl.isl_aff_floor.argtypes = [c_void_p] -isl.isl_aff_ge_set.restype = c_void_p -isl.isl_aff_ge_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_gt_set.restype = c_void_p -isl.isl_aff_gt_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_le_set.restype = c_void_p -isl.isl_aff_le_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_lt_set.restype = c_void_p -isl.isl_aff_lt_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_mod_val.restype = c_void_p -isl.isl_aff_mod_val.argtypes = [c_void_p, c_void_p] -isl.isl_aff_mul.restype = c_void_p -isl.isl_aff_mul.argtypes = [c_void_p, c_void_p] -isl.isl_aff_ne_set.restype = c_void_p -isl.isl_aff_ne_set.argtypes = [c_void_p, c_void_p] -isl.isl_aff_neg.restype = c_void_p -isl.isl_aff_neg.argtypes = [c_void_p] -isl.isl_aff_pullback_multi_aff.restype = c_void_p -isl.isl_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_aff_scale_val.restype = c_void_p -isl.isl_aff_scale_val.argtypes = [c_void_p, c_void_p] -isl.isl_aff_scale_down_val.restype = c_void_p -isl.isl_aff_scale_down_val.argtypes = [c_void_p, c_void_p] -isl.isl_aff_sub.restype = c_void_p -isl.isl_aff_sub.argtypes = [c_void_p, c_void_p] -isl.isl_aff_copy.restype = c_void_p -isl.isl_aff_copy.argtypes = [c_void_p] -isl.isl_aff_free.restype = c_void_p -isl.isl_aff_free.argtypes = [c_void_p] -isl.isl_aff_to_str.restype = POINTER(c_char) -isl.isl_aff_to_str.argtypes = [c_void_p] - -class ast_build(object): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 0: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_ast_build_alloc(self.ctx) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_ast_build_free(self.ptr) - def access_from(arg0, arg1): - if arg1.__class__ is pw_multi_aff: - res = isl.isl_ast_build_access_from_pw_multi_aff(arg0.ptr, isl.isl_pw_multi_aff_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is multi_pw_aff: - res = isl.isl_ast_build_access_from_multi_pw_aff(arg0.ptr, isl.isl_multi_pw_aff_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - def call_from(arg0, arg1): - if arg1.__class__ is pw_multi_aff: - res = isl.isl_ast_build_call_from_pw_multi_aff(arg0.ptr, isl.isl_pw_multi_aff_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is multi_pw_aff: - res = isl.isl_ast_build_call_from_multi_pw_aff(arg0.ptr, isl.isl_multi_pw_aff_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - def expr_from(arg0, arg1): - if arg1.__class__ is set: - res = isl.isl_ast_build_expr_from_set(arg0.ptr, isl.isl_set_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is pw_aff: - res = isl.isl_ast_build_expr_from_pw_aff(arg0.ptr, isl.isl_pw_aff_copy(arg1.ptr)) - return ast_expr(ctx=arg0.ctx, ptr=res) - @staticmethod - def from_context(arg0): + res = isl.isl_pw_multi_aff_subtract_domain(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def union_add(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is pw_multi_aff: + arg0 = pw_multi_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_ast_build_from_context(isl.isl_set_copy(arg0.ptr)) - return ast_build(ctx=ctx, ptr=res) - def node_from_schedule_map(arg0, arg1): try: - if not arg0.__class__ is ast_build: - arg0 = ast_build(arg0) + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) except: - raise + return union_pw_multi_aff(arg0).union_add(arg1) + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_union_add(isl.isl_pw_multi_aff_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def zero(arg0): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_ast_build_node_from_schedule_map(arg0.ptr, isl.isl_union_map_copy(arg1.ptr)) - return ast_node(ctx=ctx, ptr=res) + res = isl.isl_pw_multi_aff_zero(isl.isl_space_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj -isl.isl_ast_build_alloc.restype = c_void_p -isl.isl_ast_build_alloc.argtypes = [Context] -isl.isl_ast_build_access_from_pw_multi_aff.restype = c_void_p -isl.isl_ast_build_access_from_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_access_from_multi_pw_aff.restype = c_void_p -isl.isl_ast_build_access_from_multi_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_call_from_pw_multi_aff.restype = c_void_p -isl.isl_ast_build_call_from_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_call_from_multi_pw_aff.restype = c_void_p -isl.isl_ast_build_call_from_multi_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_expr_from_set.restype = c_void_p -isl.isl_ast_build_expr_from_set.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_expr_from_pw_aff.restype = c_void_p -isl.isl_ast_build_expr_from_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_from_context.restype = c_void_p -isl.isl_ast_build_from_context.argtypes = [c_void_p] -isl.isl_ast_build_node_from_schedule_map.restype = c_void_p -isl.isl_ast_build_node_from_schedule_map.argtypes = [c_void_p, c_void_p] -isl.isl_ast_build_copy.restype = c_void_p -isl.isl_ast_build_copy.argtypes = [c_void_p] -isl.isl_ast_build_free.restype = c_void_p -isl.isl_ast_build_free.argtypes = [c_void_p] +isl.isl_pw_multi_aff_from_multi_aff.restype = c_void_p +isl.isl_pw_multi_aff_from_multi_aff.argtypes = [c_void_p] +isl.isl_pw_multi_aff_from_pw_aff.restype = c_void_p +isl.isl_pw_multi_aff_from_pw_aff.argtypes = [c_void_p] +isl.isl_pw_multi_aff_read_from_str.restype = c_void_p +isl.isl_pw_multi_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_pw_multi_aff_add.restype = c_void_p +isl.isl_pw_multi_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_as_multi_aff.restype = c_void_p +isl.isl_pw_multi_aff_as_multi_aff.argtypes = [c_void_p] +isl.isl_pw_multi_aff_bind_domain.restype = c_void_p +isl.isl_pw_multi_aff_bind_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_bind_domain_wrapped_domain.restype = c_void_p +isl.isl_pw_multi_aff_bind_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_domain.restype = c_void_p +isl.isl_pw_multi_aff_domain.argtypes = [c_void_p] +isl.isl_pw_multi_aff_flat_range_product.restype = c_void_p +isl.isl_pw_multi_aff_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_foreach_piece.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_pw_multi_aff_get_space.restype = c_void_p +isl.isl_pw_multi_aff_get_space.argtypes = [c_void_p] +isl.isl_pw_multi_aff_gist.restype = c_void_p +isl.isl_pw_multi_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_intersect_domain.restype = c_void_p +isl.isl_pw_multi_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_intersect_params.restype = c_void_p +isl.isl_pw_multi_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_isa_multi_aff.argtypes = [c_void_p] +isl.isl_pw_multi_aff_n_piece.argtypes = [c_void_p] +isl.isl_pw_multi_aff_product.restype = c_void_p +isl.isl_pw_multi_aff_product.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_pullback_multi_aff.restype = c_void_p +isl.isl_pw_multi_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_pullback_pw_multi_aff.restype = c_void_p +isl.isl_pw_multi_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_range_factor_domain.restype = c_void_p +isl.isl_pw_multi_aff_range_factor_domain.argtypes = [c_void_p] +isl.isl_pw_multi_aff_range_factor_range.restype = c_void_p +isl.isl_pw_multi_aff_range_factor_range.argtypes = [c_void_p] +isl.isl_pw_multi_aff_range_product.restype = c_void_p +isl.isl_pw_multi_aff_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_scale_val.restype = c_void_p +isl.isl_pw_multi_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_scale_down_val.restype = c_void_p +isl.isl_pw_multi_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_sub.restype = c_void_p +isl.isl_pw_multi_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_subtract_domain.restype = c_void_p +isl.isl_pw_multi_aff_subtract_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_union_add.restype = c_void_p +isl.isl_pw_multi_aff_union_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_zero.restype = c_void_p +isl.isl_pw_multi_aff_zero.argtypes = [c_void_p] +isl.isl_pw_multi_aff_copy.restype = c_void_p +isl.isl_pw_multi_aff_copy.argtypes = [c_void_p] +isl.isl_pw_multi_aff_free.restype = c_void_p +isl.isl_pw_multi_aff_free.argtypes = [c_void_p] +isl.isl_pw_multi_aff_to_str.restype = POINTER(c_char) +isl.isl_pw_multi_aff_to_str.argtypes = [c_void_p] -class ast_expr(object): +class pw_aff(union_pw_aff, pw_multi_aff, multi_pw_aff): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_aff_from_aff(isl.isl_aff_copy(args[0].ptr)) return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_aff_read_from_str(self.ctx, args[0].encode('ascii')) + return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_ast_expr_free(self.ptr) + isl.isl_pw_aff_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is ast_expr: - arg0 = ast_expr(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ptr = isl.isl_ast_expr_to_str(arg0.ptr) + ptr = isl.isl_pw_aff_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.ast_expr("""%s""")' % s + return 'isl.pw_aff("""%s""")' % s else: - return 'isl.ast_expr("%s")' % s - def to_C_str(arg0): + return 'isl.pw_aff("%s")' % s + def add(arg0, arg1): try: - if not arg0.__class__ is ast_expr: - arg0 = ast_expr(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) + except: + return union_pw_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_ast_expr_to_C_str(arg0.ptr) - if res == 0: + res = isl.isl_pw_aff_add(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def as_aff(arg0): + try: + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) + except: raise - string = cast(res, c_char_p).value.decode('ascii') - libc.free(res) - return string - -isl.isl_ast_expr_to_C_str.restype = POINTER(c_char) -isl.isl_ast_expr_to_C_str.argtypes = [c_void_p] -isl.isl_ast_expr_copy.restype = c_void_p -isl.isl_ast_expr_copy.argtypes = [c_void_p] -isl.isl_ast_expr_free.restype = c_void_p -isl.isl_ast_expr_free.argtypes = [c_void_p] -isl.isl_ast_expr_to_str.restype = POINTER(c_char) -isl.isl_ast_expr_to_str.argtypes = [c_void_p] - -class ast_node(object): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return + ctx = arg0.ctx + res = isl.isl_pw_aff_as_aff(isl.isl_pw_aff_copy(arg0.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def bind(*args): + if len(args) == 2 and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_aff_bind_id(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_ast_node_free(self.ptr) - def __str__(arg0): + def bind_domain(arg0, arg1): try: - if not arg0.__class__ is ast_node: - arg0 = ast_node(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ptr = isl.isl_ast_node_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.ast_node("""%s""")' % s - else: - return 'isl.ast_node("%s")' % s - def to_C_str(arg0): try: - if not arg0.__class__ is ast_node: - arg0 = ast_node(arg0) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_pw_aff(arg0).bind_domain(arg1) + ctx = arg0.ctx + res = isl.isl_pw_aff_bind_domain(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def bind_domain_wrapped_domain(arg0, arg1): + try: + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_pw_aff(arg0).bind_domain_wrapped_domain(arg1) ctx = arg0.ctx - res = isl.isl_ast_node_to_C_str(arg0.ptr) - if res == 0: + res = isl.isl_pw_aff_bind_domain_wrapped_domain(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def ceil(arg0): + try: + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) + except: raise - string = cast(res, c_char_p).value.decode('ascii') - libc.free(res) - return string - -isl.isl_ast_node_to_C_str.restype = POINTER(c_char) -isl.isl_ast_node_to_C_str.argtypes = [c_void_p] -isl.isl_ast_node_copy.restype = c_void_p -isl.isl_ast_node_copy.argtypes = [c_void_p] -isl.isl_ast_node_free.restype = c_void_p -isl.isl_ast_node_free.argtypes = [c_void_p] -isl.isl_ast_node_to_str.restype = POINTER(c_char) -isl.isl_ast_node_to_str.argtypes = [c_void_p] - -class union_map(object): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 1 and args[0].__class__ is basic_map: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_map_from_basic_map(isl.isl_basic_map_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is map: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_map_from_map(isl.isl_map_copy(args[0].ptr)) - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_map_read_from_str(self.ctx, args[0].encode('ascii')) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_union_map_free(self.ptr) - def __str__(arg0): - try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) - except: - raise - ptr = isl.isl_union_map_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.union_map("""%s""")' % s - else: - return 'isl.union_map("%s")' % s - def affine_hull(arg0): + ctx = arg0.ctx + res = isl.isl_pw_aff_ceil(isl.isl_pw_aff_copy(arg0.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def cond(arg0, arg1, arg2): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_affine_hull(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def apply_domain(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).cond(arg1, arg2) try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg2.__class__ is pw_aff: + arg2 = pw_aff(arg2) except: - raise + return union_pw_aff(arg0).cond(arg1, arg2) ctx = arg0.ctx - res = isl.isl_union_map_apply_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def apply_range(arg0, arg1): + res = isl.isl_pw_aff_cond(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr), isl.isl_pw_aff_copy(arg2.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def div(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).div(arg1) ctx = arg0.ctx - res = isl.isl_union_map_apply_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def coalesce(arg0): + res = isl.isl_pw_aff_div(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def domain(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_coalesce(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def compute_divs(arg0): + res = isl.isl_pw_aff_domain(isl.isl_pw_aff_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def eq_set(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_compute_divs(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def deltas(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).eq_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_deltas(isl.isl_union_map_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_pw_aff_eq_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def eval(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_detect_equalities(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def domain(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is point: + arg1 = point(arg1) except: - raise + return union_pw_aff(arg0).eval(arg1) ctx = arg0.ctx - res = isl.isl_union_map_domain(isl.isl_union_map_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def domain_factor_domain(arg0): + res = isl.isl_pw_aff_eval(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_point_copy(arg1.ptr)) + obj = val(ctx=ctx, ptr=res) + return obj + def floor(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_domain_factor_domain(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def domain_factor_range(arg0): + res = isl.isl_pw_aff_floor(isl.isl_pw_aff_copy(arg0.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def ge_set(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_domain_factor_range(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def domain_map(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).ge_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_domain_map(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def domain_map_union_pw_multi_aff(arg0): + res = isl.isl_pw_aff_ge_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def gist(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_pw_aff(arg0).gist(arg1) ctx = arg0.ctx - res = isl.isl_union_map_domain_map_union_pw_multi_aff(isl.isl_union_map_copy(arg0.ptr)) - return union_pw_multi_aff(ctx=ctx, ptr=res) - def domain_product(arg0, arg1): + res = isl.isl_pw_aff_gist(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def gt_set(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).gt_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_domain_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def eq_at(arg0, arg1): - if arg1.__class__ is multi_union_pw_aff: - res = isl.isl_union_map_eq_at_multi_union_pw_aff(isl.isl_union_map_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) - return union_map(ctx=arg0.ctx, ptr=res) - def factor_domain(arg0): + res = isl.isl_pw_aff_gt_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_factor_domain(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def factor_range(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - raise + return union_pw_aff(arg0).intersect_domain(arg1) ctx = arg0.ctx - res = isl.isl_union_map_factor_range(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def fixed_power(arg0, arg1): - if arg1.__class__ is val: - res = isl.isl_union_map_fixed_power_val(isl.isl_union_map_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return union_map(ctx=arg0.ctx, ptr=res) - def foreach_map(arg0, arg1): + res = isl.isl_pw_aff_intersect_domain(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - exc_info = [None] - fn = CFUNCTYPE(c_int, c_void_p, c_void_p) - def cb_func(cb_arg0, cb_arg1): - cb_arg0 = map(ctx=arg0.ctx, ptr=cb_arg0) - try: - arg1(cb_arg0) - except: - import sys - exc_info[0] = sys.exc_info() - return -1 - return 0 - cb = fn(cb_func) - ctx = arg0.ctx - res = isl.isl_union_map_foreach_map(arg0.ptr, cb, None) - if exc_info[0] != None: - raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) - return res - @staticmethod - def convert_from(arg0): - if arg0.__class__ is union_pw_multi_aff: - res = isl.isl_union_map_from_union_pw_multi_aff(isl.isl_union_pw_multi_aff_copy(arg0.ptr)) - return union_map(ctx=arg0.ctx, ptr=res) - if arg0.__class__ is multi_union_pw_aff: - res = isl.isl_union_map_from_multi_union_pw_aff(isl.isl_multi_union_pw_aff_copy(arg0.ptr)) - return union_map(ctx=arg0.ctx, ptr=res) - @staticmethod - def from_domain(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - raise + return union_pw_aff(arg0).intersect_params(arg1) ctx = arg0.ctx - res = isl.isl_union_map_from_domain(isl.isl_union_set_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - @staticmethod - def from_domain_and_range(arg0, arg1): + res = isl.isl_pw_aff_intersect_params(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def isa_aff(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: + raise + ctx = arg0.ctx + res = isl.isl_pw_aff_isa_aff(arg0.ptr) + if res < 0: raise + return bool(res) + def le_set(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_from_domain_and_range(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - @staticmethod - def from_range(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).le_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_from_range(isl.isl_union_set_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def gist(arg0, arg1): + res = isl.isl_pw_aff_le_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def lt_set(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).lt_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_gist(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def gist_domain(arg0, arg1): + res = isl.isl_pw_aff_lt_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def max(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).max(arg1) ctx = arg0.ctx - res = isl.isl_union_map_gist_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def gist_params(arg0, arg1): + res = isl.isl_pw_aff_max(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def min(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).min(arg1) ctx = arg0.ctx - res = isl.isl_union_map_gist_params(isl.isl_union_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def gist_range(arg0, arg1): + res = isl.isl_pw_aff_min(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def mod(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_aff_mod_val(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def mul(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).mul(arg1) ctx = arg0.ctx - res = isl.isl_union_map_gist_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_pw_aff_mul(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def ne_set(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).ne_set(arg1) ctx = arg0.ctx - res = isl.isl_union_map_intersect(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def intersect_domain(arg0, arg1): + res = isl.isl_pw_aff_ne_set(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def neg(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_pw_aff_neg(isl.isl_pw_aff_copy(arg0.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def param_on_domain(*args): + if len(args) == 2 and args[0].__class__ is set and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_aff_param_on_domain_id(isl.isl_set_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def pullback(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_pw_aff_pullback_multi_aff(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_pw_aff_pullback_multi_pw_aff(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_multi_pw_aff_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_pw_aff_pullback_pw_multi_aff(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_aff_scale_val(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_pw_aff_scale_down_val(isl.isl_pw_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + raise Error + def sub(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) + except: + return union_pw_aff(arg0).sub(arg1) ctx = arg0.ctx - res = isl.isl_union_map_intersect_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def intersect_params(arg0, arg1): + res = isl.isl_pw_aff_sub(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def subtract_domain(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: if not arg1.__class__ is set: arg1 = set(arg1) except: - raise + return union_pw_aff(arg0).subtract_domain(arg1) ctx = arg0.ctx - res = isl.isl_union_map_intersect_params(isl.isl_union_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def intersect_range(arg0, arg1): + res = isl.isl_pw_aff_subtract_domain(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def tdiv_q(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: - raise + return union_pw_aff(arg0).tdiv_q(arg1) ctx = arg0.ctx - res = isl.isl_union_map_intersect_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def is_bijective(arg0): + res = isl.isl_pw_aff_tdiv_q(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def tdiv_r(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) + except: + return union_pw_aff(arg0).tdiv_r(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_bijective(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_empty(arg0): + res = isl.isl_pw_aff_tdiv_r(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def union_add(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is pw_aff: + arg0 = pw_aff(arg0) except: raise + try: + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) + except: + return union_pw_aff(arg0).union_add(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_empty(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_equal(arg0, arg1): + res = isl.isl_pw_aff_union_add(isl.isl_pw_aff_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + +isl.isl_pw_aff_from_aff.restype = c_void_p +isl.isl_pw_aff_from_aff.argtypes = [c_void_p] +isl.isl_pw_aff_read_from_str.restype = c_void_p +isl.isl_pw_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_pw_aff_add.restype = c_void_p +isl.isl_pw_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_as_aff.restype = c_void_p +isl.isl_pw_aff_as_aff.argtypes = [c_void_p] +isl.isl_pw_aff_bind_id.restype = c_void_p +isl.isl_pw_aff_bind_id.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_bind_domain.restype = c_void_p +isl.isl_pw_aff_bind_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_bind_domain_wrapped_domain.restype = c_void_p +isl.isl_pw_aff_bind_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_ceil.restype = c_void_p +isl.isl_pw_aff_ceil.argtypes = [c_void_p] +isl.isl_pw_aff_cond.restype = c_void_p +isl.isl_pw_aff_cond.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_pw_aff_div.restype = c_void_p +isl.isl_pw_aff_div.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_domain.restype = c_void_p +isl.isl_pw_aff_domain.argtypes = [c_void_p] +isl.isl_pw_aff_eq_set.restype = c_void_p +isl.isl_pw_aff_eq_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_eval.restype = c_void_p +isl.isl_pw_aff_eval.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_floor.restype = c_void_p +isl.isl_pw_aff_floor.argtypes = [c_void_p] +isl.isl_pw_aff_ge_set.restype = c_void_p +isl.isl_pw_aff_ge_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_gist.restype = c_void_p +isl.isl_pw_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_gt_set.restype = c_void_p +isl.isl_pw_aff_gt_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_intersect_domain.restype = c_void_p +isl.isl_pw_aff_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_intersect_params.restype = c_void_p +isl.isl_pw_aff_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_isa_aff.argtypes = [c_void_p] +isl.isl_pw_aff_le_set.restype = c_void_p +isl.isl_pw_aff_le_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_lt_set.restype = c_void_p +isl.isl_pw_aff_lt_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_max.restype = c_void_p +isl.isl_pw_aff_max.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_min.restype = c_void_p +isl.isl_pw_aff_min.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_mod_val.restype = c_void_p +isl.isl_pw_aff_mod_val.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_mul.restype = c_void_p +isl.isl_pw_aff_mul.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_ne_set.restype = c_void_p +isl.isl_pw_aff_ne_set.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_neg.restype = c_void_p +isl.isl_pw_aff_neg.argtypes = [c_void_p] +isl.isl_pw_aff_param_on_domain_id.restype = c_void_p +isl.isl_pw_aff_param_on_domain_id.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_pullback_multi_aff.restype = c_void_p +isl.isl_pw_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_pullback_multi_pw_aff.restype = c_void_p +isl.isl_pw_aff_pullback_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_pullback_pw_multi_aff.restype = c_void_p +isl.isl_pw_aff_pullback_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_scale_val.restype = c_void_p +isl.isl_pw_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_scale_down_val.restype = c_void_p +isl.isl_pw_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_sub.restype = c_void_p +isl.isl_pw_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_subtract_domain.restype = c_void_p +isl.isl_pw_aff_subtract_domain.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_tdiv_q.restype = c_void_p +isl.isl_pw_aff_tdiv_q.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_tdiv_r.restype = c_void_p +isl.isl_pw_aff_tdiv_r.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_union_add.restype = c_void_p +isl.isl_pw_aff_union_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_copy.restype = c_void_p +isl.isl_pw_aff_copy.argtypes = [c_void_p] +isl.isl_pw_aff_free.restype = c_void_p +isl.isl_pw_aff_free.argtypes = [c_void_p] +isl.isl_pw_aff_to_str.restype = POINTER(c_char) +isl.isl_pw_aff_to_str.argtypes = [c_void_p] + +class multi_aff(pw_multi_aff, multi_pw_aff): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_aff_from_aff(isl.isl_aff_copy(args[0].ptr)) + return + if len(args) == 2 and args[0].__class__ is space and args[1].__class__ is aff_list: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_aff_from_aff_list(isl.isl_space_copy(args[0].ptr), isl.isl_aff_list_copy(args[1].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_aff_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_multi_aff_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + ptr = isl.isl_multi_aff_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.multi_aff("""%s""")' % s + else: + return 'isl.multi_aff("%s")' % s + def add(arg0, arg1): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) + except: + return pw_multi_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_equal(arg0.ptr, arg1.ptr) - if res < 0: - raise - return bool(res) - def is_injective(arg0): + res = isl.isl_multi_aff_add(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def bind(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return pw_multi_aff(arg0).bind(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_injective(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_single_valued(arg0): + res = isl.isl_multi_aff_bind(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def bind_domain(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return pw_multi_aff(arg0).bind_domain(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_single_valued(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_strict_subset(arg0, arg1): + res = isl.isl_multi_aff_bind_domain(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def bind_domain_wrapped_domain(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: - raise + return pw_multi_aff(arg0).bind_domain_wrapped_domain(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_strict_subset(arg0.ptr, arg1.ptr) - if res < 0: - raise - return bool(res) - def is_subset(arg0, arg1): + res = isl.isl_multi_aff_bind_domain_wrapped_domain(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def domain_map(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_multi_aff_domain_map(isl.isl_space_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def flat_range_product(arg0, arg1): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) + except: + return pw_multi_aff(arg0).flat_range_product(arg1) ctx = arg0.ctx - res = isl.isl_union_map_is_subset(arg0.ptr, arg1.ptr) - if res < 0: - raise - return bool(res) - def lexmax(arg0): + res = isl.isl_multi_aff_flat_range_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def floor(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_lexmax(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_multi_aff_floor(isl.isl_multi_aff_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def at(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_lexmin(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def polyhedral_hull(arg0): + res = isl.isl_multi_aff_get_at(arg0.ptr, arg1) + obj = aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def space(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_polyhedral_hull(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def product(arg0, arg1): + res = isl.isl_multi_aff_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is set: + arg1 = set(arg1) except: - raise - ctx = arg0.ctx - res = isl.isl_union_map_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def project_out_all_params(arg0): + return pw_multi_aff(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_multi_aff_gist(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def identity(*args): + if len(args) == 1: + ctx = args[0].ctx + res = isl.isl_multi_aff_identity_multi_aff(isl.isl_multi_aff_copy(args[0].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + @staticmethod + def identity_on_domain(*args): + if len(args) == 1 and args[0].__class__ is space: + ctx = args[0].ctx + res = isl.isl_multi_aff_identity_on_domain_space(isl.isl_space_copy(args[0].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def involves_locals(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_project_out_all_params(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def range(arg0): + res = isl.isl_multi_aff_involves_locals(arg0.ptr) + if res < 0: + raise + return bool(res) + def neg(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_range(isl.isl_union_map_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def range_factor_domain(arg0): + res = isl.isl_multi_aff_neg(isl.isl_multi_aff_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def plain_is_equal(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) + except: + return pw_multi_aff(arg0).plain_is_equal(arg1) ctx = arg0.ctx - res = isl.isl_union_map_range_factor_domain(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def range_factor_range(arg0): + res = isl.isl_multi_aff_plain_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def product(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise + try: + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) + except: + return pw_multi_aff(arg0).product(arg1) ctx = arg0.ctx - res = isl.isl_union_map_range_factor_range(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) + res = isl.isl_multi_aff_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def pullback(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_multi_aff_pullback_multi_aff(isl.isl_multi_aff_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + @staticmethod def range_map(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_range_map(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) + res = isl.isl_multi_aff_range_map(isl.isl_space_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj def range_product(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) except: - raise + return pw_multi_aff(arg0).range_product(arg1) ctx = arg0.ctx - res = isl.isl_union_map_range_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def reverse(arg0): + res = isl.isl_multi_aff_range_product(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def scale(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_aff_scale_multi_val(isl.isl_multi_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_aff_scale_val(isl.isl_multi_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_aff_scale_down_multi_val(isl.isl_multi_aff_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_aff_scale_down_val(isl.isl_multi_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + raise Error + def set_at(arg0, arg1, arg2): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_reverse(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def subtract(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg2.__class__ is aff: + arg2 = aff(arg2) except: - raise + return pw_multi_aff(arg0).set_at(arg1, arg2) + ctx = arg0.ctx + res = isl.isl_multi_aff_set_at(isl.isl_multi_aff_copy(arg0.ptr), arg1, isl.isl_aff_copy(arg2.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def size(arg0): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_subtract(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def subtract_domain(arg0, arg1): - try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) - except: + res = isl.isl_multi_aff_size(arg0.ptr) + if res < 0: raise + return int(res) + def sub(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is multi_aff: + arg0 = multi_aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_subtract_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def subtract_range(arg0, arg1): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is multi_aff: + arg1 = multi_aff(arg1) except: - raise + return pw_multi_aff(arg0).sub(arg1) + ctx = arg0.ctx + res = isl.isl_multi_aff_sub(isl.isl_multi_aff_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + @staticmethod + def zero(arg0): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_subtract_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_multi_aff_zero(isl.isl_space_copy(arg0.ptr)) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + +isl.isl_multi_aff_from_aff.restype = c_void_p +isl.isl_multi_aff_from_aff.argtypes = [c_void_p] +isl.isl_multi_aff_from_aff_list.restype = c_void_p +isl.isl_multi_aff_from_aff_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_read_from_str.restype = c_void_p +isl.isl_multi_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_multi_aff_add.restype = c_void_p +isl.isl_multi_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_bind.restype = c_void_p +isl.isl_multi_aff_bind.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_bind_domain.restype = c_void_p +isl.isl_multi_aff_bind_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_bind_domain_wrapped_domain.restype = c_void_p +isl.isl_multi_aff_bind_domain_wrapped_domain.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_domain_map.restype = c_void_p +isl.isl_multi_aff_domain_map.argtypes = [c_void_p] +isl.isl_multi_aff_flat_range_product.restype = c_void_p +isl.isl_multi_aff_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_floor.restype = c_void_p +isl.isl_multi_aff_floor.argtypes = [c_void_p] +isl.isl_multi_aff_get_at.restype = c_void_p +isl.isl_multi_aff_get_at.argtypes = [c_void_p, c_int] +isl.isl_multi_aff_get_space.restype = c_void_p +isl.isl_multi_aff_get_space.argtypes = [c_void_p] +isl.isl_multi_aff_gist.restype = c_void_p +isl.isl_multi_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_identity_multi_aff.restype = c_void_p +isl.isl_multi_aff_identity_multi_aff.argtypes = [c_void_p] +isl.isl_multi_aff_identity_on_domain_space.restype = c_void_p +isl.isl_multi_aff_identity_on_domain_space.argtypes = [c_void_p] +isl.isl_multi_aff_involves_locals.argtypes = [c_void_p] +isl.isl_multi_aff_neg.restype = c_void_p +isl.isl_multi_aff_neg.argtypes = [c_void_p] +isl.isl_multi_aff_plain_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_product.restype = c_void_p +isl.isl_multi_aff_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_pullback_multi_aff.restype = c_void_p +isl.isl_multi_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_range_map.restype = c_void_p +isl.isl_multi_aff_range_map.argtypes = [c_void_p] +isl.isl_multi_aff_range_product.restype = c_void_p +isl.isl_multi_aff_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_scale_multi_val.restype = c_void_p +isl.isl_multi_aff_scale_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_scale_val.restype = c_void_p +isl.isl_multi_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_scale_down_multi_val.restype = c_void_p +isl.isl_multi_aff_scale_down_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_scale_down_val.restype = c_void_p +isl.isl_multi_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_set_at.restype = c_void_p +isl.isl_multi_aff_set_at.argtypes = [c_void_p, c_int, c_void_p] +isl.isl_multi_aff_size.argtypes = [c_void_p] +isl.isl_multi_aff_sub.restype = c_void_p +isl.isl_multi_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_multi_aff_zero.restype = c_void_p +isl.isl_multi_aff_zero.argtypes = [c_void_p] +isl.isl_multi_aff_copy.restype = c_void_p +isl.isl_multi_aff_copy.argtypes = [c_void_p] +isl.isl_multi_aff_free.restype = c_void_p +isl.isl_multi_aff_free.argtypes = [c_void_p] +isl.isl_multi_aff_to_str.restype = POINTER(c_char) +isl.isl_multi_aff_to_str.argtypes = [c_void_p] + +class aff(pw_aff, multi_aff): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_aff_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_aff_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg0.__class__ is aff: + arg0 = aff(arg0) except: raise + ptr = isl.isl_aff_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.aff("""%s""")' % s + else: + return 'isl.aff("%s")' % s + def add(arg0, arg1): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is aff: + arg0 = aff(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_map_union(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_map(ctx=ctx, ptr=res) - def wrap(arg0): try: - if not arg0.__class__ is union_map: - arg0 = union_map(arg0) + if not arg1.__class__ is aff: + arg1 = aff(arg1) except: - raise + return pw_aff(arg0).add(arg1) ctx = arg0.ctx - res = isl.isl_union_map_wrap(isl.isl_union_map_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def zip(arg0): - try: + res = isl.isl_aff_add(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def add_constant(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_aff_add_constant_val(isl.isl_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + raise Error + def bind(*args): + if len(args) == 2 and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_aff_bind_id(isl.isl_aff_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + raise Error + def ceil(arg0): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_ceil(isl.isl_aff_copy(arg0.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def div(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).div(arg1) + ctx = arg0.ctx + res = isl.isl_aff_div(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def eq_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).eq_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_eq_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def eval(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is point: + arg1 = point(arg1) + except: + return pw_aff(arg0).eval(arg1) + ctx = arg0.ctx + res = isl.isl_aff_eval(isl.isl_aff_copy(arg0.ptr), isl.isl_point_copy(arg1.ptr)) + obj = val(ctx=ctx, ptr=res) + return obj + def floor(arg0): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_floor(isl.isl_aff_copy(arg0.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def ge_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).ge_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_ge_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def gist(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return pw_aff(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_aff_gist(isl.isl_aff_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def gt_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).gt_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_gt_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def le_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).le_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_le_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def lt_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).lt_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_lt_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def mod(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_aff_mod_val(isl.isl_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + raise Error + def mul(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).mul(arg1) + ctx = arg0.ctx + res = isl.isl_aff_mul(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def ne_set(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).ne_set(arg1) + ctx = arg0.ctx + res = isl.isl_aff_ne_set(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def neg(arg0): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_neg(isl.isl_aff_copy(arg0.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def pullback(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_aff_pullback_multi_aff(isl.isl_aff_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_aff_scale_val(isl.isl_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_aff_scale_down_val(isl.isl_aff_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + raise Error + def sub(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return pw_aff(arg0).sub(arg1) + ctx = arg0.ctx + res = isl.isl_aff_sub(isl.isl_aff_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + def unbind_params_insert_domain(arg0, arg1): + try: + if not arg0.__class__ is aff: + arg0 = aff(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return pw_aff(arg0).unbind_params_insert_domain(arg1) + ctx = arg0.ctx + res = isl.isl_aff_unbind_params_insert_domain(isl.isl_aff_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = aff(ctx=ctx, ptr=res) + return obj + +isl.isl_aff_read_from_str.restype = c_void_p +isl.isl_aff_read_from_str.argtypes = [Context, c_char_p] +isl.isl_aff_add.restype = c_void_p +isl.isl_aff_add.argtypes = [c_void_p, c_void_p] +isl.isl_aff_add_constant_val.restype = c_void_p +isl.isl_aff_add_constant_val.argtypes = [c_void_p, c_void_p] +isl.isl_aff_bind_id.restype = c_void_p +isl.isl_aff_bind_id.argtypes = [c_void_p, c_void_p] +isl.isl_aff_ceil.restype = c_void_p +isl.isl_aff_ceil.argtypes = [c_void_p] +isl.isl_aff_div.restype = c_void_p +isl.isl_aff_div.argtypes = [c_void_p, c_void_p] +isl.isl_aff_eq_set.restype = c_void_p +isl.isl_aff_eq_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_eval.restype = c_void_p +isl.isl_aff_eval.argtypes = [c_void_p, c_void_p] +isl.isl_aff_floor.restype = c_void_p +isl.isl_aff_floor.argtypes = [c_void_p] +isl.isl_aff_ge_set.restype = c_void_p +isl.isl_aff_ge_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_gist.restype = c_void_p +isl.isl_aff_gist.argtypes = [c_void_p, c_void_p] +isl.isl_aff_gt_set.restype = c_void_p +isl.isl_aff_gt_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_le_set.restype = c_void_p +isl.isl_aff_le_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_lt_set.restype = c_void_p +isl.isl_aff_lt_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_mod_val.restype = c_void_p +isl.isl_aff_mod_val.argtypes = [c_void_p, c_void_p] +isl.isl_aff_mul.restype = c_void_p +isl.isl_aff_mul.argtypes = [c_void_p, c_void_p] +isl.isl_aff_ne_set.restype = c_void_p +isl.isl_aff_ne_set.argtypes = [c_void_p, c_void_p] +isl.isl_aff_neg.restype = c_void_p +isl.isl_aff_neg.argtypes = [c_void_p] +isl.isl_aff_pullback_multi_aff.restype = c_void_p +isl.isl_aff_pullback_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_aff_scale_val.restype = c_void_p +isl.isl_aff_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_aff_scale_down_val.restype = c_void_p +isl.isl_aff_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_aff_sub.restype = c_void_p +isl.isl_aff_sub.argtypes = [c_void_p, c_void_p] +isl.isl_aff_unbind_params_insert_domain.restype = c_void_p +isl.isl_aff_unbind_params_insert_domain.argtypes = [c_void_p, c_void_p] +isl.isl_aff_copy.restype = c_void_p +isl.isl_aff_copy.argtypes = [c_void_p] +isl.isl_aff_free.restype = c_void_p +isl.isl_aff_free.argtypes = [c_void_p] +isl.isl_aff_to_str.restype = POINTER(c_char) +isl.isl_aff_to_str.argtypes = [c_void_p] + +class aff_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_aff_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and args[0].__class__ is aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_aff_list_from_aff(isl.isl_aff_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_aff_list_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + ptr = isl.isl_aff_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.aff_list("""%s""")' % s + else: + return 'isl.aff_list("%s")' % s + def add(arg0, arg1): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_list_add(isl.isl_aff_list_copy(arg0.ptr), isl.isl_aff_copy(arg1.ptr)) + obj = aff_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_list_clear(isl.isl_aff_list_copy(arg0.ptr)) + obj = aff_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + try: + if not arg1.__class__ is aff_list: + arg1 = aff_list(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_list_concat(isl.isl_aff_list_copy(arg0.ptr), isl.isl_aff_list_copy(arg1.ptr)) + obj = aff_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = aff(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_aff_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_list_get_at(arg0.ptr, arg1) + obj = aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): + try: + if not arg0.__class__ is aff_list: + arg0 = aff_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_aff_list_size(arg0.ptr) + if res < 0: + raise + return int(res) + +isl.isl_aff_list_alloc.restype = c_void_p +isl.isl_aff_list_alloc.argtypes = [Context, c_int] +isl.isl_aff_list_from_aff.restype = c_void_p +isl.isl_aff_list_from_aff.argtypes = [c_void_p] +isl.isl_aff_list_add.restype = c_void_p +isl.isl_aff_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_aff_list_clear.restype = c_void_p +isl.isl_aff_list_clear.argtypes = [c_void_p] +isl.isl_aff_list_concat.restype = c_void_p +isl.isl_aff_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_aff_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_aff_list_get_at.restype = c_void_p +isl.isl_aff_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_aff_list_size.argtypes = [c_void_p] +isl.isl_aff_list_copy.restype = c_void_p +isl.isl_aff_list_copy.argtypes = [c_void_p] +isl.isl_aff_list_free.restype = c_void_p +isl.isl_aff_list_free.argtypes = [c_void_p] +isl.isl_aff_list_to_str.restype = POINTER(c_char) +isl.isl_aff_list_to_str.argtypes = [c_void_p] + +class ast_build(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 0: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_ast_build_alloc(self.ctx) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_build_free(self.ptr) + def copy_callbacks(self, obj): + if hasattr(obj, 'at_each_domain'): + self.at_each_domain = obj.at_each_domain + def set_at_each_domain(arg0, arg1): + try: + if not arg0.__class__ is ast_build: + arg0 = ast_build(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_void_p, c_void_p, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1, cb_arg2): + cb_arg0 = ast_node(ctx=arg0.ctx, ptr=(cb_arg0)) + cb_arg1 = ast_build(ctx=arg0.ctx, ptr=isl.isl_ast_build_copy(cb_arg1)) + try: + res = arg1(cb_arg0, cb_arg1) + except: + import sys + exc_info[0] = sys.exc_info() + return None + return isl.isl_ast_node_copy(res.ptr) + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_ast_build_set_at_each_domain(isl.isl_ast_build_copy(arg0.ptr), cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if hasattr(arg0, 'at_each_domain') and arg0.at_each_domain['exc_info'] != None: + exc_info = arg0.at_each_domain['exc_info'][0] + arg0.at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_build(ctx=ctx, ptr=res) + obj.copy_callbacks(arg0) + obj.at_each_domain = { 'func': cb, 'exc_info': exc_info } + return obj + def access_from(*args): + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_ast_build_access_from_multi_pw_aff(args[0].ptr, isl.isl_multi_pw_aff_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_ast_build_access_from_pw_multi_aff(args[0].ptr, isl.isl_pw_multi_aff_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + raise Error + def call_from(*args): + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_ast_build_call_from_multi_pw_aff(args[0].ptr, isl.isl_multi_pw_aff_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_ast_build_call_from_pw_multi_aff(args[0].ptr, isl.isl_pw_multi_aff_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + raise Error + def expr_from(*args): + if len(args) == 2 and args[1].__class__ is pw_aff: + ctx = args[0].ctx + res = isl.isl_ast_build_expr_from_pw_aff(args[0].ptr, isl.isl_pw_aff_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is set: + ctx = args[0].ctx + res = isl.isl_ast_build_expr_from_set(args[0].ptr, isl.isl_set_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + raise Error + @staticmethod + def from_context(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_build_from_context(isl.isl_set_copy(arg0.ptr)) + obj = ast_build(ctx=ctx, ptr=res) + return obj + def schedule(arg0): + try: + if not arg0.__class__ is ast_build: + arg0 = ast_build(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_build_get_schedule(arg0.ptr) + if hasattr(arg0, 'at_each_domain') and arg0.at_each_domain['exc_info'] != None: + exc_info = arg0.at_each_domain['exc_info'][0] + arg0.at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_schedule(arg0): + return arg0.schedule() + def node_from(*args): + if len(args) == 2 and args[1].__class__ is schedule: + ctx = args[0].ctx + res = isl.isl_ast_build_node_from_schedule(args[0].ptr, isl.isl_schedule_copy(args[1].ptr)) + if hasattr(args[0], 'at_each_domain') and args[0].at_each_domain['exc_info'] != None: + exc_info = args[0].at_each_domain['exc_info'][0] + args[0].at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_node(ctx=ctx, ptr=res) + return obj + raise Error + def node_from_schedule_map(arg0, arg1): + try: + if not arg0.__class__ is ast_build: + arg0 = ast_build(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_build_node_from_schedule_map(arg0.ptr, isl.isl_union_map_copy(arg1.ptr)) + if hasattr(arg0, 'at_each_domain') and arg0.at_each_domain['exc_info'] != None: + exc_info = arg0.at_each_domain['exc_info'][0] + arg0.at_each_domain['exc_info'][0] = None + if exc_info != None: + raise (exc_info[0], exc_info[1], exc_info[2]) + obj = ast_node(ctx=ctx, ptr=res) + return obj + +isl.isl_ast_build_alloc.restype = c_void_p +isl.isl_ast_build_alloc.argtypes = [Context] +isl.isl_ast_build_set_at_each_domain.restype = c_void_p +isl.isl_ast_build_set_at_each_domain.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_ast_build_access_from_multi_pw_aff.restype = c_void_p +isl.isl_ast_build_access_from_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_access_from_pw_multi_aff.restype = c_void_p +isl.isl_ast_build_access_from_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_call_from_multi_pw_aff.restype = c_void_p +isl.isl_ast_build_call_from_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_call_from_pw_multi_aff.restype = c_void_p +isl.isl_ast_build_call_from_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_expr_from_pw_aff.restype = c_void_p +isl.isl_ast_build_expr_from_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_expr_from_set.restype = c_void_p +isl.isl_ast_build_expr_from_set.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_from_context.restype = c_void_p +isl.isl_ast_build_from_context.argtypes = [c_void_p] +isl.isl_ast_build_get_schedule.restype = c_void_p +isl.isl_ast_build_get_schedule.argtypes = [c_void_p] +isl.isl_ast_build_node_from_schedule.restype = c_void_p +isl.isl_ast_build_node_from_schedule.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_node_from_schedule_map.restype = c_void_p +isl.isl_ast_build_node_from_schedule_map.argtypes = [c_void_p, c_void_p] +isl.isl_ast_build_copy.restype = c_void_p +isl.isl_ast_build_copy.argtypes = [c_void_p] +isl.isl_ast_build_free.restype = c_void_p +isl.isl_ast_build_free.argtypes = [c_void_p] + +class ast_expr(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and isinstance(args[0], ast_expr_op): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_id): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_int): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + if "ptr" in keywords: + type = isl.isl_ast_expr_get_type(keywords["ptr"]) + if type == 0: + return ast_expr_op(**keywords) + if type == 1: + return ast_expr_id(**keywords) + if type == 2: + return ast_expr_int(**keywords) + raise + return super(ast_expr, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr("""%s""")' % s + else: + return 'isl.ast_expr("%s")' % s + def to_C_str(arg0): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_expr_to_C_str(arg0.ptr) + if res == 0: + raise + string = cast(res, c_char_p).value.decode('ascii') + libc.free(res) + return string + +isl.isl_ast_expr_to_C_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_C_str.argtypes = [c_void_p] +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] +isl.isl_ast_expr_get_type.argtypes = [c_void_p] + +class ast_expr_id(ast_expr): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_id, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_id: + arg0 = ast_expr_id(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_id("""%s""")' % s + else: + return 'isl.ast_expr_id("%s")' % s + def id(arg0): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_expr_id_get_id(arg0.ptr) + obj = id(ctx=ctx, ptr=res) + return obj + def get_id(arg0): + return arg0.id() + +isl.isl_ast_expr_id_get_id.restype = c_void_p +isl.isl_ast_expr_id_get_id.argtypes = [c_void_p] +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_int(ast_expr): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_int, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_int: + arg0 = ast_expr_int(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_int("""%s""")' % s + else: + return 'isl.ast_expr_int("%s")' % s + def val(arg0): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_expr_int_get_val(arg0.ptr) + obj = val(ctx=ctx, ptr=res) + return obj + def get_val(arg0): + return arg0.val() + +isl.isl_ast_expr_int_get_val.restype = c_void_p +isl.isl_ast_expr_int_get_val.argtypes = [c_void_p] +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op(ast_expr): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_and): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_and_then): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_or): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_or_else): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_max): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_min): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_minus): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_add): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_sub): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_mul): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_div): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_fdiv_q): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_pdiv_q): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_pdiv_r): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_zdiv_r): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_cond): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_select): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_eq): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_le): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_lt): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_ge): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_gt): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_call): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_access): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_member): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_expr_op_address_of): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_expr_copy(args[0].ptr) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + if "ptr" in keywords: + type = isl.isl_ast_expr_op_get_type(keywords["ptr"]) + if type == 0: + return ast_expr_op_and(**keywords) + if type == 1: + return ast_expr_op_and_then(**keywords) + if type == 2: + return ast_expr_op_or(**keywords) + if type == 3: + return ast_expr_op_or_else(**keywords) + if type == 4: + return ast_expr_op_max(**keywords) + if type == 5: + return ast_expr_op_min(**keywords) + if type == 6: + return ast_expr_op_minus(**keywords) + if type == 7: + return ast_expr_op_add(**keywords) + if type == 8: + return ast_expr_op_sub(**keywords) + if type == 9: + return ast_expr_op_mul(**keywords) + if type == 10: + return ast_expr_op_div(**keywords) + if type == 11: + return ast_expr_op_fdiv_q(**keywords) + if type == 12: + return ast_expr_op_pdiv_q(**keywords) + if type == 13: + return ast_expr_op_pdiv_r(**keywords) + if type == 14: + return ast_expr_op_zdiv_r(**keywords) + if type == 15: + return ast_expr_op_cond(**keywords) + if type == 16: + return ast_expr_op_select(**keywords) + if type == 17: + return ast_expr_op_eq(**keywords) + if type == 18: + return ast_expr_op_le(**keywords) + if type == 19: + return ast_expr_op_lt(**keywords) + if type == 20: + return ast_expr_op_ge(**keywords) + if type == 21: + return ast_expr_op_gt(**keywords) + if type == 22: + return ast_expr_op_call(**keywords) + if type == 23: + return ast_expr_op_access(**keywords) + if type == 24: + return ast_expr_op_member(**keywords) + if type == 25: + return ast_expr_op_address_of(**keywords) + raise + return super(ast_expr_op, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op: + arg0 = ast_expr_op(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op("""%s""")' % s + else: + return 'isl.ast_expr_op("%s")' % s + def arg(arg0, arg1): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_expr_op_get_arg(arg0.ptr, arg1) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_arg(arg0, arg1): + return arg0.arg(arg1) + def n_arg(arg0): + try: + if not arg0.__class__ is ast_expr: + arg0 = ast_expr(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_expr_op_get_n_arg(arg0.ptr) + if res < 0: + raise + return int(res) + def get_n_arg(arg0): + return arg0.n_arg() + +isl.isl_ast_expr_op_get_arg.restype = c_void_p +isl.isl_ast_expr_op_get_arg.argtypes = [c_void_p, c_int] +isl.isl_ast_expr_op_get_n_arg.argtypes = [c_void_p] +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] +isl.isl_ast_expr_op_get_type.argtypes = [c_void_p] + +class ast_expr_op_access(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_access, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_access: + arg0 = ast_expr_op_access(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_access("""%s""")' % s + else: + return 'isl.ast_expr_op_access("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_add(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_add, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_add: + arg0 = ast_expr_op_add(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_add("""%s""")' % s + else: + return 'isl.ast_expr_op_add("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_address_of(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_address_of, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_address_of: + arg0 = ast_expr_op_address_of(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_address_of("""%s""")' % s + else: + return 'isl.ast_expr_op_address_of("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_and(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_and, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_and: + arg0 = ast_expr_op_and(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_and("""%s""")' % s + else: + return 'isl.ast_expr_op_and("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_and_then(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_and_then, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_and_then: + arg0 = ast_expr_op_and_then(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_and_then("""%s""")' % s + else: + return 'isl.ast_expr_op_and_then("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_call(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_call, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_call: + arg0 = ast_expr_op_call(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_call("""%s""")' % s + else: + return 'isl.ast_expr_op_call("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_cond(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_cond, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_cond: + arg0 = ast_expr_op_cond(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_cond("""%s""")' % s + else: + return 'isl.ast_expr_op_cond("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_div(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_div, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_div: + arg0 = ast_expr_op_div(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_div("""%s""")' % s + else: + return 'isl.ast_expr_op_div("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_eq(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_eq, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_eq: + arg0 = ast_expr_op_eq(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_eq("""%s""")' % s + else: + return 'isl.ast_expr_op_eq("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_fdiv_q(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_fdiv_q, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_fdiv_q: + arg0 = ast_expr_op_fdiv_q(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_fdiv_q("""%s""")' % s + else: + return 'isl.ast_expr_op_fdiv_q("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_ge(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_ge, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_ge: + arg0 = ast_expr_op_ge(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_ge("""%s""")' % s + else: + return 'isl.ast_expr_op_ge("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_gt(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_gt, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_gt: + arg0 = ast_expr_op_gt(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_gt("""%s""")' % s + else: + return 'isl.ast_expr_op_gt("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_le(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_le, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_le: + arg0 = ast_expr_op_le(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_le("""%s""")' % s + else: + return 'isl.ast_expr_op_le("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_lt(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_lt, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_lt: + arg0 = ast_expr_op_lt(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_lt("""%s""")' % s + else: + return 'isl.ast_expr_op_lt("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_max(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_max, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_max: + arg0 = ast_expr_op_max(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_max("""%s""")' % s + else: + return 'isl.ast_expr_op_max("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_member(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_member, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_member: + arg0 = ast_expr_op_member(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_member("""%s""")' % s + else: + return 'isl.ast_expr_op_member("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_min(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_min, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_min: + arg0 = ast_expr_op_min(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_min("""%s""")' % s + else: + return 'isl.ast_expr_op_min("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_minus(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_minus, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_minus: + arg0 = ast_expr_op_minus(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_minus("""%s""")' % s + else: + return 'isl.ast_expr_op_minus("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_mul(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_mul, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_mul: + arg0 = ast_expr_op_mul(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_mul("""%s""")' % s + else: + return 'isl.ast_expr_op_mul("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_or(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_or, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_or: + arg0 = ast_expr_op_or(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_or("""%s""")' % s + else: + return 'isl.ast_expr_op_or("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_or_else(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_or_else, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_or_else: + arg0 = ast_expr_op_or_else(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_or_else("""%s""")' % s + else: + return 'isl.ast_expr_op_or_else("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_pdiv_q(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_pdiv_q, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_pdiv_q: + arg0 = ast_expr_op_pdiv_q(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_pdiv_q("""%s""")' % s + else: + return 'isl.ast_expr_op_pdiv_q("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_pdiv_r(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_pdiv_r, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_pdiv_r: + arg0 = ast_expr_op_pdiv_r(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_pdiv_r("""%s""")' % s + else: + return 'isl.ast_expr_op_pdiv_r("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_select(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_select, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_select: + arg0 = ast_expr_op_select(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_select("""%s""")' % s + else: + return 'isl.ast_expr_op_select("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_sub(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_sub, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_sub: + arg0 = ast_expr_op_sub(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_sub("""%s""")' % s + else: + return 'isl.ast_expr_op_sub("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_expr_op_zdiv_r(ast_expr_op): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_expr_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_expr_op_zdiv_r, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_expr_op_zdiv_r: + arg0 = ast_expr_op_zdiv_r(arg0) + except: + raise + ptr = isl.isl_ast_expr_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_expr_op_zdiv_r("""%s""")' % s + else: + return 'isl.ast_expr_op_zdiv_r("%s")' % s + +isl.isl_ast_expr_copy.restype = c_void_p +isl.isl_ast_expr_copy.argtypes = [c_void_p] +isl.isl_ast_expr_free.restype = c_void_p +isl.isl_ast_expr_free.argtypes = [c_void_p] +isl.isl_ast_expr_to_str.restype = POINTER(c_char) +isl.isl_ast_expr_to_str.argtypes = [c_void_p] + +class ast_node(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and isinstance(args[0], ast_node_for): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_node_if): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_node_block): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_node_mark): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], ast_node_user): + self.ctx = args[0].ctx + self.ptr = isl.isl_ast_node_copy(args[0].ptr) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + if "ptr" in keywords: + type = isl.isl_ast_node_get_type(keywords["ptr"]) + if type == 1: + return ast_node_for(**keywords) + if type == 2: + return ast_node_if(**keywords) + if type == 3: + return ast_node_block(**keywords) + if type == 4: + return ast_node_mark(**keywords) + if type == 5: + return ast_node_user(**keywords) + raise + return super(ast_node, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node("""%s""")' % s + else: + return 'isl.ast_node("%s")' % s + def to_C_str(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_to_C_str(arg0.ptr) + if res == 0: + raise + string = cast(res, c_char_p).value.decode('ascii') + libc.free(res) + return string + +isl.isl_ast_node_to_C_str.restype = POINTER(c_char) +isl.isl_ast_node_to_C_str.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] +isl.isl_ast_node_get_type.argtypes = [c_void_p] + +class ast_node_block(ast_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_node_block, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_block: + arg0 = ast_node_block(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_block("""%s""")' % s + else: + return 'isl.ast_node_block("%s")' % s + def children(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_block_get_children(arg0.ptr) + obj = ast_node_list(ctx=ctx, ptr=res) + return obj + def get_children(arg0): + return arg0.children() + +isl.isl_ast_node_block_get_children.restype = c_void_p +isl.isl_ast_node_block_get_children.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] + +class ast_node_for(ast_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_node_for, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_for: + arg0 = ast_node_for(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_for("""%s""")' % s + else: + return 'isl.ast_node_for("%s")' % s + def body(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_get_body(arg0.ptr) + obj = ast_node(ctx=ctx, ptr=res) + return obj + def get_body(arg0): + return arg0.body() + def cond(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_get_cond(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_cond(arg0): + return arg0.cond() + def inc(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_get_inc(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_inc(arg0): + return arg0.inc() + def init(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_get_init(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_init(arg0): + return arg0.init() + def iterator(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_get_iterator(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_iterator(arg0): + return arg0.iterator() + def is_degenerate(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_for_is_degenerate(arg0.ptr) + if res < 0: + raise + return bool(res) + +isl.isl_ast_node_for_get_body.restype = c_void_p +isl.isl_ast_node_for_get_body.argtypes = [c_void_p] +isl.isl_ast_node_for_get_cond.restype = c_void_p +isl.isl_ast_node_for_get_cond.argtypes = [c_void_p] +isl.isl_ast_node_for_get_inc.restype = c_void_p +isl.isl_ast_node_for_get_inc.argtypes = [c_void_p] +isl.isl_ast_node_for_get_init.restype = c_void_p +isl.isl_ast_node_for_get_init.argtypes = [c_void_p] +isl.isl_ast_node_for_get_iterator.restype = c_void_p +isl.isl_ast_node_for_get_iterator.argtypes = [c_void_p] +isl.isl_ast_node_for_is_degenerate.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] + +class ast_node_if(ast_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_node_if, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_if: + arg0 = ast_node_if(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_if("""%s""")' % s + else: + return 'isl.ast_node_if("%s")' % s + def cond(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_if_get_cond(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_cond(arg0): + return arg0.cond() + def else_node(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_if_get_else_node(arg0.ptr) + obj = ast_node(ctx=ctx, ptr=res) + return obj + def get_else_node(arg0): + return arg0.else_node() + def then_node(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_if_get_then_node(arg0.ptr) + obj = ast_node(ctx=ctx, ptr=res) + return obj + def get_then_node(arg0): + return arg0.then_node() + def has_else_node(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_if_has_else_node(arg0.ptr) + if res < 0: + raise + return bool(res) + +isl.isl_ast_node_if_get_cond.restype = c_void_p +isl.isl_ast_node_if_get_cond.argtypes = [c_void_p] +isl.isl_ast_node_if_get_else_node.restype = c_void_p +isl.isl_ast_node_if_get_else_node.argtypes = [c_void_p] +isl.isl_ast_node_if_get_then_node.restype = c_void_p +isl.isl_ast_node_if_get_then_node.argtypes = [c_void_p] +isl.isl_ast_node_if_has_else_node.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] + +class ast_node_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_ast_node_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and args[0].__class__ is ast_node: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_ast_node_list_from_ast_node(isl.isl_ast_node_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_list_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + ptr = isl.isl_ast_node_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_list("""%s""")' % s + else: + return 'isl.ast_node_list("%s")' % s + def add(arg0, arg1): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + try: + if not arg1.__class__ is ast_node: + arg1 = ast_node(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_list_add(isl.isl_ast_node_list_copy(arg0.ptr), isl.isl_ast_node_copy(arg1.ptr)) + obj = ast_node_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_list_clear(isl.isl_ast_node_list_copy(arg0.ptr)) + obj = ast_node_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + try: + if not arg1.__class__ is ast_node_list: + arg1 = ast_node_list(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_list_concat(isl.isl_ast_node_list_copy(arg0.ptr), isl.isl_ast_node_list_copy(arg1.ptr)) + obj = ast_node_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = ast_node(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_ast_node_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_list_get_at(arg0.ptr, arg1) + obj = ast_node(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): + try: + if not arg0.__class__ is ast_node_list: + arg0 = ast_node_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_list_size(arg0.ptr) + if res < 0: + raise + return int(res) + +isl.isl_ast_node_list_alloc.restype = c_void_p +isl.isl_ast_node_list_alloc.argtypes = [Context, c_int] +isl.isl_ast_node_list_from_ast_node.restype = c_void_p +isl.isl_ast_node_list_from_ast_node.argtypes = [c_void_p] +isl.isl_ast_node_list_add.restype = c_void_p +isl.isl_ast_node_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_ast_node_list_clear.restype = c_void_p +isl.isl_ast_node_list_clear.argtypes = [c_void_p] +isl.isl_ast_node_list_concat.restype = c_void_p +isl.isl_ast_node_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_ast_node_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_ast_node_list_get_at.restype = c_void_p +isl.isl_ast_node_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_ast_node_list_size.argtypes = [c_void_p] +isl.isl_ast_node_list_copy.restype = c_void_p +isl.isl_ast_node_list_copy.argtypes = [c_void_p] +isl.isl_ast_node_list_free.restype = c_void_p +isl.isl_ast_node_list_free.argtypes = [c_void_p] +isl.isl_ast_node_list_to_str.restype = POINTER(c_char) +isl.isl_ast_node_list_to_str.argtypes = [c_void_p] + +class ast_node_mark(ast_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_node_mark, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_mark: + arg0 = ast_node_mark(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_mark("""%s""")' % s + else: + return 'isl.ast_node_mark("%s")' % s + def id(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_mark_get_id(arg0.ptr) + obj = id(ctx=ctx, ptr=res) + return obj + def get_id(arg0): + return arg0.id() + def node(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_mark_get_node(arg0.ptr) + obj = ast_node(ctx=ctx, ptr=res) + return obj + def get_node(arg0): + return arg0.node() + +isl.isl_ast_node_mark_get_id.restype = c_void_p +isl.isl_ast_node_mark_get_id.argtypes = [c_void_p] +isl.isl_ast_node_mark_get_node.restype = c_void_p +isl.isl_ast_node_mark_get_node.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] + +class ast_node_user(ast_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_ast_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(ast_node_user, cls).__new__(cls) + def __str__(arg0): + try: + if not arg0.__class__ is ast_node_user: + arg0 = ast_node_user(arg0) + except: + raise + ptr = isl.isl_ast_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.ast_node_user("""%s""")' % s + else: + return 'isl.ast_node_user("%s")' % s + def expr(arg0): + try: + if not arg0.__class__ is ast_node: + arg0 = ast_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_ast_node_user_get_expr(arg0.ptr) + obj = ast_expr(ctx=ctx, ptr=res) + return obj + def get_expr(arg0): + return arg0.expr() + +isl.isl_ast_node_user_get_expr.restype = c_void_p +isl.isl_ast_node_user_get_expr.argtypes = [c_void_p] +isl.isl_ast_node_copy.restype = c_void_p +isl.isl_ast_node_copy.argtypes = [c_void_p] +isl.isl_ast_node_free.restype = c_void_p +isl.isl_ast_node_free.argtypes = [c_void_p] +isl.isl_ast_node_to_str.restype = POINTER(c_char) +isl.isl_ast_node_to_str.argtypes = [c_void_p] + +class union_map(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is basic_map: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_map_from_basic_map(isl.isl_basic_map_copy(args[0].ptr)) + return + if len(args) == 1 and args[0].__class__ is map: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_map_from_map(isl.isl_map_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_map_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_union_map_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ptr = isl.isl_union_map_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.union_map("""%s""")' % s + else: + return 'isl.union_map("%s")' % s + def affine_hull(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_affine_hull(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def apply_domain(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_apply_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def apply_range(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_apply_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def bind_range(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_bind_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def coalesce(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_coalesce(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def compute_divs(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_compute_divs(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def curry(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_curry(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def deltas(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_deltas(isl.isl_union_map_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_detect_equalities(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def domain(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain(isl.isl_union_map_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def domain_factor_domain(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain_factor_domain(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def domain_factor_range(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain_factor_range(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def domain_map(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain_map(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def domain_map_union_pw_multi_aff(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain_map_union_pw_multi_aff(isl.isl_union_map_copy(arg0.ptr)) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def domain_product(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_domain_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + @staticmethod + def empty(*args): + if len(args) == 0: + ctx = Context.getDefaultInstance() + res = isl.isl_union_map_empty_ctx(ctx) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + def eq_at(*args): + if len(args) == 2 and args[1].__class__ is multi_union_pw_aff: + ctx = args[0].ctx + res = isl.isl_union_map_eq_at_multi_union_pw_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_multi_union_pw_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + def every_map(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = map(ctx=arg0.ctx, ptr=isl.isl_map_copy(cb_arg0)) + try: + res = arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 1 if res else 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_union_map_every_map(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + return bool(res) + def extract_map(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is space: + arg1 = space(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_extract_map(arg0.ptr, isl.isl_space_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def factor_domain(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_factor_domain(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def factor_range(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_factor_range(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def fixed_power(*args): + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_union_map_fixed_power_val(isl.isl_union_map_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + def foreach_map(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = map(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_union_map_foreach_map(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + @staticmethod + def convert_from(*args): + if len(args) == 1 and args[0].__class__ is multi_union_pw_aff: + ctx = args[0].ctx + res = isl.isl_union_map_from_multi_union_pw_aff(isl.isl_multi_union_pw_aff_copy(args[0].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 1 and args[0].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_from_union_pw_multi_aff(isl.isl_union_pw_multi_aff_copy(args[0].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + @staticmethod + def from_domain(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_from_domain(isl.isl_union_set_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + @staticmethod + def from_domain_and_range(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_from_domain_and_range(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + @staticmethod + def from_range(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_from_range(isl.isl_union_set_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def space(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_gist(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def gist_domain(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_gist_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def gist_params(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_gist_params(isl.isl_union_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def gist_range(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_gist_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_intersect(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_intersect_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_intersect_params(isl.isl_union_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def intersect_range(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_intersect_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def is_bijective(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_bijective(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_disjoint(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_disjoint(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_empty(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_injective(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_injective(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_single_valued(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_single_valued(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_strict_subset(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_strict_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def isa_map(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_isa_map(arg0.ptr) + if res < 0: + raise + return bool(res) + def lexmax(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_lexmax(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_lexmin(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def polyhedral_hull(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_polyhedral_hull(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def preimage_domain(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_domain_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_domain_multi_pw_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_multi_pw_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_domain_pw_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_domain_union_pw_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + def preimage_range(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_range_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_range_pw_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_map_preimage_range_union_pw_multi_aff(isl.isl_union_map_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + raise Error + def product(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def project_out_all_params(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_project_out_all_params(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def range(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_range(isl.isl_union_map_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def range_factor_domain(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_range_factor_domain(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def range_factor_range(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_range_factor_range(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def range_map(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_range_map(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def range_product(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_range_product(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def reverse(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_reverse(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def subtract(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_subtract(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def subtract_domain(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_subtract_domain(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def subtract_range(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_subtract_range(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def uncurry(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_uncurry(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_union(isl.isl_union_map_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def universe(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_universe(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def wrap(arg0): + try: + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_wrap(isl.isl_union_map_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def zip(arg0): + try: if not arg0.__class__ is union_map: arg0 = union_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_map_zip(isl.isl_union_map_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + +isl.isl_union_map_from_basic_map.restype = c_void_p +isl.isl_union_map_from_basic_map.argtypes = [c_void_p] +isl.isl_union_map_from_map.restype = c_void_p +isl.isl_union_map_from_map.argtypes = [c_void_p] +isl.isl_union_map_read_from_str.restype = c_void_p +isl.isl_union_map_read_from_str.argtypes = [Context, c_char_p] +isl.isl_union_map_affine_hull.restype = c_void_p +isl.isl_union_map_affine_hull.argtypes = [c_void_p] +isl.isl_union_map_apply_domain.restype = c_void_p +isl.isl_union_map_apply_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_apply_range.restype = c_void_p +isl.isl_union_map_apply_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_bind_range.restype = c_void_p +isl.isl_union_map_bind_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_coalesce.restype = c_void_p +isl.isl_union_map_coalesce.argtypes = [c_void_p] +isl.isl_union_map_compute_divs.restype = c_void_p +isl.isl_union_map_compute_divs.argtypes = [c_void_p] +isl.isl_union_map_curry.restype = c_void_p +isl.isl_union_map_curry.argtypes = [c_void_p] +isl.isl_union_map_deltas.restype = c_void_p +isl.isl_union_map_deltas.argtypes = [c_void_p] +isl.isl_union_map_detect_equalities.restype = c_void_p +isl.isl_union_map_detect_equalities.argtypes = [c_void_p] +isl.isl_union_map_domain.restype = c_void_p +isl.isl_union_map_domain.argtypes = [c_void_p] +isl.isl_union_map_domain_factor_domain.restype = c_void_p +isl.isl_union_map_domain_factor_domain.argtypes = [c_void_p] +isl.isl_union_map_domain_factor_range.restype = c_void_p +isl.isl_union_map_domain_factor_range.argtypes = [c_void_p] +isl.isl_union_map_domain_map.restype = c_void_p +isl.isl_union_map_domain_map.argtypes = [c_void_p] +isl.isl_union_map_domain_map_union_pw_multi_aff.restype = c_void_p +isl.isl_union_map_domain_map_union_pw_multi_aff.argtypes = [c_void_p] +isl.isl_union_map_domain_product.restype = c_void_p +isl.isl_union_map_domain_product.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_empty_ctx.restype = c_void_p +isl.isl_union_map_empty_ctx.argtypes = [Context] +isl.isl_union_map_eq_at_multi_union_pw_aff.restype = c_void_p +isl.isl_union_map_eq_at_multi_union_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_every_map.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_map_extract_map.restype = c_void_p +isl.isl_union_map_extract_map.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_factor_domain.restype = c_void_p +isl.isl_union_map_factor_domain.argtypes = [c_void_p] +isl.isl_union_map_factor_range.restype = c_void_p +isl.isl_union_map_factor_range.argtypes = [c_void_p] +isl.isl_union_map_fixed_power_val.restype = c_void_p +isl.isl_union_map_fixed_power_val.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_foreach_map.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_map_from_multi_union_pw_aff.restype = c_void_p +isl.isl_union_map_from_multi_union_pw_aff.argtypes = [c_void_p] +isl.isl_union_map_from_union_pw_multi_aff.restype = c_void_p +isl.isl_union_map_from_union_pw_multi_aff.argtypes = [c_void_p] +isl.isl_union_map_from_domain.restype = c_void_p +isl.isl_union_map_from_domain.argtypes = [c_void_p] +isl.isl_union_map_from_domain_and_range.restype = c_void_p +isl.isl_union_map_from_domain_and_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_from_range.restype = c_void_p +isl.isl_union_map_from_range.argtypes = [c_void_p] +isl.isl_union_map_get_space.restype = c_void_p +isl.isl_union_map_get_space.argtypes = [c_void_p] +isl.isl_union_map_gist.restype = c_void_p +isl.isl_union_map_gist.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_gist_domain.restype = c_void_p +isl.isl_union_map_gist_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_gist_params.restype = c_void_p +isl.isl_union_map_gist_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_gist_range.restype = c_void_p +isl.isl_union_map_gist_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_intersect.restype = c_void_p +isl.isl_union_map_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_intersect_domain.restype = c_void_p +isl.isl_union_map_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_intersect_params.restype = c_void_p +isl.isl_union_map_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_intersect_range.restype = c_void_p +isl.isl_union_map_intersect_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_is_bijective.argtypes = [c_void_p] +isl.isl_union_map_is_disjoint.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_is_empty.argtypes = [c_void_p] +isl.isl_union_map_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_is_injective.argtypes = [c_void_p] +isl.isl_union_map_is_single_valued.argtypes = [c_void_p] +isl.isl_union_map_is_strict_subset.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_isa_map.argtypes = [c_void_p] +isl.isl_union_map_lexmax.restype = c_void_p +isl.isl_union_map_lexmax.argtypes = [c_void_p] +isl.isl_union_map_lexmin.restype = c_void_p +isl.isl_union_map_lexmin.argtypes = [c_void_p] +isl.isl_union_map_polyhedral_hull.restype = c_void_p +isl.isl_union_map_polyhedral_hull.argtypes = [c_void_p] +isl.isl_union_map_preimage_domain_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_domain_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_domain_multi_pw_aff.restype = c_void_p +isl.isl_union_map_preimage_domain_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_domain_pw_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_domain_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_domain_union_pw_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_domain_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_range_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_range_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_range_pw_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_range_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_preimage_range_union_pw_multi_aff.restype = c_void_p +isl.isl_union_map_preimage_range_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_product.restype = c_void_p +isl.isl_union_map_product.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_project_out_all_params.restype = c_void_p +isl.isl_union_map_project_out_all_params.argtypes = [c_void_p] +isl.isl_union_map_range.restype = c_void_p +isl.isl_union_map_range.argtypes = [c_void_p] +isl.isl_union_map_range_factor_domain.restype = c_void_p +isl.isl_union_map_range_factor_domain.argtypes = [c_void_p] +isl.isl_union_map_range_factor_range.restype = c_void_p +isl.isl_union_map_range_factor_range.argtypes = [c_void_p] +isl.isl_union_map_range_map.restype = c_void_p +isl.isl_union_map_range_map.argtypes = [c_void_p] +isl.isl_union_map_range_product.restype = c_void_p +isl.isl_union_map_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_reverse.restype = c_void_p +isl.isl_union_map_reverse.argtypes = [c_void_p] +isl.isl_union_map_subtract.restype = c_void_p +isl.isl_union_map_subtract.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_subtract_domain.restype = c_void_p +isl.isl_union_map_subtract_domain.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_subtract_range.restype = c_void_p +isl.isl_union_map_subtract_range.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_uncurry.restype = c_void_p +isl.isl_union_map_uncurry.argtypes = [c_void_p] +isl.isl_union_map_union.restype = c_void_p +isl.isl_union_map_union.argtypes = [c_void_p, c_void_p] +isl.isl_union_map_universe.restype = c_void_p +isl.isl_union_map_universe.argtypes = [c_void_p] +isl.isl_union_map_wrap.restype = c_void_p +isl.isl_union_map_wrap.argtypes = [c_void_p] +isl.isl_union_map_zip.restype = c_void_p +isl.isl_union_map_zip.argtypes = [c_void_p] +isl.isl_union_map_copy.restype = c_void_p +isl.isl_union_map_copy.argtypes = [c_void_p] +isl.isl_union_map_free.restype = c_void_p +isl.isl_union_map_free.argtypes = [c_void_p] +isl.isl_union_map_to_str.restype = POINTER(c_char) +isl.isl_union_map_to_str.argtypes = [c_void_p] + +class map(union_map): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is basic_map: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_map_from_basic_map(isl.isl_basic_map_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_map_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_map_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ptr = isl.isl_map_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.map("""%s""")' % s + else: + return 'isl.map("%s")' % s + def affine_hull(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_affine_hull(isl.isl_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def apply_domain(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).apply_domain(arg1) + ctx = arg0.ctx + res = isl.isl_map_apply_domain(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def apply_range(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).apply_range(arg1) + ctx = arg0.ctx + res = isl.isl_map_apply_range(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def bind_domain(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_map(arg0).bind_domain(arg1) + ctx = arg0.ctx + res = isl.isl_map_bind_domain(isl.isl_map_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def bind_range(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_map(arg0).bind_range(arg1) + ctx = arg0.ctx + res = isl.isl_map_bind_range(isl.isl_map_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def coalesce(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_coalesce(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def complement(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_complement(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def curry(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_curry(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def deltas(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_deltas(isl.isl_map_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_detect_equalities(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def domain(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_domain(isl.isl_map_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def domain_factor_domain(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_domain_factor_domain(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def domain_factor_range(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_domain_factor_range(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def domain_product(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).domain_product(arg1) + ctx = arg0.ctx + res = isl.isl_map_domain_product(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + @staticmethod + def empty(arg0): + try: + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_empty(isl.isl_space_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def factor_domain(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_factor_domain(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def factor_range(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_factor_range(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def flatten(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_flatten(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def flatten_domain(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_flatten_domain(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def flatten_range(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_flatten_range(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def foreach_basic_map(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = basic_map(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_map_foreach_basic_map(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def range_simple_fixed_box_hull(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_get_range_simple_fixed_box_hull(arg0.ptr) + obj = fixed_box(ctx=ctx, ptr=res) + return obj + def get_range_simple_fixed_box_hull(arg0): + return arg0.range_simple_fixed_box_hull() + def space(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_map_gist(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def gist_domain(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_map(arg0).gist_domain(arg1) + ctx = arg0.ctx + res = isl.isl_map_gist_domain(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).intersect(arg1) + ctx = arg0.ctx + res = isl.isl_map_intersect(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_map(arg0).intersect_domain(arg1) + ctx = arg0.ctx + res = isl.isl_map_intersect_domain(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_map(arg0).intersect_params(arg1) + ctx = arg0.ctx + res = isl.isl_map_intersect_params(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def intersect_range(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_map(arg0).intersect_range(arg1) + ctx = arg0.ctx + res = isl.isl_map_intersect_range(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def is_bijective(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_is_bijective(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_disjoint(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).is_disjoint(arg1) + ctx = arg0.ctx + res = isl.isl_map_is_disjoint(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_empty(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).is_equal(arg1) + ctx = arg0.ctx + res = isl.isl_map_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_injective(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_is_injective(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_single_valued(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_is_single_valued(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_strict_subset(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).is_strict_subset(arg1) + ctx = arg0.ctx + res = isl.isl_map_is_strict_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).is_subset(arg1) + ctx = arg0.ctx + res = isl.isl_map_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def lexmax(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_lexmax(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def lexmax_pw_multi_aff(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_lexmax_pw_multi_aff(isl.isl_map_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_lexmin(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def lexmin_pw_multi_aff(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_lexmin_pw_multi_aff(isl.isl_map_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def polyhedral_hull(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_polyhedral_hull(isl.isl_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def preimage_domain(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_map_preimage_domain_multi_aff(isl.isl_map_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_map_preimage_domain_multi_pw_aff(isl.isl_map_copy(args[0].ptr), isl.isl_multi_pw_aff_copy(args[1].ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_map_preimage_domain_pw_multi_aff(isl.isl_map_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + raise Error + def preimage_range(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_map_preimage_range_multi_aff(isl.isl_map_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_map_preimage_range_pw_multi_aff(isl.isl_map_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + raise Error + def project_out_all_params(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_project_out_all_params(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def range(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_range(isl.isl_map_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def range_factor_domain(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_range_factor_domain(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def range_factor_range(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_range_factor_range(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def range_product(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).range_product(arg1) + ctx = arg0.ctx + res = isl.isl_map_range_product(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def reverse(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_reverse(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def sample(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_sample(isl.isl_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def subtract(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).subtract(arg1) + ctx = arg0.ctx + res = isl.isl_map_subtract(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def uncurry(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_uncurry(isl.isl_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_map(arg0).union(arg1) + ctx = arg0.ctx + res = isl.isl_map_union(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + @staticmethod + def universe(arg0): + try: + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_universe(isl.isl_space_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def unshifted_simple_hull(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_unshifted_simple_hull(isl.isl_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def wrap(arg0): + try: + if not arg0.__class__ is map: + arg0 = map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_map_wrap(isl.isl_map_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + +isl.isl_map_from_basic_map.restype = c_void_p +isl.isl_map_from_basic_map.argtypes = [c_void_p] +isl.isl_map_read_from_str.restype = c_void_p +isl.isl_map_read_from_str.argtypes = [Context, c_char_p] +isl.isl_map_affine_hull.restype = c_void_p +isl.isl_map_affine_hull.argtypes = [c_void_p] +isl.isl_map_apply_domain.restype = c_void_p +isl.isl_map_apply_domain.argtypes = [c_void_p, c_void_p] +isl.isl_map_apply_range.restype = c_void_p +isl.isl_map_apply_range.argtypes = [c_void_p, c_void_p] +isl.isl_map_bind_domain.restype = c_void_p +isl.isl_map_bind_domain.argtypes = [c_void_p, c_void_p] +isl.isl_map_bind_range.restype = c_void_p +isl.isl_map_bind_range.argtypes = [c_void_p, c_void_p] +isl.isl_map_coalesce.restype = c_void_p +isl.isl_map_coalesce.argtypes = [c_void_p] +isl.isl_map_complement.restype = c_void_p +isl.isl_map_complement.argtypes = [c_void_p] +isl.isl_map_curry.restype = c_void_p +isl.isl_map_curry.argtypes = [c_void_p] +isl.isl_map_deltas.restype = c_void_p +isl.isl_map_deltas.argtypes = [c_void_p] +isl.isl_map_detect_equalities.restype = c_void_p +isl.isl_map_detect_equalities.argtypes = [c_void_p] +isl.isl_map_domain.restype = c_void_p +isl.isl_map_domain.argtypes = [c_void_p] +isl.isl_map_domain_factor_domain.restype = c_void_p +isl.isl_map_domain_factor_domain.argtypes = [c_void_p] +isl.isl_map_domain_factor_range.restype = c_void_p +isl.isl_map_domain_factor_range.argtypes = [c_void_p] +isl.isl_map_domain_product.restype = c_void_p +isl.isl_map_domain_product.argtypes = [c_void_p, c_void_p] +isl.isl_map_empty.restype = c_void_p +isl.isl_map_empty.argtypes = [c_void_p] +isl.isl_map_factor_domain.restype = c_void_p +isl.isl_map_factor_domain.argtypes = [c_void_p] +isl.isl_map_factor_range.restype = c_void_p +isl.isl_map_factor_range.argtypes = [c_void_p] +isl.isl_map_flatten.restype = c_void_p +isl.isl_map_flatten.argtypes = [c_void_p] +isl.isl_map_flatten_domain.restype = c_void_p +isl.isl_map_flatten_domain.argtypes = [c_void_p] +isl.isl_map_flatten_range.restype = c_void_p +isl.isl_map_flatten_range.argtypes = [c_void_p] +isl.isl_map_foreach_basic_map.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_map_get_range_simple_fixed_box_hull.restype = c_void_p +isl.isl_map_get_range_simple_fixed_box_hull.argtypes = [c_void_p] +isl.isl_map_get_space.restype = c_void_p +isl.isl_map_get_space.argtypes = [c_void_p] +isl.isl_map_gist.restype = c_void_p +isl.isl_map_gist.argtypes = [c_void_p, c_void_p] +isl.isl_map_gist_domain.restype = c_void_p +isl.isl_map_gist_domain.argtypes = [c_void_p, c_void_p] +isl.isl_map_intersect.restype = c_void_p +isl.isl_map_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_map_intersect_domain.restype = c_void_p +isl.isl_map_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_map_intersect_params.restype = c_void_p +isl.isl_map_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_map_intersect_range.restype = c_void_p +isl.isl_map_intersect_range.argtypes = [c_void_p, c_void_p] +isl.isl_map_is_bijective.argtypes = [c_void_p] +isl.isl_map_is_disjoint.argtypes = [c_void_p, c_void_p] +isl.isl_map_is_empty.argtypes = [c_void_p] +isl.isl_map_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_map_is_injective.argtypes = [c_void_p] +isl.isl_map_is_single_valued.argtypes = [c_void_p] +isl.isl_map_is_strict_subset.argtypes = [c_void_p, c_void_p] +isl.isl_map_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_map_lexmax.restype = c_void_p +isl.isl_map_lexmax.argtypes = [c_void_p] +isl.isl_map_lexmax_pw_multi_aff.restype = c_void_p +isl.isl_map_lexmax_pw_multi_aff.argtypes = [c_void_p] +isl.isl_map_lexmin.restype = c_void_p +isl.isl_map_lexmin.argtypes = [c_void_p] +isl.isl_map_lexmin_pw_multi_aff.restype = c_void_p +isl.isl_map_lexmin_pw_multi_aff.argtypes = [c_void_p] +isl.isl_map_polyhedral_hull.restype = c_void_p +isl.isl_map_polyhedral_hull.argtypes = [c_void_p] +isl.isl_map_preimage_domain_multi_aff.restype = c_void_p +isl.isl_map_preimage_domain_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_map_preimage_domain_multi_pw_aff.restype = c_void_p +isl.isl_map_preimage_domain_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_map_preimage_domain_pw_multi_aff.restype = c_void_p +isl.isl_map_preimage_domain_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_map_preimage_range_multi_aff.restype = c_void_p +isl.isl_map_preimage_range_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_map_preimage_range_pw_multi_aff.restype = c_void_p +isl.isl_map_preimage_range_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_map_project_out_all_params.restype = c_void_p +isl.isl_map_project_out_all_params.argtypes = [c_void_p] +isl.isl_map_range.restype = c_void_p +isl.isl_map_range.argtypes = [c_void_p] +isl.isl_map_range_factor_domain.restype = c_void_p +isl.isl_map_range_factor_domain.argtypes = [c_void_p] +isl.isl_map_range_factor_range.restype = c_void_p +isl.isl_map_range_factor_range.argtypes = [c_void_p] +isl.isl_map_range_product.restype = c_void_p +isl.isl_map_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_map_reverse.restype = c_void_p +isl.isl_map_reverse.argtypes = [c_void_p] +isl.isl_map_sample.restype = c_void_p +isl.isl_map_sample.argtypes = [c_void_p] +isl.isl_map_subtract.restype = c_void_p +isl.isl_map_subtract.argtypes = [c_void_p, c_void_p] +isl.isl_map_uncurry.restype = c_void_p +isl.isl_map_uncurry.argtypes = [c_void_p] +isl.isl_map_union.restype = c_void_p +isl.isl_map_union.argtypes = [c_void_p, c_void_p] +isl.isl_map_universe.restype = c_void_p +isl.isl_map_universe.argtypes = [c_void_p] +isl.isl_map_unshifted_simple_hull.restype = c_void_p +isl.isl_map_unshifted_simple_hull.argtypes = [c_void_p] +isl.isl_map_wrap.restype = c_void_p +isl.isl_map_wrap.argtypes = [c_void_p] +isl.isl_map_copy.restype = c_void_p +isl.isl_map_copy.argtypes = [c_void_p] +isl.isl_map_free.restype = c_void_p +isl.isl_map_free.argtypes = [c_void_p] +isl.isl_map_to_str.restype = POINTER(c_char) +isl.isl_map_to_str.argtypes = [c_void_p] + +class basic_map(map): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_basic_map_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_basic_map_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ptr = isl.isl_basic_map_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.basic_map("""%s""")' % s + else: + return 'isl.basic_map("%s")' % s + def affine_hull(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_affine_hull(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def apply_domain(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).apply_domain(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_apply_domain(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def apply_range(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).apply_range(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_apply_range(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def deltas(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_deltas(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_detect_equalities(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def flatten(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_flatten(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def flatten_domain(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_flatten_domain(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def flatten_range(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_flatten_range(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def gist(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_gist(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).intersect(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_intersect(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def intersect_domain(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) + except: + return map(arg0).intersect_domain(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_intersect_domain(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def intersect_range(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) + except: + return map(arg0).intersect_range(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_intersect_range(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def is_empty(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).is_equal(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).is_subset(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def lexmax(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_lexmax(isl.isl_basic_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_lexmin(isl.isl_basic_map_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def reverse(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_reverse(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def sample(arg0): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_basic_map_sample(isl.isl_basic_map_copy(arg0.ptr)) + obj = basic_map(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): + try: + if not arg0.__class__ is basic_map: + arg0 = basic_map(arg0) + except: + raise + try: + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) + except: + return map(arg0).union(arg1) + ctx = arg0.ctx + res = isl.isl_basic_map_union(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + +isl.isl_basic_map_read_from_str.restype = c_void_p +isl.isl_basic_map_read_from_str.argtypes = [Context, c_char_p] +isl.isl_basic_map_affine_hull.restype = c_void_p +isl.isl_basic_map_affine_hull.argtypes = [c_void_p] +isl.isl_basic_map_apply_domain.restype = c_void_p +isl.isl_basic_map_apply_domain.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_apply_range.restype = c_void_p +isl.isl_basic_map_apply_range.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_deltas.restype = c_void_p +isl.isl_basic_map_deltas.argtypes = [c_void_p] +isl.isl_basic_map_detect_equalities.restype = c_void_p +isl.isl_basic_map_detect_equalities.argtypes = [c_void_p] +isl.isl_basic_map_flatten.restype = c_void_p +isl.isl_basic_map_flatten.argtypes = [c_void_p] +isl.isl_basic_map_flatten_domain.restype = c_void_p +isl.isl_basic_map_flatten_domain.argtypes = [c_void_p] +isl.isl_basic_map_flatten_range.restype = c_void_p +isl.isl_basic_map_flatten_range.argtypes = [c_void_p] +isl.isl_basic_map_gist.restype = c_void_p +isl.isl_basic_map_gist.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_intersect.restype = c_void_p +isl.isl_basic_map_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_intersect_domain.restype = c_void_p +isl.isl_basic_map_intersect_domain.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_intersect_range.restype = c_void_p +isl.isl_basic_map_intersect_range.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_is_empty.argtypes = [c_void_p] +isl.isl_basic_map_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_lexmax.restype = c_void_p +isl.isl_basic_map_lexmax.argtypes = [c_void_p] +isl.isl_basic_map_lexmin.restype = c_void_p +isl.isl_basic_map_lexmin.argtypes = [c_void_p] +isl.isl_basic_map_reverse.restype = c_void_p +isl.isl_basic_map_reverse.argtypes = [c_void_p] +isl.isl_basic_map_sample.restype = c_void_p +isl.isl_basic_map_sample.argtypes = [c_void_p] +isl.isl_basic_map_union.restype = c_void_p +isl.isl_basic_map_union.argtypes = [c_void_p, c_void_p] +isl.isl_basic_map_copy.restype = c_void_p +isl.isl_basic_map_copy.argtypes = [c_void_p] +isl.isl_basic_map_free.restype = c_void_p +isl.isl_basic_map_free.argtypes = [c_void_p] +isl.isl_basic_map_to_str.restype = POINTER(c_char) +isl.isl_basic_map_to_str.argtypes = [c_void_p] + +class union_set(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is basic_set: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_from_basic_set(isl.isl_basic_set_copy(args[0].ptr)) + return + if len(args) == 1 and args[0].__class__ is point: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_from_point(isl.isl_point_copy(args[0].ptr)) + return + if len(args) == 1 and args[0].__class__ is set: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_from_set(isl.isl_set_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_union_set_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ptr = isl.isl_union_set_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.union_set("""%s""")' % s + else: + return 'isl.union_set("%s")' % s + def affine_hull(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_affine_hull(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def apply(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_apply(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def coalesce(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_coalesce(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def compute_divs(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_compute_divs(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_detect_equalities(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + @staticmethod + def empty(*args): + if len(args) == 0: + ctx = Context.getDefaultInstance() + res = isl.isl_union_set_empty_ctx(ctx) + obj = union_set(ctx=ctx, ptr=res) + return obj + raise Error + def every_set(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = set(ctx=arg0.ctx, ptr=isl.isl_set_copy(cb_arg0)) + try: + res = arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 1 if res else 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_union_set_every_set(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + return bool(res) + def extract_set(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is space: + arg1 = space(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_extract_set(arg0.ptr, isl.isl_space_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def foreach_point(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = point(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_union_set_foreach_point(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def foreach_set(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = set(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_union_set_foreach_set(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def space(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def gist(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_gist(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def gist_params(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_gist_params(isl.isl_union_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def identity(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_identity(isl.isl_union_set_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_intersect(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_intersect_params(isl.isl_union_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def is_disjoint(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_is_disjoint(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_empty(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_strict_subset(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_is_strict_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def isa_set(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_isa_set(arg0.ptr) + if res < 0: + raise + return bool(res) + def lexmax(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_lexmax(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_lexmin(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def polyhedral_hull(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_polyhedral_hull(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def preimage(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_union_set_preimage_multi_aff(isl.isl_union_set_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_set_preimage_pw_multi_aff(isl.isl_union_set_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_union_set_preimage_union_pw_multi_aff(isl.isl_union_set_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + raise Error + def sample_point(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_sample_point(isl.isl_union_set_copy(arg0.ptr)) + obj = point(ctx=ctx, ptr=res) + return obj + def subtract(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_subtract(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_union(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def universe(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_universe(isl.isl_union_set_copy(arg0.ptr)) + obj = union_set(ctx=ctx, ptr=res) + return obj + def unwrap(arg0): + try: + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_union_set_unwrap(isl.isl_union_set_copy(arg0.ptr)) + obj = union_map(ctx=ctx, ptr=res) + return obj + +isl.isl_union_set_from_basic_set.restype = c_void_p +isl.isl_union_set_from_basic_set.argtypes = [c_void_p] +isl.isl_union_set_from_point.restype = c_void_p +isl.isl_union_set_from_point.argtypes = [c_void_p] +isl.isl_union_set_from_set.restype = c_void_p +isl.isl_union_set_from_set.argtypes = [c_void_p] +isl.isl_union_set_read_from_str.restype = c_void_p +isl.isl_union_set_read_from_str.argtypes = [Context, c_char_p] +isl.isl_union_set_affine_hull.restype = c_void_p +isl.isl_union_set_affine_hull.argtypes = [c_void_p] +isl.isl_union_set_apply.restype = c_void_p +isl.isl_union_set_apply.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_coalesce.restype = c_void_p +isl.isl_union_set_coalesce.argtypes = [c_void_p] +isl.isl_union_set_compute_divs.restype = c_void_p +isl.isl_union_set_compute_divs.argtypes = [c_void_p] +isl.isl_union_set_detect_equalities.restype = c_void_p +isl.isl_union_set_detect_equalities.argtypes = [c_void_p] +isl.isl_union_set_empty_ctx.restype = c_void_p +isl.isl_union_set_empty_ctx.argtypes = [Context] +isl.isl_union_set_every_set.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_set_extract_set.restype = c_void_p +isl.isl_union_set_extract_set.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_foreach_point.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_set_foreach_set.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_set_get_space.restype = c_void_p +isl.isl_union_set_get_space.argtypes = [c_void_p] +isl.isl_union_set_gist.restype = c_void_p +isl.isl_union_set_gist.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_gist_params.restype = c_void_p +isl.isl_union_set_gist_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_identity.restype = c_void_p +isl.isl_union_set_identity.argtypes = [c_void_p] +isl.isl_union_set_intersect.restype = c_void_p +isl.isl_union_set_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_intersect_params.restype = c_void_p +isl.isl_union_set_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_is_disjoint.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_is_empty.argtypes = [c_void_p] +isl.isl_union_set_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_is_strict_subset.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_isa_set.argtypes = [c_void_p] +isl.isl_union_set_lexmax.restype = c_void_p +isl.isl_union_set_lexmax.argtypes = [c_void_p] +isl.isl_union_set_lexmin.restype = c_void_p +isl.isl_union_set_lexmin.argtypes = [c_void_p] +isl.isl_union_set_polyhedral_hull.restype = c_void_p +isl.isl_union_set_polyhedral_hull.argtypes = [c_void_p] +isl.isl_union_set_preimage_multi_aff.restype = c_void_p +isl.isl_union_set_preimage_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_preimage_pw_multi_aff.restype = c_void_p +isl.isl_union_set_preimage_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_preimage_union_pw_multi_aff.restype = c_void_p +isl.isl_union_set_preimage_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_sample_point.restype = c_void_p +isl.isl_union_set_sample_point.argtypes = [c_void_p] +isl.isl_union_set_subtract.restype = c_void_p +isl.isl_union_set_subtract.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_union.restype = c_void_p +isl.isl_union_set_union.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_universe.restype = c_void_p +isl.isl_union_set_universe.argtypes = [c_void_p] +isl.isl_union_set_unwrap.restype = c_void_p +isl.isl_union_set_unwrap.argtypes = [c_void_p] +isl.isl_union_set_copy.restype = c_void_p +isl.isl_union_set_copy.argtypes = [c_void_p] +isl.isl_union_set_free.restype = c_void_p +isl.isl_union_set_free.argtypes = [c_void_p] +isl.isl_union_set_to_str.restype = POINTER(c_char) +isl.isl_union_set_to_str.argtypes = [c_void_p] + +class set(union_set): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is basic_set: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_set_from_basic_set(isl.isl_basic_set_copy(args[0].ptr)) + return + if len(args) == 1 and args[0].__class__ is point: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_set_from_point(isl.isl_point_copy(args[0].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_set_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_set_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ptr = isl.isl_set_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.set("""%s""")' % s + else: + return 'isl.set("%s")' % s + def affine_hull(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_affine_hull(isl.isl_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def apply(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is map: + arg1 = map(arg1) + except: + return union_set(arg0).apply(arg1) + ctx = arg0.ctx + res = isl.isl_set_apply(isl.isl_set_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def bind(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_set(arg0).bind(arg1) + ctx = arg0.ctx + res = isl.isl_set_bind(isl.isl_set_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def coalesce(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_coalesce(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def complement(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_complement(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_detect_equalities(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + @staticmethod + def empty(arg0): + try: + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_empty(isl.isl_space_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def flatten(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_flatten(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def foreach_basic_set(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = basic_set(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_set_foreach_basic_set(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def foreach_point(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = point(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_set_foreach_point(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def space(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def stride(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_get_stride(arg0.ptr, arg1) + obj = val(ctx=ctx, ptr=res) + return obj + def get_stride(arg0, arg1): + return arg0.stride(arg1) + def gist(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).gist(arg1) + ctx = arg0.ctx + res = isl.isl_set_gist(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def identity(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_identity(isl.isl_set_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).intersect(arg1) + ctx = arg0.ctx + res = isl.isl_set_intersect(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).intersect_params(arg1) + ctx = arg0.ctx + res = isl.isl_set_intersect_params(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def is_disjoint(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).is_disjoint(arg1) + ctx = arg0.ctx + res = isl.isl_set_is_disjoint(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_empty(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).is_equal(arg1) + ctx = arg0.ctx + res = isl.isl_set_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_singleton(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_is_singleton(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_strict_subset(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).is_strict_subset(arg1) + ctx = arg0.ctx + res = isl.isl_set_is_strict_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).is_subset(arg1) + ctx = arg0.ctx + res = isl.isl_set_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_wrapping(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_is_wrapping(arg0.ptr) + if res < 0: + raise + return bool(res) + def lexmax(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_lexmax(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def lexmax_pw_multi_aff(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_lexmax_pw_multi_aff(isl.isl_set_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_lexmin(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def lexmin_pw_multi_aff(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_lexmin_pw_multi_aff(isl.isl_set_copy(arg0.ptr)) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def max_val(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return union_set(arg0).max_val(arg1) + ctx = arg0.ctx + res = isl.isl_set_max_val(arg0.ptr, arg1.ptr) + obj = val(ctx=ctx, ptr=res) + return obj + def min_val(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is aff: + arg1 = aff(arg1) + except: + return union_set(arg0).min_val(arg1) + ctx = arg0.ctx + res = isl.isl_set_min_val(arg0.ptr, arg1.ptr) + obj = val(ctx=ctx, ptr=res) + return obj + def params(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_params(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def polyhedral_hull(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_polyhedral_hull(isl.isl_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def preimage(*args): + if len(args) == 2 and args[1].__class__ is multi_aff: + ctx = args[0].ctx + res = isl.isl_set_preimage_multi_aff(isl.isl_set_copy(args[0].ptr), isl.isl_multi_aff_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is multi_pw_aff: + ctx = args[0].ctx + res = isl.isl_set_preimage_multi_pw_aff(isl.isl_set_copy(args[0].ptr), isl.isl_multi_pw_aff_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_set_preimage_pw_multi_aff(isl.isl_set_copy(args[0].ptr), isl.isl_pw_multi_aff_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + raise Error + def product(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).product(arg1) + ctx = arg0.ctx + res = isl.isl_set_product(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def project_out_all_params(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_project_out_all_params(isl.isl_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def project_out_param(*args): + if len(args) == 2 and (args[1].__class__ is id or type(args[1]) == str): + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_set_project_out_param_id(isl.isl_set_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and args[1].__class__ is id_list: + ctx = args[0].ctx + res = isl.isl_set_project_out_param_id_list(isl.isl_set_copy(args[0].ptr), isl.isl_id_list_copy(args[1].ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + raise Error + def sample(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_sample(isl.isl_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def sample_point(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_sample_point(isl.isl_set_copy(arg0.ptr)) + obj = point(ctx=ctx, ptr=res) + return obj + def subtract(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).subtract(arg1) + ctx = arg0.ctx + res = isl.isl_set_subtract(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def unbind_params(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_set(arg0).unbind_params(arg1) + ctx = arg0.ctx + res = isl.isl_set_unbind_params(isl.isl_set_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def unbind_params_insert_domain(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + return union_set(arg0).unbind_params_insert_domain(arg1) + ctx = arg0.ctx + res = isl.isl_set_unbind_params_insert_domain(isl.isl_set_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) + except: + return union_set(arg0).union(arg1) + ctx = arg0.ctx + res = isl.isl_set_union(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + @staticmethod + def universe(arg0): + try: + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_universe(isl.isl_space_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def unshifted_simple_hull(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_map_zip(isl.isl_union_map_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) + res = isl.isl_set_unshifted_simple_hull(isl.isl_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def unwrap(arg0): + try: + if not arg0.__class__ is set: + arg0 = set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_set_unwrap(isl.isl_set_copy(arg0.ptr)) + obj = map(ctx=ctx, ptr=res) + return obj -isl.isl_union_map_from_basic_map.restype = c_void_p -isl.isl_union_map_from_basic_map.argtypes = [c_void_p] -isl.isl_union_map_from_map.restype = c_void_p -isl.isl_union_map_from_map.argtypes = [c_void_p] -isl.isl_union_map_read_from_str.restype = c_void_p -isl.isl_union_map_read_from_str.argtypes = [Context, c_char_p] -isl.isl_union_map_affine_hull.restype = c_void_p -isl.isl_union_map_affine_hull.argtypes = [c_void_p] -isl.isl_union_map_apply_domain.restype = c_void_p -isl.isl_union_map_apply_domain.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_apply_range.restype = c_void_p -isl.isl_union_map_apply_range.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_coalesce.restype = c_void_p -isl.isl_union_map_coalesce.argtypes = [c_void_p] -isl.isl_union_map_compute_divs.restype = c_void_p -isl.isl_union_map_compute_divs.argtypes = [c_void_p] -isl.isl_union_map_deltas.restype = c_void_p -isl.isl_union_map_deltas.argtypes = [c_void_p] -isl.isl_union_map_detect_equalities.restype = c_void_p -isl.isl_union_map_detect_equalities.argtypes = [c_void_p] -isl.isl_union_map_domain.restype = c_void_p -isl.isl_union_map_domain.argtypes = [c_void_p] -isl.isl_union_map_domain_factor_domain.restype = c_void_p -isl.isl_union_map_domain_factor_domain.argtypes = [c_void_p] -isl.isl_union_map_domain_factor_range.restype = c_void_p -isl.isl_union_map_domain_factor_range.argtypes = [c_void_p] -isl.isl_union_map_domain_map.restype = c_void_p -isl.isl_union_map_domain_map.argtypes = [c_void_p] -isl.isl_union_map_domain_map_union_pw_multi_aff.restype = c_void_p -isl.isl_union_map_domain_map_union_pw_multi_aff.argtypes = [c_void_p] -isl.isl_union_map_domain_product.restype = c_void_p -isl.isl_union_map_domain_product.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_eq_at_multi_union_pw_aff.restype = c_void_p -isl.isl_union_map_eq_at_multi_union_pw_aff.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_factor_domain.restype = c_void_p -isl.isl_union_map_factor_domain.argtypes = [c_void_p] -isl.isl_union_map_factor_range.restype = c_void_p -isl.isl_union_map_factor_range.argtypes = [c_void_p] -isl.isl_union_map_fixed_power_val.restype = c_void_p -isl.isl_union_map_fixed_power_val.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_foreach_map.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_union_map_from_union_pw_multi_aff.restype = c_void_p -isl.isl_union_map_from_union_pw_multi_aff.argtypes = [c_void_p] -isl.isl_union_map_from_multi_union_pw_aff.restype = c_void_p -isl.isl_union_map_from_multi_union_pw_aff.argtypes = [c_void_p] -isl.isl_union_map_from_domain.restype = c_void_p -isl.isl_union_map_from_domain.argtypes = [c_void_p] -isl.isl_union_map_from_domain_and_range.restype = c_void_p -isl.isl_union_map_from_domain_and_range.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_from_range.restype = c_void_p -isl.isl_union_map_from_range.argtypes = [c_void_p] -isl.isl_union_map_gist.restype = c_void_p -isl.isl_union_map_gist.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_gist_domain.restype = c_void_p -isl.isl_union_map_gist_domain.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_gist_params.restype = c_void_p -isl.isl_union_map_gist_params.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_gist_range.restype = c_void_p -isl.isl_union_map_gist_range.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_intersect.restype = c_void_p -isl.isl_union_map_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_intersect_domain.restype = c_void_p -isl.isl_union_map_intersect_domain.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_intersect_params.restype = c_void_p -isl.isl_union_map_intersect_params.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_intersect_range.restype = c_void_p -isl.isl_union_map_intersect_range.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_is_bijective.restype = c_bool -isl.isl_union_map_is_bijective.argtypes = [c_void_p] -isl.isl_union_map_is_empty.restype = c_bool -isl.isl_union_map_is_empty.argtypes = [c_void_p] -isl.isl_union_map_is_equal.restype = c_bool -isl.isl_union_map_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_is_injective.restype = c_bool -isl.isl_union_map_is_injective.argtypes = [c_void_p] -isl.isl_union_map_is_single_valued.restype = c_bool -isl.isl_union_map_is_single_valued.argtypes = [c_void_p] -isl.isl_union_map_is_strict_subset.restype = c_bool -isl.isl_union_map_is_strict_subset.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_is_subset.restype = c_bool -isl.isl_union_map_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_lexmax.restype = c_void_p -isl.isl_union_map_lexmax.argtypes = [c_void_p] -isl.isl_union_map_lexmin.restype = c_void_p -isl.isl_union_map_lexmin.argtypes = [c_void_p] -isl.isl_union_map_polyhedral_hull.restype = c_void_p -isl.isl_union_map_polyhedral_hull.argtypes = [c_void_p] -isl.isl_union_map_product.restype = c_void_p -isl.isl_union_map_product.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_project_out_all_params.restype = c_void_p -isl.isl_union_map_project_out_all_params.argtypes = [c_void_p] -isl.isl_union_map_range.restype = c_void_p -isl.isl_union_map_range.argtypes = [c_void_p] -isl.isl_union_map_range_factor_domain.restype = c_void_p -isl.isl_union_map_range_factor_domain.argtypes = [c_void_p] -isl.isl_union_map_range_factor_range.restype = c_void_p -isl.isl_union_map_range_factor_range.argtypes = [c_void_p] -isl.isl_union_map_range_map.restype = c_void_p -isl.isl_union_map_range_map.argtypes = [c_void_p] -isl.isl_union_map_range_product.restype = c_void_p -isl.isl_union_map_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_reverse.restype = c_void_p -isl.isl_union_map_reverse.argtypes = [c_void_p] -isl.isl_union_map_subtract.restype = c_void_p -isl.isl_union_map_subtract.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_subtract_domain.restype = c_void_p -isl.isl_union_map_subtract_domain.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_subtract_range.restype = c_void_p -isl.isl_union_map_subtract_range.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_union.restype = c_void_p -isl.isl_union_map_union.argtypes = [c_void_p, c_void_p] -isl.isl_union_map_wrap.restype = c_void_p -isl.isl_union_map_wrap.argtypes = [c_void_p] -isl.isl_union_map_zip.restype = c_void_p -isl.isl_union_map_zip.argtypes = [c_void_p] -isl.isl_union_map_copy.restype = c_void_p -isl.isl_union_map_copy.argtypes = [c_void_p] -isl.isl_union_map_free.restype = c_void_p -isl.isl_union_map_free.argtypes = [c_void_p] -isl.isl_union_map_to_str.restype = POINTER(c_char) -isl.isl_union_map_to_str.argtypes = [c_void_p] +isl.isl_set_from_basic_set.restype = c_void_p +isl.isl_set_from_basic_set.argtypes = [c_void_p] +isl.isl_set_from_point.restype = c_void_p +isl.isl_set_from_point.argtypes = [c_void_p] +isl.isl_set_read_from_str.restype = c_void_p +isl.isl_set_read_from_str.argtypes = [Context, c_char_p] +isl.isl_set_affine_hull.restype = c_void_p +isl.isl_set_affine_hull.argtypes = [c_void_p] +isl.isl_set_apply.restype = c_void_p +isl.isl_set_apply.argtypes = [c_void_p, c_void_p] +isl.isl_set_bind.restype = c_void_p +isl.isl_set_bind.argtypes = [c_void_p, c_void_p] +isl.isl_set_coalesce.restype = c_void_p +isl.isl_set_coalesce.argtypes = [c_void_p] +isl.isl_set_complement.restype = c_void_p +isl.isl_set_complement.argtypes = [c_void_p] +isl.isl_set_detect_equalities.restype = c_void_p +isl.isl_set_detect_equalities.argtypes = [c_void_p] +isl.isl_set_empty.restype = c_void_p +isl.isl_set_empty.argtypes = [c_void_p] +isl.isl_set_flatten.restype = c_void_p +isl.isl_set_flatten.argtypes = [c_void_p] +isl.isl_set_foreach_basic_set.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_set_foreach_point.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_set_get_space.restype = c_void_p +isl.isl_set_get_space.argtypes = [c_void_p] +isl.isl_set_get_stride.restype = c_void_p +isl.isl_set_get_stride.argtypes = [c_void_p, c_int] +isl.isl_set_gist.restype = c_void_p +isl.isl_set_gist.argtypes = [c_void_p, c_void_p] +isl.isl_set_identity.restype = c_void_p +isl.isl_set_identity.argtypes = [c_void_p] +isl.isl_set_intersect.restype = c_void_p +isl.isl_set_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_set_intersect_params.restype = c_void_p +isl.isl_set_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_set_is_disjoint.argtypes = [c_void_p, c_void_p] +isl.isl_set_is_empty.argtypes = [c_void_p] +isl.isl_set_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_set_is_singleton.argtypes = [c_void_p] +isl.isl_set_is_strict_subset.argtypes = [c_void_p, c_void_p] +isl.isl_set_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_set_is_wrapping.argtypes = [c_void_p] +isl.isl_set_lexmax.restype = c_void_p +isl.isl_set_lexmax.argtypes = [c_void_p] +isl.isl_set_lexmax_pw_multi_aff.restype = c_void_p +isl.isl_set_lexmax_pw_multi_aff.argtypes = [c_void_p] +isl.isl_set_lexmin.restype = c_void_p +isl.isl_set_lexmin.argtypes = [c_void_p] +isl.isl_set_lexmin_pw_multi_aff.restype = c_void_p +isl.isl_set_lexmin_pw_multi_aff.argtypes = [c_void_p] +isl.isl_set_max_val.restype = c_void_p +isl.isl_set_max_val.argtypes = [c_void_p, c_void_p] +isl.isl_set_min_val.restype = c_void_p +isl.isl_set_min_val.argtypes = [c_void_p, c_void_p] +isl.isl_set_params.restype = c_void_p +isl.isl_set_params.argtypes = [c_void_p] +isl.isl_set_polyhedral_hull.restype = c_void_p +isl.isl_set_polyhedral_hull.argtypes = [c_void_p] +isl.isl_set_preimage_multi_aff.restype = c_void_p +isl.isl_set_preimage_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_set_preimage_multi_pw_aff.restype = c_void_p +isl.isl_set_preimage_multi_pw_aff.argtypes = [c_void_p, c_void_p] +isl.isl_set_preimage_pw_multi_aff.restype = c_void_p +isl.isl_set_preimage_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_set_product.restype = c_void_p +isl.isl_set_product.argtypes = [c_void_p, c_void_p] +isl.isl_set_project_out_all_params.restype = c_void_p +isl.isl_set_project_out_all_params.argtypes = [c_void_p] +isl.isl_set_project_out_param_id.restype = c_void_p +isl.isl_set_project_out_param_id.argtypes = [c_void_p, c_void_p] +isl.isl_set_project_out_param_id_list.restype = c_void_p +isl.isl_set_project_out_param_id_list.argtypes = [c_void_p, c_void_p] +isl.isl_set_sample.restype = c_void_p +isl.isl_set_sample.argtypes = [c_void_p] +isl.isl_set_sample_point.restype = c_void_p +isl.isl_set_sample_point.argtypes = [c_void_p] +isl.isl_set_subtract.restype = c_void_p +isl.isl_set_subtract.argtypes = [c_void_p, c_void_p] +isl.isl_set_unbind_params.restype = c_void_p +isl.isl_set_unbind_params.argtypes = [c_void_p, c_void_p] +isl.isl_set_unbind_params_insert_domain.restype = c_void_p +isl.isl_set_unbind_params_insert_domain.argtypes = [c_void_p, c_void_p] +isl.isl_set_union.restype = c_void_p +isl.isl_set_union.argtypes = [c_void_p, c_void_p] +isl.isl_set_universe.restype = c_void_p +isl.isl_set_universe.argtypes = [c_void_p] +isl.isl_set_unshifted_simple_hull.restype = c_void_p +isl.isl_set_unshifted_simple_hull.argtypes = [c_void_p] +isl.isl_set_unwrap.restype = c_void_p +isl.isl_set_unwrap.argtypes = [c_void_p] +isl.isl_set_copy.restype = c_void_p +isl.isl_set_copy.argtypes = [c_void_p] +isl.isl_set_free.restype = c_void_p +isl.isl_set_free.argtypes = [c_void_p] +isl.isl_set_to_str.restype = POINTER(c_char) +isl.isl_set_to_str.argtypes = [c_void_p] -class map(union_map): +class basic_set(set): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return - if len(args) == 1 and type(args[0]) == str: + if len(args) == 1 and args[0].__class__ is point: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_map_read_from_str(self.ctx, args[0].encode('ascii')) + self.ptr = isl.isl_basic_set_from_point(isl.isl_point_copy(args[0].ptr)) return - if len(args) == 1 and args[0].__class__ is basic_map: + if len(args) == 1 and type(args[0]) == str: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_map_from_basic_map(isl.isl_basic_map_copy(args[0].ptr)) + self.ptr = isl.isl_basic_set_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_map_free(self.ptr) + isl.isl_basic_set_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - ptr = isl.isl_map_to_str(arg0.ptr) + ptr = isl.isl_basic_set_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.map("""%s""")' % s + return 'isl.basic_set("""%s""")' % s else: - return 'isl.map("%s")' % s + return 'isl.basic_set("%s")' % s def affine_hull(arg0): - try: - if not arg0.__class__ is map: - arg0 = map(arg0) - except: - raise - ctx = arg0.ctx - res = isl.isl_map_affine_hull(isl.isl_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def apply_domain(arg0, arg1): - try: - if not arg0.__class__ is map: - arg0 = map(arg0) - except: - raise - try: - if not arg1.__class__ is map: - arg1 = map(arg1) - except: - return union_map(arg0).apply_domain(arg1) - ctx = arg0.ctx - res = isl.isl_map_apply_domain(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def apply_range(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - try: - if not arg1.__class__ is map: - arg1 = map(arg1) - except: - return union_map(arg0).apply_range(arg1) ctx = arg0.ctx - res = isl.isl_map_apply_range(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def coalesce(arg0): + res = isl.isl_basic_set_affine_hull(isl.isl_basic_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def apply(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_map_coalesce(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def complement(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg1.__class__ is basic_map: + arg1 = basic_map(arg1) except: - raise + return set(arg0).apply(arg1) ctx = arg0.ctx - res = isl.isl_map_complement(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def deltas(arg0): + res = isl.isl_basic_set_apply(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def detect_equalities(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_deltas(isl.isl_map_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_basic_set_detect_equalities(isl.isl_basic_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def dim_max_val(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_detect_equalities(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) + res = isl.isl_basic_set_dim_max_val(isl.isl_basic_set_copy(arg0.ptr), arg1) + obj = val(ctx=ctx, ptr=res) + return obj def flatten(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_flatten(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def flatten_domain(arg0): + res = isl.isl_basic_set_flatten(isl.isl_basic_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def gist(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_map_flatten_domain(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def flatten_range(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) except: - raise + return set(arg0).gist(arg1) ctx = arg0.ctx - res = isl.isl_map_flatten_range(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def foreach_basic_map(arg0, arg1): + res = isl.isl_basic_set_gist(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def intersect(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - exc_info = [None] - fn = CFUNCTYPE(c_int, c_void_p, c_void_p) - def cb_func(cb_arg0, cb_arg1): - cb_arg0 = basic_map(ctx=arg0.ctx, ptr=cb_arg0) - try: - arg1(cb_arg0) - except: - import sys - exc_info[0] = sys.exc_info() - return -1 - return 0 - cb = fn(cb_func) + try: + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) + except: + return set(arg0).intersect(arg1) ctx = arg0.ctx - res = isl.isl_map_foreach_basic_map(arg0.ptr, cb, None) - if exc_info[0] != None: - raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) - return res - def gist(arg0, arg1): + res = isl.isl_basic_set_intersect(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def intersect_params(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) except: - return union_map(arg0).gist(arg1) + return set(arg0).intersect_params(arg1) ctx = arg0.ctx - res = isl.isl_map_gist(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def gist_domain(arg0, arg1): + res = isl.isl_basic_set_intersect_params(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def is_empty(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise - try: - if not arg1.__class__ is set: - arg1 = set(arg1) - except: - return union_map(arg0).gist_domain(arg1) ctx = arg0.ctx - res = isl.isl_map_gist_domain(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_basic_set_is_empty(arg0.ptr) + if res < 0: + raise + return bool(res) + def is_equal(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) except: - return union_map(arg0).intersect(arg1) + return set(arg0).is_equal(arg1) ctx = arg0.ctx - res = isl.isl_map_intersect(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def intersect_domain(arg0, arg1): + res = isl.isl_basic_set_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_subset(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) except: - return union_map(arg0).intersect_domain(arg1) + return set(arg0).is_subset(arg1) ctx = arg0.ctx - res = isl.isl_map_intersect_domain(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def intersect_params(arg0, arg1): + res = isl.isl_basic_set_is_subset(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_wrapping(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: + raise + ctx = arg0.ctx + res = isl.isl_basic_set_is_wrapping(arg0.ptr) + if res < 0: raise + return bool(res) + def lexmax(arg0): try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: - return union_map(arg0).intersect_params(arg1) + raise ctx = arg0.ctx - res = isl.isl_map_intersect_params(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def intersect_range(arg0, arg1): + res = isl.isl_basic_set_lexmax(isl.isl_basic_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def lexmin(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_basic_set_lexmin(isl.isl_basic_set_copy(arg0.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + def params(arg0): try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: - return union_map(arg0).intersect_range(arg1) + raise ctx = arg0.ctx - res = isl.isl_map_intersect_range(isl.isl_map_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def is_bijective(arg0): + res = isl.isl_basic_set_params(isl.isl_basic_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def sample(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_is_bijective(arg0.ptr) - if res < 0: + res = isl.isl_basic_set_sample(isl.isl_basic_set_copy(arg0.ptr)) + obj = basic_set(ctx=ctx, ptr=res) + return obj + def sample_point(arg0): + try: + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) + except: raise - return bool(res) - def is_disjoint(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_basic_set_sample_point(isl.isl_basic_set_copy(arg0.ptr)) + obj = point(ctx=ctx, ptr=res) + return obj + def union(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is basic_set: + arg0 = basic_set(arg0) except: raise try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg1.__class__ is basic_set: + arg1 = basic_set(arg1) except: - return union_map(arg0).is_disjoint(arg1) + return set(arg0).union(arg1) ctx = arg0.ctx - res = isl.isl_map_is_disjoint(arg0.ptr, arg1.ptr) - if res < 0: + res = isl.isl_basic_set_union(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) + obj = set(ctx=ctx, ptr=res) + return obj + +isl.isl_basic_set_from_point.restype = c_void_p +isl.isl_basic_set_from_point.argtypes = [c_void_p] +isl.isl_basic_set_read_from_str.restype = c_void_p +isl.isl_basic_set_read_from_str.argtypes = [Context, c_char_p] +isl.isl_basic_set_affine_hull.restype = c_void_p +isl.isl_basic_set_affine_hull.argtypes = [c_void_p] +isl.isl_basic_set_apply.restype = c_void_p +isl.isl_basic_set_apply.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_detect_equalities.restype = c_void_p +isl.isl_basic_set_detect_equalities.argtypes = [c_void_p] +isl.isl_basic_set_dim_max_val.restype = c_void_p +isl.isl_basic_set_dim_max_val.argtypes = [c_void_p, c_int] +isl.isl_basic_set_flatten.restype = c_void_p +isl.isl_basic_set_flatten.argtypes = [c_void_p] +isl.isl_basic_set_gist.restype = c_void_p +isl.isl_basic_set_gist.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_intersect.restype = c_void_p +isl.isl_basic_set_intersect.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_intersect_params.restype = c_void_p +isl.isl_basic_set_intersect_params.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_is_empty.argtypes = [c_void_p] +isl.isl_basic_set_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_is_subset.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_is_wrapping.argtypes = [c_void_p] +isl.isl_basic_set_lexmax.restype = c_void_p +isl.isl_basic_set_lexmax.argtypes = [c_void_p] +isl.isl_basic_set_lexmin.restype = c_void_p +isl.isl_basic_set_lexmin.argtypes = [c_void_p] +isl.isl_basic_set_params.restype = c_void_p +isl.isl_basic_set_params.argtypes = [c_void_p] +isl.isl_basic_set_sample.restype = c_void_p +isl.isl_basic_set_sample.argtypes = [c_void_p] +isl.isl_basic_set_sample_point.restype = c_void_p +isl.isl_basic_set_sample_point.argtypes = [c_void_p] +isl.isl_basic_set_union.restype = c_void_p +isl.isl_basic_set_union.argtypes = [c_void_p, c_void_p] +isl.isl_basic_set_copy.restype = c_void_p +isl.isl_basic_set_copy.argtypes = [c_void_p] +isl.isl_basic_set_free.restype = c_void_p +isl.isl_basic_set_free.argtypes = [c_void_p] +isl.isl_basic_set_to_str.restype = POINTER(c_char) +isl.isl_basic_set_to_str.argtypes = [c_void_p] + +class fixed_box(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_fixed_box_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is fixed_box: + arg0 = fixed_box(arg0) + except: raise - return bool(res) - def is_empty(arg0): + ptr = isl.isl_fixed_box_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.fixed_box("""%s""")' % s + else: + return 'isl.fixed_box("%s")' % s + def offset(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is fixed_box: + arg0 = fixed_box(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_is_empty(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_equal(arg0, arg1): + res = isl.isl_fixed_box_get_offset(arg0.ptr) + obj = multi_aff(ctx=ctx, ptr=res) + return obj + def get_offset(arg0): + return arg0.offset() + def size(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is fixed_box: + arg0 = fixed_box(arg0) except: raise - try: - if not arg1.__class__ is map: - arg1 = map(arg1) - except: - return union_map(arg0).is_equal(arg1) ctx = arg0.ctx - res = isl.isl_map_is_equal(arg0.ptr, arg1.ptr) - if res < 0: - raise - return bool(res) - def is_injective(arg0): + res = isl.isl_fixed_box_get_size(arg0.ptr) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def get_size(arg0): + return arg0.size() + def space(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is fixed_box: + arg0 = fixed_box(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_is_injective(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_single_valued(arg0): + res = isl.isl_fixed_box_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def is_valid(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is fixed_box: + arg0 = fixed_box(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_is_single_valued(arg0.ptr) + res = isl.isl_fixed_box_is_valid(arg0.ptr) if res < 0: raise return bool(res) - def is_strict_subset(arg0, arg1): + +isl.isl_fixed_box_get_offset.restype = c_void_p +isl.isl_fixed_box_get_offset.argtypes = [c_void_p] +isl.isl_fixed_box_get_size.restype = c_void_p +isl.isl_fixed_box_get_size.argtypes = [c_void_p] +isl.isl_fixed_box_get_space.restype = c_void_p +isl.isl_fixed_box_get_space.argtypes = [c_void_p] +isl.isl_fixed_box_is_valid.argtypes = [c_void_p] +isl.isl_fixed_box_copy.restype = c_void_p +isl.isl_fixed_box_copy.argtypes = [c_void_p] +isl.isl_fixed_box_free.restype = c_void_p +isl.isl_fixed_box_free.argtypes = [c_void_p] +isl.isl_fixed_box_to_str.restype = POINTER(c_char) +isl.isl_fixed_box_to_str.argtypes = [c_void_p] + +class id(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_id_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_id_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id: + arg0 = id(arg0) except: raise + ptr = isl.isl_id_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.id("""%s""")' % s + else: + return 'isl.id("%s")' % s + def name(arg0): try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg0.__class__ is id: + arg0 = id(arg0) except: - return union_map(arg0).is_strict_subset(arg1) + raise ctx = arg0.ctx - res = isl.isl_map_is_strict_subset(arg0.ptr, arg1.ptr) - if res < 0: + res = isl.isl_id_get_name(arg0.ptr) + if res == 0: raise - return bool(res) - def is_subset(arg0, arg1): + string = cast(res, c_char_p).value.decode('ascii') + return string + def get_name(arg0): + return arg0.name() + +isl.isl_id_read_from_str.restype = c_void_p +isl.isl_id_read_from_str.argtypes = [Context, c_char_p] +isl.isl_id_get_name.restype = POINTER(c_char) +isl.isl_id_get_name.argtypes = [c_void_p] +isl.isl_id_copy.restype = c_void_p +isl.isl_id_copy.argtypes = [c_void_p] +isl.isl_id_free.restype = c_void_p +isl.isl_id_free.argtypes = [c_void_p] +isl.isl_id_to_str.restype = POINTER(c_char) +isl.isl_id_to_str.argtypes = [c_void_p] + +class id_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_id_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and (args[0].__class__ is id or type(args[0]) == str): + args = list(args) + try: + if not args[0].__class__ is id: + args[0] = id(args[0]) + except: + raise + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_id_list_from_id(isl.isl_id_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_id_list_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: raise + ptr = isl.isl_id_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.id_list("""%s""")' % s + else: + return 'isl.id_list("%s")' % s + def add(arg0, arg1): try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: - return union_map(arg0).is_subset(arg1) - ctx = arg0.ctx - res = isl.isl_map_is_subset(arg0.ptr, arg1.ptr) - if res < 0: raise - return bool(res) - def lexmax(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg1.__class__ is id: + arg1 = id(arg1) except: raise ctx = arg0.ctx - res = isl.isl_map_lexmax(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_id_list_add(isl.isl_id_list_copy(arg0.ptr), isl.isl_id_copy(arg1.ptr)) + obj = id_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_map_lexmin(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def polyhedral_hull(arg0): + res = isl.isl_id_list_clear(isl.isl_id_list_copy(arg0.ptr)) + obj = id_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_map_polyhedral_hull(isl.isl_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def reverse(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg1.__class__ is id_list: + arg1 = id_list(arg1) except: raise ctx = arg0.ctx - res = isl.isl_map_reverse(isl.isl_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def sample(arg0): + res = isl.isl_id_list_concat(isl.isl_id_list_copy(arg0.ptr), isl.isl_id_list_copy(arg1.ptr)) + obj = id_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = id(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_map_sample(isl.isl_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def subtract(arg0, arg1): + res = isl.isl_id_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_id_list_get_at(arg0.ptr, arg1) + obj = id(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg0.__class__ is id_list: + arg0 = id_list(arg0) except: - return union_map(arg0).subtract(arg1) + raise ctx = arg0.ctx - res = isl.isl_map_subtract(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_id_list_size(arg0.ptr) + if res < 0: + raise + return int(res) + +isl.isl_id_list_alloc.restype = c_void_p +isl.isl_id_list_alloc.argtypes = [Context, c_int] +isl.isl_id_list_from_id.restype = c_void_p +isl.isl_id_list_from_id.argtypes = [c_void_p] +isl.isl_id_list_add.restype = c_void_p +isl.isl_id_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_id_list_clear.restype = c_void_p +isl.isl_id_list_clear.argtypes = [c_void_p] +isl.isl_id_list_concat.restype = c_void_p +isl.isl_id_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_id_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_id_list_get_at.restype = c_void_p +isl.isl_id_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_id_list_size.argtypes = [c_void_p] +isl.isl_id_list_copy.restype = c_void_p +isl.isl_id_list_copy.argtypes = [c_void_p] +isl.isl_id_list_free.restype = c_void_p +isl.isl_id_list_free.argtypes = [c_void_p] +isl.isl_id_list_to_str.restype = POINTER(c_char) +isl.isl_id_list_to_str.argtypes = [c_void_p] + +class multi_id(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 2 and args[0].__class__ is space and args[1].__class__ is id_list: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_id_from_id_list(isl.isl_space_copy(args[0].ptr), isl.isl_id_list_copy(args[1].ptr)) + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_id_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_multi_id_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) except: raise + ptr = isl.isl_multi_id_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.multi_id("""%s""")' % s + else: + return 'isl.multi_id("%s")' % s + def flat_range_product(arg0, arg1): try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) except: - return union_map(arg0).union(arg1) - ctx = arg0.ctx - res = isl.isl_map_union(isl.isl_map_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) - def unshifted_simple_hull(arg0): + raise try: - if not arg0.__class__ is map: - arg0 = map(arg0) + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) except: raise ctx = arg0.ctx - res = isl.isl_map_unshifted_simple_hull(isl.isl_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - -isl.isl_map_read_from_str.restype = c_void_p -isl.isl_map_read_from_str.argtypes = [Context, c_char_p] -isl.isl_map_from_basic_map.restype = c_void_p -isl.isl_map_from_basic_map.argtypes = [c_void_p] -isl.isl_map_affine_hull.restype = c_void_p -isl.isl_map_affine_hull.argtypes = [c_void_p] -isl.isl_map_apply_domain.restype = c_void_p -isl.isl_map_apply_domain.argtypes = [c_void_p, c_void_p] -isl.isl_map_apply_range.restype = c_void_p -isl.isl_map_apply_range.argtypes = [c_void_p, c_void_p] -isl.isl_map_coalesce.restype = c_void_p -isl.isl_map_coalesce.argtypes = [c_void_p] -isl.isl_map_complement.restype = c_void_p -isl.isl_map_complement.argtypes = [c_void_p] -isl.isl_map_deltas.restype = c_void_p -isl.isl_map_deltas.argtypes = [c_void_p] -isl.isl_map_detect_equalities.restype = c_void_p -isl.isl_map_detect_equalities.argtypes = [c_void_p] -isl.isl_map_flatten.restype = c_void_p -isl.isl_map_flatten.argtypes = [c_void_p] -isl.isl_map_flatten_domain.restype = c_void_p -isl.isl_map_flatten_domain.argtypes = [c_void_p] -isl.isl_map_flatten_range.restype = c_void_p -isl.isl_map_flatten_range.argtypes = [c_void_p] -isl.isl_map_foreach_basic_map.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_map_gist.restype = c_void_p -isl.isl_map_gist.argtypes = [c_void_p, c_void_p] -isl.isl_map_gist_domain.restype = c_void_p -isl.isl_map_gist_domain.argtypes = [c_void_p, c_void_p] -isl.isl_map_intersect.restype = c_void_p -isl.isl_map_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_map_intersect_domain.restype = c_void_p -isl.isl_map_intersect_domain.argtypes = [c_void_p, c_void_p] -isl.isl_map_intersect_params.restype = c_void_p -isl.isl_map_intersect_params.argtypes = [c_void_p, c_void_p] -isl.isl_map_intersect_range.restype = c_void_p -isl.isl_map_intersect_range.argtypes = [c_void_p, c_void_p] -isl.isl_map_is_bijective.restype = c_bool -isl.isl_map_is_bijective.argtypes = [c_void_p] -isl.isl_map_is_disjoint.restype = c_bool -isl.isl_map_is_disjoint.argtypes = [c_void_p, c_void_p] -isl.isl_map_is_empty.restype = c_bool -isl.isl_map_is_empty.argtypes = [c_void_p] -isl.isl_map_is_equal.restype = c_bool -isl.isl_map_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_map_is_injective.restype = c_bool -isl.isl_map_is_injective.argtypes = [c_void_p] -isl.isl_map_is_single_valued.restype = c_bool -isl.isl_map_is_single_valued.argtypes = [c_void_p] -isl.isl_map_is_strict_subset.restype = c_bool -isl.isl_map_is_strict_subset.argtypes = [c_void_p, c_void_p] -isl.isl_map_is_subset.restype = c_bool -isl.isl_map_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_map_lexmax.restype = c_void_p -isl.isl_map_lexmax.argtypes = [c_void_p] -isl.isl_map_lexmin.restype = c_void_p -isl.isl_map_lexmin.argtypes = [c_void_p] -isl.isl_map_polyhedral_hull.restype = c_void_p -isl.isl_map_polyhedral_hull.argtypes = [c_void_p] -isl.isl_map_reverse.restype = c_void_p -isl.isl_map_reverse.argtypes = [c_void_p] -isl.isl_map_sample.restype = c_void_p -isl.isl_map_sample.argtypes = [c_void_p] -isl.isl_map_subtract.restype = c_void_p -isl.isl_map_subtract.argtypes = [c_void_p, c_void_p] -isl.isl_map_union.restype = c_void_p -isl.isl_map_union.argtypes = [c_void_p, c_void_p] -isl.isl_map_unshifted_simple_hull.restype = c_void_p -isl.isl_map_unshifted_simple_hull.argtypes = [c_void_p] -isl.isl_map_copy.restype = c_void_p -isl.isl_map_copy.argtypes = [c_void_p] -isl.isl_map_free.restype = c_void_p -isl.isl_map_free.argtypes = [c_void_p] -isl.isl_map_to_str.restype = POINTER(c_char) -isl.isl_map_to_str.argtypes = [c_void_p] + res = isl.isl_multi_id_flat_range_product(isl.isl_multi_id_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_id(ctx=ctx, ptr=res) + return obj + def at(arg0, arg1): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_get_at(arg0.ptr, arg1) + obj = id(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def space(arg0): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def plain_is_equal(arg0, arg1): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_plain_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def range_product(arg0, arg1): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + try: + if not arg1.__class__ is multi_id: + arg1 = multi_id(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_range_product(isl.isl_multi_id_copy(arg0.ptr), isl.isl_multi_id_copy(arg1.ptr)) + obj = multi_id(ctx=ctx, ptr=res) + return obj + def set_at(arg0, arg1, arg2): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + try: + if not arg2.__class__ is id: + arg2 = id(arg2) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_set_at(isl.isl_multi_id_copy(arg0.ptr), arg1, isl.isl_id_copy(arg2.ptr)) + obj = multi_id(ctx=ctx, ptr=res) + return obj + def size(arg0): + try: + if not arg0.__class__ is multi_id: + arg0 = multi_id(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_id_size(arg0.ptr) + if res < 0: + raise + return int(res) -class basic_map(map): +isl.isl_multi_id_from_id_list.restype = c_void_p +isl.isl_multi_id_from_id_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_id_read_from_str.restype = c_void_p +isl.isl_multi_id_read_from_str.argtypes = [Context, c_char_p] +isl.isl_multi_id_flat_range_product.restype = c_void_p +isl.isl_multi_id_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_id_get_at.restype = c_void_p +isl.isl_multi_id_get_at.argtypes = [c_void_p, c_int] +isl.isl_multi_id_get_space.restype = c_void_p +isl.isl_multi_id_get_space.argtypes = [c_void_p] +isl.isl_multi_id_plain_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_multi_id_range_product.restype = c_void_p +isl.isl_multi_id_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_id_set_at.restype = c_void_p +isl.isl_multi_id_set_at.argtypes = [c_void_p, c_int, c_void_p] +isl.isl_multi_id_size.argtypes = [c_void_p] +isl.isl_multi_id_copy.restype = c_void_p +isl.isl_multi_id_copy.argtypes = [c_void_p] +isl.isl_multi_id_free.restype = c_void_p +isl.isl_multi_id_free.argtypes = [c_void_p] +isl.isl_multi_id_to_str.restype = POINTER(c_char) +isl.isl_multi_id_to_str.argtypes = [c_void_p] + +class multi_val(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return + if len(args) == 2 and args[0].__class__ is space and args[1].__class__ is val_list: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_multi_val_from_val_list(isl.isl_space_copy(args[0].ptr), isl.isl_val_list_copy(args[1].ptr)) + return if len(args) == 1 and type(args[0]) == str: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_basic_map_read_from_str(self.ctx, args[0].encode('ascii')) + self.ptr = isl.isl_multi_val_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_basic_map_free(self.ptr) + isl.isl_multi_val_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: raise - ptr = isl.isl_basic_map_to_str(arg0.ptr) + ptr = isl.isl_multi_val_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.basic_map("""%s""")' % s + return 'isl.multi_val("""%s""")' % s else: - return 'isl.basic_map("%s")' % s - def affine_hull(arg0): + return 'isl.multi_val("%s")' % s + def add(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_val_add(isl.isl_multi_val_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_val_add_val(isl.isl_multi_val_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + raise Error + def flat_range_product(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_basic_map_affine_hull(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def apply_domain(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: raise + ctx = arg0.ctx + res = isl.isl_multi_val_flat_range_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def at(arg0, arg1): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: - return map(arg0).apply_domain(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_apply_domain(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def apply_range(arg0, arg1): + res = isl.isl_multi_val_get_at(arg0.ptr, arg1) + obj = val(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def space(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_multi_val_get_space(arg0.ptr) + obj = space(ctx=ctx, ptr=res) + return obj + def get_space(arg0): + return arg0.space() + def neg(arg0): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: - return map(arg0).apply_range(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_apply_range(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def deltas(arg0): + res = isl.isl_multi_val_neg(isl.isl_multi_val_copy(arg0.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def plain_is_equal(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) + except: + raise + try: + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_deltas(isl.isl_basic_map_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_multi_val_plain_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def product(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) + except: + raise + try: + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_detect_equalities(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def flatten(arg0): + res = isl.isl_multi_val_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def range_product(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) + except: + raise + try: + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_flatten(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def flatten_domain(arg0): + res = isl.isl_multi_val_range_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def scale(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_val_scale_multi_val(isl.isl_multi_val_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_val_scale_val(isl.isl_multi_val_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + raise Error + def scale_down(*args): + if len(args) == 2 and args[1].__class__ is multi_val: + ctx = args[0].ctx + res = isl.isl_multi_val_scale_down_multi_val(isl.isl_multi_val_copy(args[0].ptr), isl.isl_multi_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + if len(args) == 2 and (args[1].__class__ is val or type(args[1]) == int): + args = list(args) + try: + if not args[1].__class__ is val: + args[1] = val(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_multi_val_scale_down_val(isl.isl_multi_val_copy(args[0].ptr), isl.isl_val_copy(args[1].ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + raise Error + def set_at(arg0, arg1, arg2): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) + except: + raise + try: + if not arg2.__class__ is val: + arg2 = val(arg2) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_flatten_domain(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def flatten_range(arg0): + res = isl.isl_multi_val_set_at(isl.isl_multi_val_copy(arg0.ptr), arg1, isl.isl_val_copy(arg2.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + def size(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_flatten_range(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def gist(arg0, arg1): + res = isl.isl_multi_val_size(arg0.ptr) + if res < 0: + raise + return int(res) + def sub(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is multi_val: + arg0 = multi_val(arg0) except: raise try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: - return map(arg0).gist(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_gist(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_multi_val_sub(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + @staticmethod + def zero(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_multi_val_zero(isl.isl_space_copy(arg0.ptr)) + obj = multi_val(ctx=ctx, ptr=res) + return obj + +isl.isl_multi_val_from_val_list.restype = c_void_p +isl.isl_multi_val_from_val_list.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_read_from_str.restype = c_void_p +isl.isl_multi_val_read_from_str.argtypes = [Context, c_char_p] +isl.isl_multi_val_add.restype = c_void_p +isl.isl_multi_val_add.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_add_val.restype = c_void_p +isl.isl_multi_val_add_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_flat_range_product.restype = c_void_p +isl.isl_multi_val_flat_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_get_at.restype = c_void_p +isl.isl_multi_val_get_at.argtypes = [c_void_p, c_int] +isl.isl_multi_val_get_space.restype = c_void_p +isl.isl_multi_val_get_space.argtypes = [c_void_p] +isl.isl_multi_val_neg.restype = c_void_p +isl.isl_multi_val_neg.argtypes = [c_void_p] +isl.isl_multi_val_plain_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_product.restype = c_void_p +isl.isl_multi_val_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_range_product.restype = c_void_p +isl.isl_multi_val_range_product.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_scale_multi_val.restype = c_void_p +isl.isl_multi_val_scale_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_scale_val.restype = c_void_p +isl.isl_multi_val_scale_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_scale_down_multi_val.restype = c_void_p +isl.isl_multi_val_scale_down_multi_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_scale_down_val.restype = c_void_p +isl.isl_multi_val_scale_down_val.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_set_at.restype = c_void_p +isl.isl_multi_val_set_at.argtypes = [c_void_p, c_int, c_void_p] +isl.isl_multi_val_size.argtypes = [c_void_p] +isl.isl_multi_val_sub.restype = c_void_p +isl.isl_multi_val_sub.argtypes = [c_void_p, c_void_p] +isl.isl_multi_val_zero.restype = c_void_p +isl.isl_multi_val_zero.argtypes = [c_void_p] +isl.isl_multi_val_copy.restype = c_void_p +isl.isl_multi_val_copy.argtypes = [c_void_p] +isl.isl_multi_val_free.restype = c_void_p +isl.isl_multi_val_free.argtypes = [c_void_p] +isl.isl_multi_val_to_str.restype = POINTER(c_char) +isl.isl_multi_val_to_str.argtypes = [c_void_p] + +class point(basic_set): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_point_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is point: + arg0 = point(arg0) + except: + raise + ptr = isl.isl_point_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.point("""%s""")' % s + else: + return 'isl.point("%s")' % s + +isl.isl_point_copy.restype = c_void_p +isl.isl_point_copy.argtypes = [c_void_p] +isl.isl_point_free.restype = c_void_p +isl.isl_point_free.argtypes = [c_void_p] +isl.isl_point_to_str.restype = POINTER(c_char) +isl.isl_point_to_str.argtypes = [c_void_p] + +class pw_aff_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_aff_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and args[0].__class__ is pw_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_aff_list_from_pw_aff(isl.isl_pw_aff_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_pw_aff_list_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) + except: + raise + ptr = isl.isl_pw_aff_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.pw_aff_list("""%s""")' % s + else: + return 'isl.pw_aff_list("%s")' % s + def add(arg0, arg1): + try: + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) + except: + raise + try: + if not arg1.__class__ is pw_aff: + arg1 = pw_aff(arg1) except: raise + ctx = arg0.ctx + res = isl.isl_pw_aff_list_add(isl.isl_pw_aff_list_copy(arg0.ptr), isl.isl_pw_aff_copy(arg1.ptr)) + obj = pw_aff_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) except: - return map(arg0).intersect(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_intersect(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def intersect_domain(arg0, arg1): + res = isl.isl_pw_aff_list_clear(isl.isl_pw_aff_list_copy(arg0.ptr)) + obj = pw_aff_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) except: raise try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg1.__class__ is pw_aff_list: + arg1 = pw_aff_list(arg1) except: - return map(arg0).intersect_domain(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_intersect_domain(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def intersect_range(arg0, arg1): + res = isl.isl_pw_aff_list_concat(isl.isl_pw_aff_list_copy(arg0.ptr), isl.isl_pw_aff_list_copy(arg1.ptr)) + obj = pw_aff_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = pw_aff(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_pw_aff_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: raise + def at(arg0, arg1): try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) except: - return map(arg0).intersect_range(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_intersect_range(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return basic_map(ctx=ctx, ptr=res) - def is_empty(arg0): + res = isl.isl_pw_aff_list_get_at(arg0.ptr, arg1) + obj = pw_aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_aff_list: + arg0 = pw_aff_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_is_empty(arg0.ptr) + res = isl.isl_pw_aff_list_size(arg0.ptr) if res < 0: raise - return bool(res) - def is_equal(arg0, arg1): + return int(res) + +isl.isl_pw_aff_list_alloc.restype = c_void_p +isl.isl_pw_aff_list_alloc.argtypes = [Context, c_int] +isl.isl_pw_aff_list_from_pw_aff.restype = c_void_p +isl.isl_pw_aff_list_from_pw_aff.argtypes = [c_void_p] +isl.isl_pw_aff_list_add.restype = c_void_p +isl.isl_pw_aff_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_list_clear.restype = c_void_p +isl.isl_pw_aff_list_clear.argtypes = [c_void_p] +isl.isl_pw_aff_list_concat.restype = c_void_p +isl.isl_pw_aff_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_pw_aff_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_pw_aff_list_get_at.restype = c_void_p +isl.isl_pw_aff_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_pw_aff_list_size.argtypes = [c_void_p] +isl.isl_pw_aff_list_copy.restype = c_void_p +isl.isl_pw_aff_list_copy.argtypes = [c_void_p] +isl.isl_pw_aff_list_free.restype = c_void_p +isl.isl_pw_aff_list_free.argtypes = [c_void_p] +isl.isl_pw_aff_list_to_str.restype = POINTER(c_char) +isl.isl_pw_aff_list_to_str.argtypes = [c_void_p] + +class pw_multi_aff_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_multi_aff_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and args[0].__class__ is pw_multi_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_pw_multi_aff_list_from_pw_multi_aff(isl.isl_pw_multi_aff_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_pw_multi_aff_list_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) except: raise + ptr = isl.isl_pw_multi_aff_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.pw_multi_aff_list("""%s""")' % s + else: + return 'isl.pw_multi_aff_list("%s")' % s + def add(arg0, arg1): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) except: - return map(arg0).is_equal(arg1) + raise + try: + if not arg1.__class__ is pw_multi_aff: + arg1 = pw_multi_aff(arg1) + except: + raise ctx = arg0.ctx - res = isl.isl_basic_map_is_equal(arg0.ptr, arg1.ptr) - if res < 0: + res = isl.isl_pw_multi_aff_list_add(isl.isl_pw_multi_aff_list_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) + obj = pw_multi_aff_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): + try: + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) + except: raise - return bool(res) - def is_subset(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_list_clear(isl.isl_pw_multi_aff_list_copy(arg0.ptr)) + obj = pw_multi_aff_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) except: raise try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg1.__class__ is pw_multi_aff_list: + arg1 = pw_multi_aff_list(arg1) except: - return map(arg0).is_subset(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_is_subset(arg0.ptr, arg1.ptr) + res = isl.isl_pw_multi_aff_list_concat(isl.isl_pw_multi_aff_list_copy(arg0.ptr), isl.isl_pw_multi_aff_list_copy(arg1.ptr)) + obj = pw_multi_aff_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): + try: + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = pw_multi_aff(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_pw_multi_aff_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) if res < 0: raise - return bool(res) - def lexmax(arg0): + def at(arg0, arg1): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_lexmax(isl.isl_basic_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_pw_multi_aff_list_get_at(arg0.ptr, arg1) + obj = pw_multi_aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is pw_multi_aff_list: + arg0 = pw_multi_aff_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_lexmin(isl.isl_basic_map_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def reverse(arg0): + res = isl.isl_pw_multi_aff_list_size(arg0.ptr) + if res < 0: + raise + return int(res) + +isl.isl_pw_multi_aff_list_alloc.restype = c_void_p +isl.isl_pw_multi_aff_list_alloc.argtypes = [Context, c_int] +isl.isl_pw_multi_aff_list_from_pw_multi_aff.restype = c_void_p +isl.isl_pw_multi_aff_list_from_pw_multi_aff.argtypes = [c_void_p] +isl.isl_pw_multi_aff_list_add.restype = c_void_p +isl.isl_pw_multi_aff_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_list_clear.restype = c_void_p +isl.isl_pw_multi_aff_list_clear.argtypes = [c_void_p] +isl.isl_pw_multi_aff_list_concat.restype = c_void_p +isl.isl_pw_multi_aff_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_pw_multi_aff_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_pw_multi_aff_list_get_at.restype = c_void_p +isl.isl_pw_multi_aff_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_pw_multi_aff_list_size.argtypes = [c_void_p] +isl.isl_pw_multi_aff_list_copy.restype = c_void_p +isl.isl_pw_multi_aff_list_copy.argtypes = [c_void_p] +isl.isl_pw_multi_aff_list_free.restype = c_void_p +isl.isl_pw_multi_aff_list_free.argtypes = [c_void_p] +isl.isl_pw_multi_aff_list_to_str.restype = POINTER(c_char) +isl.isl_pw_multi_aff_list_to_str.argtypes = [c_void_p] + +class schedule(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == str: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_schedule_read_from_str(self.ctx, args[0].encode('ascii')) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_free(self.ptr) + def __str__(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is schedule: + arg0 = schedule(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_basic_map_reverse(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def sample(arg0): + ptr = isl.isl_schedule_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule("""%s""")' % s + else: + return 'isl.schedule("%s")' % s + @staticmethod + def from_domain(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is union_set: + arg0 = union_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_map_sample(isl.isl_basic_map_copy(arg0.ptr)) - return basic_map(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_schedule_from_domain(isl.isl_union_set_copy(arg0.ptr)) + obj = schedule(ctx=ctx, ptr=res) + return obj + def map(arg0): try: - if not arg0.__class__ is basic_map: - arg0 = basic_map(arg0) + if not arg0.__class__ is schedule: + arg0 = schedule(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_get_map(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_map(arg0): + return arg0.map() + def root(arg0): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is schedule: + arg0 = schedule(arg0) except: - return map(arg0).union(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_map_union(isl.isl_basic_map_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return map(ctx=ctx, ptr=res) + res = isl.isl_schedule_get_root(arg0.ptr) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def get_root(arg0): + return arg0.root() + def pullback(*args): + if len(args) == 2 and args[1].__class__ is union_pw_multi_aff: + ctx = args[0].ctx + res = isl.isl_schedule_pullback_union_pw_multi_aff(isl.isl_schedule_copy(args[0].ptr), isl.isl_union_pw_multi_aff_copy(args[1].ptr)) + obj = schedule(ctx=ctx, ptr=res) + return obj + raise Error -isl.isl_basic_map_read_from_str.restype = c_void_p -isl.isl_basic_map_read_from_str.argtypes = [Context, c_char_p] -isl.isl_basic_map_affine_hull.restype = c_void_p -isl.isl_basic_map_affine_hull.argtypes = [c_void_p] -isl.isl_basic_map_apply_domain.restype = c_void_p -isl.isl_basic_map_apply_domain.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_apply_range.restype = c_void_p -isl.isl_basic_map_apply_range.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_deltas.restype = c_void_p -isl.isl_basic_map_deltas.argtypes = [c_void_p] -isl.isl_basic_map_detect_equalities.restype = c_void_p -isl.isl_basic_map_detect_equalities.argtypes = [c_void_p] -isl.isl_basic_map_flatten.restype = c_void_p -isl.isl_basic_map_flatten.argtypes = [c_void_p] -isl.isl_basic_map_flatten_domain.restype = c_void_p -isl.isl_basic_map_flatten_domain.argtypes = [c_void_p] -isl.isl_basic_map_flatten_range.restype = c_void_p -isl.isl_basic_map_flatten_range.argtypes = [c_void_p] -isl.isl_basic_map_gist.restype = c_void_p -isl.isl_basic_map_gist.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_intersect.restype = c_void_p -isl.isl_basic_map_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_intersect_domain.restype = c_void_p -isl.isl_basic_map_intersect_domain.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_intersect_range.restype = c_void_p -isl.isl_basic_map_intersect_range.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_is_empty.restype = c_bool -isl.isl_basic_map_is_empty.argtypes = [c_void_p] -isl.isl_basic_map_is_equal.restype = c_bool -isl.isl_basic_map_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_is_subset.restype = c_bool -isl.isl_basic_map_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_lexmax.restype = c_void_p -isl.isl_basic_map_lexmax.argtypes = [c_void_p] -isl.isl_basic_map_lexmin.restype = c_void_p -isl.isl_basic_map_lexmin.argtypes = [c_void_p] -isl.isl_basic_map_reverse.restype = c_void_p -isl.isl_basic_map_reverse.argtypes = [c_void_p] -isl.isl_basic_map_sample.restype = c_void_p -isl.isl_basic_map_sample.argtypes = [c_void_p] -isl.isl_basic_map_union.restype = c_void_p -isl.isl_basic_map_union.argtypes = [c_void_p, c_void_p] -isl.isl_basic_map_copy.restype = c_void_p -isl.isl_basic_map_copy.argtypes = [c_void_p] -isl.isl_basic_map_free.restype = c_void_p -isl.isl_basic_map_free.argtypes = [c_void_p] -isl.isl_basic_map_to_str.restype = POINTER(c_char) -isl.isl_basic_map_to_str.argtypes = [c_void_p] +isl.isl_schedule_read_from_str.restype = c_void_p +isl.isl_schedule_read_from_str.argtypes = [Context, c_char_p] +isl.isl_schedule_from_domain.restype = c_void_p +isl.isl_schedule_from_domain.argtypes = [c_void_p] +isl.isl_schedule_get_map.restype = c_void_p +isl.isl_schedule_get_map.argtypes = [c_void_p] +isl.isl_schedule_get_root.restype = c_void_p +isl.isl_schedule_get_root.argtypes = [c_void_p] +isl.isl_schedule_pullback_union_pw_multi_aff.restype = c_void_p +isl.isl_schedule_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_copy.restype = c_void_p +isl.isl_schedule_copy.argtypes = [c_void_p] +isl.isl_schedule_free.restype = c_void_p +isl.isl_schedule_free.argtypes = [c_void_p] +isl.isl_schedule_to_str.restype = POINTER(c_char) +isl.isl_schedule_to_str.argtypes = [c_void_p] -class union_set(object): +class schedule_constraints(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] - return - if len(args) == 1 and args[0].__class__ is basic_set: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_set_from_basic_set(isl.isl_basic_set_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is set: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_set_from_set(isl.isl_set_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is point: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_set_from_point(isl.isl_point_copy(args[0].ptr)) return if len(args) == 1 and type(args[0]) == str: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_set_read_from_str(self.ctx, args[0].encode('ascii')) + self.ptr = isl.isl_schedule_constraints_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_union_set_free(self.ptr) + isl.isl_schedule_constraints_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise - ptr = isl.isl_union_set_to_str(arg0.ptr) + ptr = isl.isl_schedule_constraints_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.union_set("""%s""")' % s + return 'isl.schedule_constraints("""%s""")' % s else: - return 'isl.union_set("%s")' % s - def affine_hull(arg0): + return 'isl.schedule_constraints("%s")' % s + def compute_schedule(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_affine_hull(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def apply(arg0, arg1): + res = isl.isl_schedule_constraints_compute_schedule(isl.isl_schedule_constraints_copy(arg0.ptr)) + obj = schedule(ctx=ctx, ptr=res) + return obj + def coincidence(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_constraints_get_coincidence(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_coincidence(arg0): + return arg0.coincidence() + def conditional_validity(arg0): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_apply(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def coalesce(arg0): + res = isl.isl_schedule_constraints_get_conditional_validity(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_conditional_validity(arg0): + return arg0.conditional_validity() + def conditional_validity_condition(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_coalesce(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def compute_divs(arg0): + res = isl.isl_schedule_constraints_get_conditional_validity_condition(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_conditional_validity_condition(arg0): + return arg0.conditional_validity_condition() + def context(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_compute_divs(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_schedule_constraints_get_context(arg0.ptr) + obj = set(ctx=ctx, ptr=res) + return obj + def get_context(arg0): + return arg0.context() + def domain(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_detect_equalities(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def foreach_point(arg0, arg1): + res = isl.isl_schedule_constraints_get_domain(arg0.ptr) + obj = union_set(ctx=ctx, ptr=res) + return obj + def get_domain(arg0): + return arg0.domain() + def proximity(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise - exc_info = [None] - fn = CFUNCTYPE(c_int, c_void_p, c_void_p) - def cb_func(cb_arg0, cb_arg1): - cb_arg0 = point(ctx=arg0.ctx, ptr=cb_arg0) - try: - arg1(cb_arg0) - except: - import sys - exc_info[0] = sys.exc_info() - return -1 - return 0 - cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_set_foreach_point(arg0.ptr, cb, None) - if exc_info[0] != None: - raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) - return res - def foreach_set(arg0, arg1): + res = isl.isl_schedule_constraints_get_proximity(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_proximity(arg0): + return arg0.proximity() + def validity(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise - exc_info = [None] - fn = CFUNCTYPE(c_int, c_void_p, c_void_p) - def cb_func(cb_arg0, cb_arg1): - cb_arg0 = set(ctx=arg0.ctx, ptr=cb_arg0) - try: - arg1(cb_arg0) - except: - import sys - exc_info[0] = sys.exc_info() - return -1 - return 0 - cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_set_foreach_set(arg0.ptr, cb, None) - if exc_info[0] != None: - raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) - return res - def gist(arg0, arg1): + res = isl.isl_schedule_constraints_get_validity(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_validity(arg0): + return arg0.validity() + @staticmethod + def on_domain(arg0): try: if not arg0.__class__ is union_set: arg0 = union_set(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_schedule_constraints_on_domain(isl.isl_union_set_copy(arg0.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + def set_coincidence(arg0, arg1): + try: + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_set_gist(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def gist_params(arg0, arg1): + res = isl.isl_schedule_constraints_set_coincidence(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + def set_conditional_validity(arg0, arg1, arg2): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) + except: + raise + try: + if not arg2.__class__ is union_map: + arg2 = union_map(arg2) except: raise ctx = arg0.ctx - res = isl.isl_union_set_gist_params(isl.isl_union_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def identity(arg0): + res = isl.isl_schedule_constraints_set_conditional_validity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr), isl.isl_union_map_copy(arg2.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + def set_context(arg0, arg1): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) + except: + raise + try: + if not arg1.__class__ is set: + arg1 = set(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_set_identity(isl.isl_union_set_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_schedule_constraints_set_context(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + def set_proximity(arg0, arg1): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_set_intersect(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def intersect_params(arg0, arg1): + res = isl.isl_schedule_constraints_set_proximity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + def set_validity(arg0, arg1): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_constraints: + arg0 = schedule_constraints(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_set_intersect_params(isl.isl_union_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def is_empty(arg0): + res = isl.isl_schedule_constraints_set_validity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = schedule_constraints(ctx=ctx, ptr=res) + return obj + +isl.isl_schedule_constraints_read_from_str.restype = c_void_p +isl.isl_schedule_constraints_read_from_str.argtypes = [Context, c_char_p] +isl.isl_schedule_constraints_compute_schedule.restype = c_void_p +isl.isl_schedule_constraints_compute_schedule.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_coincidence.restype = c_void_p +isl.isl_schedule_constraints_get_coincidence.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_conditional_validity.restype = c_void_p +isl.isl_schedule_constraints_get_conditional_validity.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_conditional_validity_condition.restype = c_void_p +isl.isl_schedule_constraints_get_conditional_validity_condition.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_context.restype = c_void_p +isl.isl_schedule_constraints_get_context.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_domain.restype = c_void_p +isl.isl_schedule_constraints_get_domain.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_proximity.restype = c_void_p +isl.isl_schedule_constraints_get_proximity.argtypes = [c_void_p] +isl.isl_schedule_constraints_get_validity.restype = c_void_p +isl.isl_schedule_constraints_get_validity.argtypes = [c_void_p] +isl.isl_schedule_constraints_on_domain.restype = c_void_p +isl.isl_schedule_constraints_on_domain.argtypes = [c_void_p] +isl.isl_schedule_constraints_set_coincidence.restype = c_void_p +isl.isl_schedule_constraints_set_coincidence.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_constraints_set_conditional_validity.restype = c_void_p +isl.isl_schedule_constraints_set_conditional_validity.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_schedule_constraints_set_context.restype = c_void_p +isl.isl_schedule_constraints_set_context.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_constraints_set_proximity.restype = c_void_p +isl.isl_schedule_constraints_set_proximity.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_constraints_set_validity.restype = c_void_p +isl.isl_schedule_constraints_set_validity.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_constraints_copy.restype = c_void_p +isl.isl_schedule_constraints_copy.argtypes = [c_void_p] +isl.isl_schedule_constraints_free.restype = c_void_p +isl.isl_schedule_constraints_free.argtypes = [c_void_p] +isl.isl_schedule_constraints_to_str.restype = POINTER(c_char) +isl.isl_schedule_constraints_to_str.argtypes = [c_void_p] + +class schedule_node(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and isinstance(args[0], schedule_node_band): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_context): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_domain): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_expansion): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_extension): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_filter): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_leaf): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_guard): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_mark): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_sequence): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + if len(args) == 1 and isinstance(args[0], schedule_node_set): + self.ctx = args[0].ctx + self.ptr = isl.isl_schedule_node_copy(args[0].ptr) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + if "ptr" in keywords: + type = isl.isl_schedule_node_get_type(keywords["ptr"]) + if type == 0: + return schedule_node_band(**keywords) + if type == 1: + return schedule_node_context(**keywords) + if type == 2: + return schedule_node_domain(**keywords) + if type == 3: + return schedule_node_expansion(**keywords) + if type == 4: + return schedule_node_extension(**keywords) + if type == 5: + return schedule_node_filter(**keywords) + if type == 6: + return schedule_node_leaf(**keywords) + if type == 7: + return schedule_node_guard(**keywords) + if type == 8: + return schedule_node_mark(**keywords) + if type == 9: + return schedule_node_sequence(**keywords) + if type == 10: + return schedule_node_set(**keywords) + raise + return super(schedule_node, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: + raise + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node("""%s""")' % s + else: + return 'isl.schedule_node("%s")' % s + def ancestor(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_is_empty(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_equal(arg0, arg1): + res = isl.isl_schedule_node_ancestor(isl.isl_schedule_node_copy(arg0.ptr), arg1) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def child(arg0, arg1): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_node_child(isl.isl_schedule_node_copy(arg0.ptr), arg1) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def every_descendant(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = schedule_node(ctx=arg0.ctx, ptr=isl.isl_schedule_node_copy(cb_arg0)) + try: + res = arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 1 if res else 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_set_is_equal(arg0.ptr, arg1.ptr) + res = isl.isl_schedule_node_every_descendant(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) if res < 0: raise return bool(res) - def is_strict_subset(arg0, arg1): + def first_child(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_node_first_child(isl.isl_schedule_node_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def foreach_ancestor_top_down(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = schedule_node(ctx=arg0.ctx, ptr=isl.isl_schedule_node_copy(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_set_is_strict_subset(arg0.ptr, arg1.ptr) + res = isl.isl_schedule_node_foreach_ancestor_top_down(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) if res < 0: - raise - return bool(res) - def is_subset(arg0, arg1): - try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) - except: raise + def foreach_descendant_top_down(arg0, arg1): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = schedule_node(ctx=arg0.ctx, ptr=isl.isl_schedule_node_copy(cb_arg0)) + try: + res = arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 1 if res else 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_set_is_subset(arg0.ptr, arg1.ptr) + res = isl.isl_schedule_node_foreach_descendant_top_down(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) if res < 0: raise - return bool(res) - def lexmax(arg0): + @staticmethod + def from_domain(arg0): try: if not arg0.__class__ is union_set: arg0 = union_set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_lexmax(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_schedule_node_from_domain(isl.isl_union_set_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + @staticmethod + def from_extension(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is union_map: + arg0 = union_map(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_lexmin(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def polyhedral_hull(arg0): + res = isl.isl_schedule_node_from_extension(isl.isl_union_map_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def ancestor_child_position(arg0, arg1): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_set_polyhedral_hull(isl.isl_union_set_copy(arg0.ptr)) - return union_set(ctx=ctx, ptr=res) - def preimage(arg0, arg1): - if arg1.__class__ is multi_aff: - res = isl.isl_union_set_preimage_multi_aff(isl.isl_union_set_copy(arg0.ptr), isl.isl_multi_aff_copy(arg1.ptr)) - return union_set(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is pw_multi_aff: - res = isl.isl_union_set_preimage_pw_multi_aff(isl.isl_union_set_copy(arg0.ptr), isl.isl_pw_multi_aff_copy(arg1.ptr)) - return union_set(ctx=arg0.ctx, ptr=res) - if arg1.__class__ is union_pw_multi_aff: - res = isl.isl_union_set_preimage_union_pw_multi_aff(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return union_set(ctx=arg0.ctx, ptr=res) - def sample_point(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg1.__class__ is schedule_node: + arg1 = schedule_node(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_set_sample_point(isl.isl_union_set_copy(arg0.ptr)) - return point(ctx=ctx, ptr=res) - def subtract(arg0, arg1): + res = isl.isl_schedule_node_get_ancestor_child_position(arg0.ptr, arg1.ptr) + if res < 0: + raise + return int(res) + def get_ancestor_child_position(arg0, arg1): + return arg0.ancestor_child_position(arg1) + def child_position(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: + raise + ctx = arg0.ctx + res = isl.isl_schedule_node_get_child_position(arg0.ptr) + if res < 0: raise + return int(res) + def get_child_position(arg0): + return arg0.child_position() + def prefix_schedule_multi_union_pw_aff(arg0): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_subtract(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(arg0.ptr) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def get_prefix_schedule_multi_union_pw_aff(arg0): + return arg0.prefix_schedule_multi_union_pw_aff() + def prefix_schedule_union_map(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_node_get_prefix_schedule_union_map(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_prefix_schedule_union_map(arg0): + return arg0.prefix_schedule_union_map() + def prefix_schedule_union_pw_multi_aff(arg0): try: - if not arg1.__class__ is union_set: - arg1 = union_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_union(isl.isl_union_set_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) - return union_set(ctx=ctx, ptr=res) - def unwrap(arg0): + res = isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(arg0.ptr) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def get_prefix_schedule_union_pw_multi_aff(arg0): + return arg0.prefix_schedule_union_pw_multi_aff() + def schedule(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_set_unwrap(isl.isl_union_set_copy(arg0.ptr)) - return union_map(ctx=ctx, ptr=res) - -isl.isl_union_set_from_basic_set.restype = c_void_p -isl.isl_union_set_from_basic_set.argtypes = [c_void_p] -isl.isl_union_set_from_set.restype = c_void_p -isl.isl_union_set_from_set.argtypes = [c_void_p] -isl.isl_union_set_from_point.restype = c_void_p -isl.isl_union_set_from_point.argtypes = [c_void_p] -isl.isl_union_set_read_from_str.restype = c_void_p -isl.isl_union_set_read_from_str.argtypes = [Context, c_char_p] -isl.isl_union_set_affine_hull.restype = c_void_p -isl.isl_union_set_affine_hull.argtypes = [c_void_p] -isl.isl_union_set_apply.restype = c_void_p -isl.isl_union_set_apply.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_coalesce.restype = c_void_p -isl.isl_union_set_coalesce.argtypes = [c_void_p] -isl.isl_union_set_compute_divs.restype = c_void_p -isl.isl_union_set_compute_divs.argtypes = [c_void_p] -isl.isl_union_set_detect_equalities.restype = c_void_p -isl.isl_union_set_detect_equalities.argtypes = [c_void_p] -isl.isl_union_set_foreach_point.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_union_set_foreach_set.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_union_set_gist.restype = c_void_p -isl.isl_union_set_gist.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_gist_params.restype = c_void_p -isl.isl_union_set_gist_params.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_identity.restype = c_void_p -isl.isl_union_set_identity.argtypes = [c_void_p] -isl.isl_union_set_intersect.restype = c_void_p -isl.isl_union_set_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_intersect_params.restype = c_void_p -isl.isl_union_set_intersect_params.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_is_empty.restype = c_bool -isl.isl_union_set_is_empty.argtypes = [c_void_p] -isl.isl_union_set_is_equal.restype = c_bool -isl.isl_union_set_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_is_strict_subset.restype = c_bool -isl.isl_union_set_is_strict_subset.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_is_subset.restype = c_bool -isl.isl_union_set_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_lexmax.restype = c_void_p -isl.isl_union_set_lexmax.argtypes = [c_void_p] -isl.isl_union_set_lexmin.restype = c_void_p -isl.isl_union_set_lexmin.argtypes = [c_void_p] -isl.isl_union_set_polyhedral_hull.restype = c_void_p -isl.isl_union_set_polyhedral_hull.argtypes = [c_void_p] -isl.isl_union_set_preimage_multi_aff.restype = c_void_p -isl.isl_union_set_preimage_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_preimage_pw_multi_aff.restype = c_void_p -isl.isl_union_set_preimage_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_preimage_union_pw_multi_aff.restype = c_void_p -isl.isl_union_set_preimage_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_sample_point.restype = c_void_p -isl.isl_union_set_sample_point.argtypes = [c_void_p] -isl.isl_union_set_subtract.restype = c_void_p -isl.isl_union_set_subtract.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_union.restype = c_void_p -isl.isl_union_set_union.argtypes = [c_void_p, c_void_p] -isl.isl_union_set_unwrap.restype = c_void_p -isl.isl_union_set_unwrap.argtypes = [c_void_p] -isl.isl_union_set_copy.restype = c_void_p -isl.isl_union_set_copy.argtypes = [c_void_p] -isl.isl_union_set_free.restype = c_void_p -isl.isl_union_set_free.argtypes = [c_void_p] -isl.isl_union_set_to_str.restype = POINTER(c_char) -isl.isl_union_set_to_str.argtypes = [c_void_p] - -class set(union_set): - def __init__(self, *args, **keywords): - if "ptr" in keywords: - self.ctx = keywords["ctx"] - self.ptr = keywords["ptr"] - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_set_read_from_str(self.ctx, args[0].encode('ascii')) - return - if len(args) == 1 and args[0].__class__ is basic_set: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_set_from_basic_set(isl.isl_basic_set_copy(args[0].ptr)) - return - if len(args) == 1 and args[0].__class__ is point: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_set_from_point(isl.isl_point_copy(args[0].ptr)) - return - raise Error - def __del__(self): - if hasattr(self, 'ptr'): - isl.isl_set_free(self.ptr) - def __str__(arg0): + res = isl.isl_schedule_node_get_schedule(arg0.ptr) + obj = schedule(ctx=ctx, ptr=res) + return obj + def get_schedule(arg0): + return arg0.schedule() + def shared_ancestor(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - ptr = isl.isl_set_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.set("""%s""")' % s - else: - return 'isl.set("%s")' % s - def affine_hull(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg1.__class__ is schedule_node: + arg1 = schedule_node(arg1) except: raise ctx = arg0.ctx - res = isl.isl_set_affine_hull(isl.isl_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def apply(arg0, arg1): + res = isl.isl_schedule_node_get_shared_ancestor(arg0.ptr, arg1.ptr) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def get_shared_ancestor(arg0, arg1): + return arg0.shared_ancestor(arg1) + def tree_depth(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_schedule_node_get_tree_depth(arg0.ptr) + if res < 0: + raise + return int(res) + def get_tree_depth(arg0): + return arg0.tree_depth() + def graft_after(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is map: - arg1 = map(arg1) + if not arg1.__class__ is schedule_node: + arg1 = schedule_node(arg1) except: - return union_set(arg0).apply(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_apply(isl.isl_set_copy(arg0.ptr), isl.isl_map_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def coalesce(arg0): + res = isl.isl_schedule_node_graft_after(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_schedule_node_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def graft_before(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_set_coalesce(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def complement(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg1.__class__ is schedule_node: + arg1 = schedule_node(arg1) except: raise ctx = arg0.ctx - res = isl.isl_set_complement(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_schedule_node_graft_before(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_schedule_node_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def has_children(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_detect_equalities(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def flatten(arg0): + res = isl.isl_schedule_node_has_children(arg0.ptr) + if res < 0: + raise + return bool(res) + def has_next_sibling(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_flatten(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def foreach_basic_set(arg0, arg1): + res = isl.isl_schedule_node_has_next_sibling(arg0.ptr) + if res < 0: + raise + return bool(res) + def has_parent(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - exc_info = [None] - fn = CFUNCTYPE(c_int, c_void_p, c_void_p) - def cb_func(cb_arg0, cb_arg1): - cb_arg0 = basic_set(ctx=arg0.ctx, ptr=cb_arg0) - try: - arg1(cb_arg0) - except: - import sys - exc_info[0] = sys.exc_info() - return -1 - return 0 - cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_set_foreach_basic_set(arg0.ptr, cb, None) - if exc_info[0] != None: - raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) - return res - def get_stride(arg0, arg1): + res = isl.isl_schedule_node_has_parent(arg0.ptr) + if res < 0: + raise + return bool(res) + def has_previous_sibling(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_get_stride(arg0.ptr, arg1) - return val(ctx=ctx, ptr=res) - def gist(arg0, arg1): + res = isl.isl_schedule_node_has_previous_sibling(arg0.ptr) + if res < 0: + raise + return bool(res) + def insert_context(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: if not arg1.__class__ is set: arg1 = set(arg1) - except: - return union_set(arg0).gist(arg1) - ctx = arg0.ctx - res = isl.isl_set_gist(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def identity(arg0): - try: - if not arg0.__class__ is set: - arg0 = set(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_identity(isl.isl_set_copy(arg0.ptr)) - return map(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_schedule_node_insert_context(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_filter(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: - return union_set(arg0).intersect(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_intersect(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def intersect_params(arg0, arg1): + res = isl.isl_schedule_node_insert_filter(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_guard(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: if not arg1.__class__ is set: arg1 = set(arg1) except: - return union_set(arg0).intersect_params(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_intersect_params(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def is_disjoint(arg0, arg1): + res = isl.isl_schedule_node_insert_guard(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_mark(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is id: + arg1 = id(arg1) except: - return union_set(arg0).is_disjoint(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_is_disjoint(arg0.ptr, arg1.ptr) - if res < 0: + res = isl.isl_schedule_node_insert_mark(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_id_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_partial_schedule(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: raise - return bool(res) - def is_empty(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) except: raise ctx = arg0.ctx - res = isl.isl_set_is_empty(arg0.ptr) - if res < 0: - raise - return bool(res) - def is_equal(arg0, arg1): + res = isl.isl_schedule_node_insert_partial_schedule(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_sequence(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_set_list: + arg1 = union_set_list(arg1) except: - return union_set(arg0).is_equal(arg1) - ctx = arg0.ctx - res = isl.isl_set_is_equal(arg0.ptr, arg1.ptr) - if res < 0: raise - return bool(res) - def is_strict_subset(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_schedule_node_insert_sequence(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_list_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def insert_set(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_set_list: + arg1 = union_set_list(arg1) except: - return union_set(arg0).is_strict_subset(arg1) - ctx = arg0.ctx - res = isl.isl_set_is_strict_subset(arg0.ptr, arg1.ptr) - if res < 0: raise - return bool(res) - def is_subset(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_schedule_node_insert_set(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_list_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def is_equal(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is schedule_node: + arg1 = schedule_node(arg1) except: - return union_set(arg0).is_subset(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_is_subset(arg0.ptr, arg1.ptr) + res = isl.isl_schedule_node_is_equal(arg0.ptr, arg1.ptr) if res < 0: raise return bool(res) - def is_wrapping(arg0): + def is_subtree_anchored(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_is_wrapping(arg0.ptr) + res = isl.isl_schedule_node_is_subtree_anchored(arg0.ptr) if res < 0: raise return bool(res) - def lexmax(arg0): + def map_descendant_bottom_up(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_void_p, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = schedule_node(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + res = arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return None + return isl.isl_schedule_node_copy(res.ptr) + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_set_lexmax(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_schedule_node_map_descendant_bottom_up(isl.isl_schedule_node_copy(arg0.ptr), cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def n_children(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_lexmin(isl.isl_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def max_val(arg0, arg1): - try: - if not arg0.__class__ is set: - arg0 = set(arg0) - except: + res = isl.isl_schedule_node_n_children(arg0.ptr) + if res < 0: raise + return int(res) + def next_sibling(arg0): try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: - return union_set(arg0).max_val(arg1) + raise ctx = arg0.ctx - res = isl.isl_set_max_val(arg0.ptr, arg1.ptr) - return val(ctx=ctx, ptr=res) - def min_val(arg0, arg1): + res = isl.isl_schedule_node_next_sibling(isl.isl_schedule_node_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def order_after(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - try: - if not arg1.__class__ is aff: - arg1 = aff(arg1) - except: - return union_set(arg0).min_val(arg1) - ctx = arg0.ctx - res = isl.isl_set_min_val(arg0.ptr, arg1.ptr) - return val(ctx=ctx, ptr=res) - def polyhedral_hull(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: raise ctx = arg0.ctx - res = isl.isl_set_polyhedral_hull(isl.isl_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def sample(arg0): + res = isl.isl_schedule_node_order_after(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def order_before(arg0, arg1): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_set_sample(isl.isl_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def sample_point(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: raise ctx = arg0.ctx - res = isl.isl_set_sample_point(isl.isl_set_copy(arg0.ptr)) - return point(ctx=ctx, ptr=res) - def subtract(arg0, arg1): + res = isl.isl_schedule_node_order_before(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def parent(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - try: - if not arg1.__class__ is set: - arg1 = set(arg1) - except: - return union_set(arg0).subtract(arg1) ctx = arg0.ctx - res = isl.isl_set_subtract(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_schedule_node_parent(isl.isl_schedule_node_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def previous_sibling(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise - try: - if not arg1.__class__ is set: - arg1 = set(arg1) - except: - return union_set(arg0).union(arg1) - ctx = arg0.ctx - res = isl.isl_set_union(isl.isl_set_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) - def unshifted_simple_hull(arg0): + ctx = arg0.ctx + res = isl.isl_schedule_node_previous_sibling(isl.isl_schedule_node_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def root(arg0): try: - if not arg0.__class__ is set: - arg0 = set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_set_unshifted_simple_hull(isl.isl_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) + res = isl.isl_schedule_node_root(isl.isl_schedule_node_copy(arg0.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj -isl.isl_set_read_from_str.restype = c_void_p -isl.isl_set_read_from_str.argtypes = [Context, c_char_p] -isl.isl_set_from_basic_set.restype = c_void_p -isl.isl_set_from_basic_set.argtypes = [c_void_p] -isl.isl_set_from_point.restype = c_void_p -isl.isl_set_from_point.argtypes = [c_void_p] -isl.isl_set_affine_hull.restype = c_void_p -isl.isl_set_affine_hull.argtypes = [c_void_p] -isl.isl_set_apply.restype = c_void_p -isl.isl_set_apply.argtypes = [c_void_p, c_void_p] -isl.isl_set_coalesce.restype = c_void_p -isl.isl_set_coalesce.argtypes = [c_void_p] -isl.isl_set_complement.restype = c_void_p -isl.isl_set_complement.argtypes = [c_void_p] -isl.isl_set_detect_equalities.restype = c_void_p -isl.isl_set_detect_equalities.argtypes = [c_void_p] -isl.isl_set_flatten.restype = c_void_p -isl.isl_set_flatten.argtypes = [c_void_p] -isl.isl_set_foreach_basic_set.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_set_get_stride.restype = c_void_p -isl.isl_set_get_stride.argtypes = [c_void_p, c_int] -isl.isl_set_gist.restype = c_void_p -isl.isl_set_gist.argtypes = [c_void_p, c_void_p] -isl.isl_set_identity.restype = c_void_p -isl.isl_set_identity.argtypes = [c_void_p] -isl.isl_set_intersect.restype = c_void_p -isl.isl_set_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_set_intersect_params.restype = c_void_p -isl.isl_set_intersect_params.argtypes = [c_void_p, c_void_p] -isl.isl_set_is_disjoint.restype = c_bool -isl.isl_set_is_disjoint.argtypes = [c_void_p, c_void_p] -isl.isl_set_is_empty.restype = c_bool -isl.isl_set_is_empty.argtypes = [c_void_p] -isl.isl_set_is_equal.restype = c_bool -isl.isl_set_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_set_is_strict_subset.restype = c_bool -isl.isl_set_is_strict_subset.argtypes = [c_void_p, c_void_p] -isl.isl_set_is_subset.restype = c_bool -isl.isl_set_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_set_is_wrapping.restype = c_bool -isl.isl_set_is_wrapping.argtypes = [c_void_p] -isl.isl_set_lexmax.restype = c_void_p -isl.isl_set_lexmax.argtypes = [c_void_p] -isl.isl_set_lexmin.restype = c_void_p -isl.isl_set_lexmin.argtypes = [c_void_p] -isl.isl_set_max_val.restype = c_void_p -isl.isl_set_max_val.argtypes = [c_void_p, c_void_p] -isl.isl_set_min_val.restype = c_void_p -isl.isl_set_min_val.argtypes = [c_void_p, c_void_p] -isl.isl_set_polyhedral_hull.restype = c_void_p -isl.isl_set_polyhedral_hull.argtypes = [c_void_p] -isl.isl_set_sample.restype = c_void_p -isl.isl_set_sample.argtypes = [c_void_p] -isl.isl_set_sample_point.restype = c_void_p -isl.isl_set_sample_point.argtypes = [c_void_p] -isl.isl_set_subtract.restype = c_void_p -isl.isl_set_subtract.argtypes = [c_void_p, c_void_p] -isl.isl_set_union.restype = c_void_p -isl.isl_set_union.argtypes = [c_void_p, c_void_p] -isl.isl_set_unshifted_simple_hull.restype = c_void_p -isl.isl_set_unshifted_simple_hull.argtypes = [c_void_p] -isl.isl_set_copy.restype = c_void_p -isl.isl_set_copy.argtypes = [c_void_p] -isl.isl_set_free.restype = c_void_p -isl.isl_set_free.argtypes = [c_void_p] -isl.isl_set_to_str.restype = POINTER(c_char) -isl.isl_set_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_ancestor.restype = c_void_p +isl.isl_schedule_node_ancestor.argtypes = [c_void_p, c_int] +isl.isl_schedule_node_child.restype = c_void_p +isl.isl_schedule_node_child.argtypes = [c_void_p, c_int] +isl.isl_schedule_node_every_descendant.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_schedule_node_first_child.restype = c_void_p +isl.isl_schedule_node_first_child.argtypes = [c_void_p] +isl.isl_schedule_node_foreach_ancestor_top_down.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_schedule_node_foreach_descendant_top_down.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_schedule_node_from_domain.restype = c_void_p +isl.isl_schedule_node_from_domain.argtypes = [c_void_p] +isl.isl_schedule_node_from_extension.restype = c_void_p +isl.isl_schedule_node_from_extension.argtypes = [c_void_p] +isl.isl_schedule_node_get_ancestor_child_position.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_get_child_position.argtypes = [c_void_p] +isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff.restype = c_void_p +isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff.argtypes = [c_void_p] +isl.isl_schedule_node_get_prefix_schedule_union_map.restype = c_void_p +isl.isl_schedule_node_get_prefix_schedule_union_map.argtypes = [c_void_p] +isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff.restype = c_void_p +isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff.argtypes = [c_void_p] +isl.isl_schedule_node_get_schedule.restype = c_void_p +isl.isl_schedule_node_get_schedule.argtypes = [c_void_p] +isl.isl_schedule_node_get_shared_ancestor.restype = c_void_p +isl.isl_schedule_node_get_shared_ancestor.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_get_tree_depth.argtypes = [c_void_p] +isl.isl_schedule_node_graft_after.restype = c_void_p +isl.isl_schedule_node_graft_after.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_graft_before.restype = c_void_p +isl.isl_schedule_node_graft_before.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_has_children.argtypes = [c_void_p] +isl.isl_schedule_node_has_next_sibling.argtypes = [c_void_p] +isl.isl_schedule_node_has_parent.argtypes = [c_void_p] +isl.isl_schedule_node_has_previous_sibling.argtypes = [c_void_p] +isl.isl_schedule_node_insert_context.restype = c_void_p +isl.isl_schedule_node_insert_context.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_filter.restype = c_void_p +isl.isl_schedule_node_insert_filter.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_guard.restype = c_void_p +isl.isl_schedule_node_insert_guard.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_mark.restype = c_void_p +isl.isl_schedule_node_insert_mark.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_partial_schedule.restype = c_void_p +isl.isl_schedule_node_insert_partial_schedule.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_sequence.restype = c_void_p +isl.isl_schedule_node_insert_sequence.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_insert_set.restype = c_void_p +isl.isl_schedule_node_insert_set.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_is_subtree_anchored.argtypes = [c_void_p] +isl.isl_schedule_node_map_descendant_bottom_up.restype = c_void_p +isl.isl_schedule_node_map_descendant_bottom_up.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_schedule_node_n_children.argtypes = [c_void_p] +isl.isl_schedule_node_next_sibling.restype = c_void_p +isl.isl_schedule_node_next_sibling.argtypes = [c_void_p] +isl.isl_schedule_node_order_after.restype = c_void_p +isl.isl_schedule_node_order_after.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_order_before.restype = c_void_p +isl.isl_schedule_node_order_before.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_parent.restype = c_void_p +isl.isl_schedule_node_parent.argtypes = [c_void_p] +isl.isl_schedule_node_previous_sibling.restype = c_void_p +isl.isl_schedule_node_previous_sibling.argtypes = [c_void_p] +isl.isl_schedule_node_root.restype = c_void_p +isl.isl_schedule_node_root.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_get_type.argtypes = [c_void_p] -class basic_set(set): +class schedule_node_band(schedule_node): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_basic_set_read_from_str(self.ctx, args[0].encode('ascii')) - return - if len(args) == 1 and args[0].__class__ is point: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_basic_set_from_point(isl.isl_point_copy(args[0].ptr)) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_basic_set_free(self.ptr) + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_band, cls).__new__(cls) def __str__(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node_band: + arg0 = schedule_node_band(arg0) except: raise - ptr = isl.isl_basic_set_to_str(arg0.ptr) + ptr = isl.isl_schedule_node_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.basic_set("""%s""")' % s + return 'isl.schedule_node_band("""%s""")' % s else: - return 'isl.basic_set("%s")' % s - def affine_hull(arg0): + return 'isl.schedule_node_band("%s")' % s + def ast_build_options(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_affine_hull(isl.isl_basic_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def apply(arg0, arg1): + res = isl.isl_schedule_node_band_get_ast_build_options(arg0.ptr) + obj = union_set(ctx=ctx, ptr=res) + return obj + def get_ast_build_options(arg0): + return arg0.ast_build_options() + def ast_isolate_option(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_node_band_get_ast_isolate_option(arg0.ptr) + obj = set(ctx=ctx, ptr=res) + return obj + def get_ast_isolate_option(arg0): + return arg0.ast_isolate_option() + def partial_schedule(arg0): try: - if not arg1.__class__ is basic_map: - arg1 = basic_map(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: - return set(arg0).apply(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_set_apply(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_map_copy(arg1.ptr)) - return basic_set(ctx=ctx, ptr=res) - def detect_equalities(arg0): + res = isl.isl_schedule_node_band_get_partial_schedule(arg0.ptr) + obj = multi_union_pw_aff(ctx=ctx, ptr=res) + return obj + def get_partial_schedule(arg0): + return arg0.partial_schedule() + def permutable(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_detect_equalities(isl.isl_basic_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def dim_max_val(arg0, arg1): + res = isl.isl_schedule_node_band_get_permutable(arg0.ptr) + if res < 0: + raise + return bool(res) + def get_permutable(arg0): + return arg0.permutable() + def member_get_coincident(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_dim_max_val(isl.isl_basic_set_copy(arg0.ptr), arg1) - return val(ctx=ctx, ptr=res) - def flatten(arg0): + res = isl.isl_schedule_node_band_member_get_coincident(arg0.ptr, arg1) + if res < 0: + raise + return bool(res) + def member_set_coincident(arg0, arg1, arg2): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_flatten(isl.isl_basic_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def gist(arg0, arg1): + res = isl.isl_schedule_node_band_member_set_coincident(isl.isl_schedule_node_copy(arg0.ptr), arg1, arg2) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def mod(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: - return set(arg0).gist(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_set_gist(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return basic_set(ctx=ctx, ptr=res) - def intersect(arg0, arg1): + res = isl.isl_schedule_node_band_mod(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def n_member(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: + raise + ctx = arg0.ctx + res = isl.isl_schedule_node_band_n_member(arg0.ptr) + if res < 0: raise + return int(res) + def scale(arg0, arg1): try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: - return set(arg0).intersect(arg1) + raise + try: + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) + except: + raise ctx = arg0.ctx - res = isl.isl_basic_set_intersect(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return basic_set(ctx=ctx, ptr=res) - def intersect_params(arg0, arg1): + res = isl.isl_schedule_node_band_scale(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def scale_down(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: - return set(arg0).intersect_params(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_set_intersect_params(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return basic_set(ctx=ctx, ptr=res) - def is_empty(arg0): + res = isl.isl_schedule_node_band_scale_down(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def set_ast_build_options(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_is_empty(arg0.ptr) - if res < 0: + res = isl.isl_schedule_node_band_set_ast_build_options(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def set_permutable(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: raise - return bool(res) - def is_equal(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_schedule_node_band_set_permutable(isl.isl_schedule_node_copy(arg0.ptr), arg1) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def shift(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg1.__class__ is multi_union_pw_aff: + arg1 = multi_union_pw_aff(arg1) except: - return set(arg0).is_equal(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_set_is_equal(arg0.ptr, arg1.ptr) - if res < 0: + res = isl.isl_schedule_node_band_shift(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_union_pw_aff_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def split(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: raise - return bool(res) - def is_subset(arg0, arg1): + ctx = arg0.ctx + res = isl.isl_schedule_node_band_split(isl.isl_schedule_node_copy(arg0.ptr), arg1) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def tile(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg1.__class__ is multi_val: + arg1 = multi_val(arg1) except: - return set(arg0).is_subset(arg1) - ctx = arg0.ctx - res = isl.isl_basic_set_is_subset(arg0.ptr, arg1.ptr) - if res < 0: raise - return bool(res) - def is_wrapping(arg0): + ctx = arg0.ctx + res = isl.isl_schedule_node_band_tile(isl.isl_schedule_node_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def member_set_ast_loop_default(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_is_wrapping(arg0.ptr) - if res < 0: + res = isl.isl_schedule_node_band_member_set_ast_loop_type(isl.isl_schedule_node_copy(arg0.ptr), arg1, 0) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def member_set_ast_loop_atomic(arg0, arg1): + try: + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) + except: raise - return bool(res) - def lexmax(arg0): + ctx = arg0.ctx + res = isl.isl_schedule_node_band_member_set_ast_loop_type(isl.isl_schedule_node_copy(arg0.ptr), arg1, 1) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def member_set_ast_loop_unroll(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_lexmax(isl.isl_basic_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def lexmin(arg0): + res = isl.isl_schedule_node_band_member_set_ast_loop_type(isl.isl_schedule_node_copy(arg0.ptr), arg1, 2) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + def member_set_ast_loop_separate(arg0, arg1): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_lexmin(isl.isl_basic_set_copy(arg0.ptr)) - return set(ctx=ctx, ptr=res) - def sample(arg0): + res = isl.isl_schedule_node_band_member_set_ast_loop_type(isl.isl_schedule_node_copy(arg0.ptr), arg1, 3) + obj = schedule_node(ctx=ctx, ptr=res) + return obj + +isl.isl_schedule_node_band_get_ast_build_options.restype = c_void_p +isl.isl_schedule_node_band_get_ast_build_options.argtypes = [c_void_p] +isl.isl_schedule_node_band_get_ast_isolate_option.restype = c_void_p +isl.isl_schedule_node_band_get_ast_isolate_option.argtypes = [c_void_p] +isl.isl_schedule_node_band_get_partial_schedule.restype = c_void_p +isl.isl_schedule_node_band_get_partial_schedule.argtypes = [c_void_p] +isl.isl_schedule_node_band_get_permutable.argtypes = [c_void_p] +isl.isl_schedule_node_band_member_get_coincident.argtypes = [c_void_p, c_int] +isl.isl_schedule_node_band_member_set_coincident.restype = c_void_p +isl.isl_schedule_node_band_member_set_coincident.argtypes = [c_void_p, c_int, c_int] +isl.isl_schedule_node_band_mod.restype = c_void_p +isl.isl_schedule_node_band_mod.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_n_member.argtypes = [c_void_p] +isl.isl_schedule_node_band_scale.restype = c_void_p +isl.isl_schedule_node_band_scale.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_scale_down.restype = c_void_p +isl.isl_schedule_node_band_scale_down.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_set_ast_build_options.restype = c_void_p +isl.isl_schedule_node_band_set_ast_build_options.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_set_permutable.restype = c_void_p +isl.isl_schedule_node_band_set_permutable.argtypes = [c_void_p, c_int] +isl.isl_schedule_node_band_shift.restype = c_void_p +isl.isl_schedule_node_band_shift.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_split.restype = c_void_p +isl.isl_schedule_node_band_split.argtypes = [c_void_p, c_int] +isl.isl_schedule_node_band_tile.restype = c_void_p +isl.isl_schedule_node_band_tile.argtypes = [c_void_p, c_void_p] +isl.isl_schedule_node_band_member_set_ast_loop_type.restype = c_void_p +isl.isl_schedule_node_band_member_set_ast_loop_type.argtypes = [c_void_p, c_int, c_int] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_context(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_context, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node_context: + arg0 = schedule_node_context(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_basic_set_sample(isl.isl_basic_set_copy(arg0.ptr)) - return basic_set(ctx=ctx, ptr=res) - def sample_point(arg0): + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_context("""%s""")' % s + else: + return 'isl.schedule_node_context("%s")' % s + def context(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_basic_set_sample_point(isl.isl_basic_set_copy(arg0.ptr)) - return point(ctx=ctx, ptr=res) - def union(arg0, arg1): + res = isl.isl_schedule_node_context_get_context(arg0.ptr) + obj = set(ctx=ctx, ptr=res) + return obj + def get_context(arg0): + return arg0.context() + +isl.isl_schedule_node_context_get_context.restype = c_void_p +isl.isl_schedule_node_context_get_context.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_domain(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_domain, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is basic_set: - arg0 = basic_set(arg0) + if not arg0.__class__ is schedule_node_domain: + arg0 = schedule_node_domain(arg0) except: raise + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_domain("""%s""")' % s + else: + return 'isl.schedule_node_domain("%s")' % s + def domain(arg0): try: - if not arg1.__class__ is basic_set: - arg1 = basic_set(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: - return set(arg0).union(arg1) + raise ctx = arg0.ctx - res = isl.isl_basic_set_union(isl.isl_basic_set_copy(arg0.ptr), isl.isl_basic_set_copy(arg1.ptr)) - return set(ctx=ctx, ptr=res) + res = isl.isl_schedule_node_domain_get_domain(arg0.ptr) + obj = union_set(ctx=ctx, ptr=res) + return obj + def get_domain(arg0): + return arg0.domain() -isl.isl_basic_set_read_from_str.restype = c_void_p -isl.isl_basic_set_read_from_str.argtypes = [Context, c_char_p] -isl.isl_basic_set_from_point.restype = c_void_p -isl.isl_basic_set_from_point.argtypes = [c_void_p] -isl.isl_basic_set_affine_hull.restype = c_void_p -isl.isl_basic_set_affine_hull.argtypes = [c_void_p] -isl.isl_basic_set_apply.restype = c_void_p -isl.isl_basic_set_apply.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_detect_equalities.restype = c_void_p -isl.isl_basic_set_detect_equalities.argtypes = [c_void_p] -isl.isl_basic_set_dim_max_val.restype = c_void_p -isl.isl_basic_set_dim_max_val.argtypes = [c_void_p, c_int] -isl.isl_basic_set_flatten.restype = c_void_p -isl.isl_basic_set_flatten.argtypes = [c_void_p] -isl.isl_basic_set_gist.restype = c_void_p -isl.isl_basic_set_gist.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_intersect.restype = c_void_p -isl.isl_basic_set_intersect.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_intersect_params.restype = c_void_p -isl.isl_basic_set_intersect_params.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_is_empty.restype = c_bool -isl.isl_basic_set_is_empty.argtypes = [c_void_p] -isl.isl_basic_set_is_equal.restype = c_bool -isl.isl_basic_set_is_equal.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_is_subset.restype = c_bool -isl.isl_basic_set_is_subset.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_is_wrapping.restype = c_bool -isl.isl_basic_set_is_wrapping.argtypes = [c_void_p] -isl.isl_basic_set_lexmax.restype = c_void_p -isl.isl_basic_set_lexmax.argtypes = [c_void_p] -isl.isl_basic_set_lexmin.restype = c_void_p -isl.isl_basic_set_lexmin.argtypes = [c_void_p] -isl.isl_basic_set_sample.restype = c_void_p -isl.isl_basic_set_sample.argtypes = [c_void_p] -isl.isl_basic_set_sample_point.restype = c_void_p -isl.isl_basic_set_sample_point.argtypes = [c_void_p] -isl.isl_basic_set_union.restype = c_void_p -isl.isl_basic_set_union.argtypes = [c_void_p, c_void_p] -isl.isl_basic_set_copy.restype = c_void_p -isl.isl_basic_set_copy.argtypes = [c_void_p] -isl.isl_basic_set_free.restype = c_void_p -isl.isl_basic_set_free.argtypes = [c_void_p] -isl.isl_basic_set_to_str.restype = POINTER(c_char) -isl.isl_basic_set_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_domain_get_domain.restype = c_void_p +isl.isl_schedule_node_domain_get_domain.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] -class multi_val(object): +class schedule_node_expansion(schedule_node): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] @@ -4281,96 +11859,212 @@ raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_multi_val_free(self.ptr) + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_expansion, cls).__new__(cls) def __str__(arg0): try: - if not arg0.__class__ is multi_val: - arg0 = multi_val(arg0) + if not arg0.__class__ is schedule_node_expansion: + arg0 = schedule_node_expansion(arg0) except: raise - ptr = isl.isl_multi_val_to_str(arg0.ptr) + ptr = isl.isl_schedule_node_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.multi_val("""%s""")' % s + return 'isl.schedule_node_expansion("""%s""")' % s else: - return 'isl.multi_val("%s")' % s - def add(arg0, arg1): + return 'isl.schedule_node_expansion("%s")' % s + def contraction(arg0): try: - if not arg0.__class__ is multi_val: - arg0 = multi_val(arg0) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_schedule_node_expansion_get_contraction(arg0.ptr) + obj = union_pw_multi_aff(ctx=ctx, ptr=res) + return obj + def get_contraction(arg0): + return arg0.contraction() + def expansion(arg0): try: - if not arg1.__class__ is multi_val: - arg1 = multi_val(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_multi_val_add(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) - return multi_val(ctx=ctx, ptr=res) - def flat_range_product(arg0, arg1): + res = isl.isl_schedule_node_expansion_get_expansion(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_expansion(arg0): + return arg0.expansion() + +isl.isl_schedule_node_expansion_get_contraction.restype = c_void_p +isl.isl_schedule_node_expansion_get_contraction.argtypes = [c_void_p] +isl.isl_schedule_node_expansion_get_expansion.restype = c_void_p +isl.isl_schedule_node_expansion_get_expansion.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_extension(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_extension, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is multi_val: - arg0 = multi_val(arg0) + if not arg0.__class__ is schedule_node_extension: + arg0 = schedule_node_extension(arg0) except: raise + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_extension("""%s""")' % s + else: + return 'isl.schedule_node_extension("%s")' % s + def extension(arg0): try: - if not arg1.__class__ is multi_val: - arg1 = multi_val(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_multi_val_flat_range_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) - return multi_val(ctx=ctx, ptr=res) - def product(arg0, arg1): + res = isl.isl_schedule_node_extension_get_extension(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_extension(arg0): + return arg0.extension() + +isl.isl_schedule_node_extension_get_extension.restype = c_void_p +isl.isl_schedule_node_extension_get_extension.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_filter(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_filter, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is multi_val: - arg0 = multi_val(arg0) + if not arg0.__class__ is schedule_node_filter: + arg0 = schedule_node_filter(arg0) except: raise + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_filter("""%s""")' % s + else: + return 'isl.schedule_node_filter("%s")' % s + def filter(arg0): try: - if not arg1.__class__ is multi_val: - arg1 = multi_val(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_multi_val_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) - return multi_val(ctx=ctx, ptr=res) - def range_product(arg0, arg1): + res = isl.isl_schedule_node_filter_get_filter(arg0.ptr) + obj = union_set(ctx=ctx, ptr=res) + return obj + def get_filter(arg0): + return arg0.filter() + +isl.isl_schedule_node_filter_get_filter.restype = c_void_p +isl.isl_schedule_node_filter_get_filter.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_guard(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_guard, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is multi_val: - arg0 = multi_val(arg0) + if not arg0.__class__ is schedule_node_guard: + arg0 = schedule_node_guard(arg0) except: raise + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_guard("""%s""")' % s + else: + return 'isl.schedule_node_guard("%s")' % s + def guard(arg0): try: - if not arg1.__class__ is multi_val: - arg1 = multi_val(arg1) + if not arg0.__class__ is schedule_node: + arg0 = schedule_node(arg0) except: raise ctx = arg0.ctx - res = isl.isl_multi_val_range_product(isl.isl_multi_val_copy(arg0.ptr), isl.isl_multi_val_copy(arg1.ptr)) - return multi_val(ctx=ctx, ptr=res) + res = isl.isl_schedule_node_guard_get_guard(arg0.ptr) + obj = set(ctx=ctx, ptr=res) + return obj + def get_guard(arg0): + return arg0.guard() -isl.isl_multi_val_add.restype = c_void_p -isl.isl_multi_val_add.argtypes = [c_void_p, c_void_p] -isl.isl_multi_val_flat_range_product.restype = c_void_p -isl.isl_multi_val_flat_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_val_product.restype = c_void_p -isl.isl_multi_val_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_val_range_product.restype = c_void_p -isl.isl_multi_val_range_product.argtypes = [c_void_p, c_void_p] -isl.isl_multi_val_copy.restype = c_void_p -isl.isl_multi_val_copy.argtypes = [c_void_p] -isl.isl_multi_val_free.restype = c_void_p -isl.isl_multi_val_free.argtypes = [c_void_p] -isl.isl_multi_val_to_str.restype = POINTER(c_char) -isl.isl_multi_val_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_guard_get_guard.restype = c_void_p +isl.isl_schedule_node_guard_get_guard.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] -class point(basic_set): +class schedule_node_leaf(schedule_node): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] @@ -4379,229 +12073,376 @@ raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_point_free(self.ptr) + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_leaf, cls).__new__(cls) def __str__(arg0): try: - if not arg0.__class__ is point: - arg0 = point(arg0) + if not arg0.__class__ is schedule_node_leaf: + arg0 = schedule_node_leaf(arg0) except: raise - ptr = isl.isl_point_to_str(arg0.ptr) + ptr = isl.isl_schedule_node_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.point("""%s""")' % s + return 'isl.schedule_node_leaf("""%s""")' % s else: - return 'isl.point("%s")' % s + return 'isl.schedule_node_leaf("%s")' % s -isl.isl_point_copy.restype = c_void_p -isl.isl_point_copy.argtypes = [c_void_p] -isl.isl_point_free.restype = c_void_p -isl.isl_point_free.argtypes = [c_void_p] -isl.isl_point_to_str.restype = POINTER(c_char) -isl.isl_point_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] -class schedule(object): +class schedule_node_mark(schedule_node): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_schedule_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_schedule_free(self.ptr) + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_mark, cls).__new__(cls) def __str__(arg0): try: - if not arg0.__class__ is schedule: - arg0 = schedule(arg0) + if not arg0.__class__ is schedule_node_mark: + arg0 = schedule_node_mark(arg0) except: raise - ptr = isl.isl_schedule_to_str(arg0.ptr) + ptr = isl.isl_schedule_node_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.schedule("""%s""")' % s + return 'isl.schedule_node_mark("""%s""")' % s else: - return 'isl.schedule("%s")' % s - def get_map(arg0): + return 'isl.schedule_node_mark("%s")' % s + +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_sequence(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_sequence, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is schedule: - arg0 = schedule(arg0) + if not arg0.__class__ is schedule_node_sequence: + arg0 = schedule_node_sequence(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_schedule_get_map(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_root(arg0): + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_sequence("""%s""")' % s + else: + return 'isl.schedule_node_sequence("%s")' % s + +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] + +class schedule_node_set(schedule_node): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_schedule_node_free(self.ptr) + def __new__(cls, *args, **keywords): + return super(schedule_node_set, cls).__new__(cls) + def __str__(arg0): try: - if not arg0.__class__ is schedule: - arg0 = schedule(arg0) + if not arg0.__class__ is schedule_node_set: + arg0 = schedule_node_set(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_schedule_get_root(arg0.ptr) - return schedule_node(ctx=ctx, ptr=res) - def pullback(arg0, arg1): - if arg1.__class__ is union_pw_multi_aff: - res = isl.isl_schedule_pullback_union_pw_multi_aff(isl.isl_schedule_copy(arg0.ptr), isl.isl_union_pw_multi_aff_copy(arg1.ptr)) - return schedule(ctx=arg0.ctx, ptr=res) + ptr = isl.isl_schedule_node_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.schedule_node_set("""%s""")' % s + else: + return 'isl.schedule_node_set("%s")' % s -isl.isl_schedule_read_from_str.restype = c_void_p -isl.isl_schedule_read_from_str.argtypes = [Context, c_char_p] -isl.isl_schedule_get_map.restype = c_void_p -isl.isl_schedule_get_map.argtypes = [c_void_p] -isl.isl_schedule_get_root.restype = c_void_p -isl.isl_schedule_get_root.argtypes = [c_void_p] -isl.isl_schedule_pullback_union_pw_multi_aff.restype = c_void_p -isl.isl_schedule_pullback_union_pw_multi_aff.argtypes = [c_void_p, c_void_p] -isl.isl_schedule_copy.restype = c_void_p -isl.isl_schedule_copy.argtypes = [c_void_p] -isl.isl_schedule_free.restype = c_void_p -isl.isl_schedule_free.argtypes = [c_void_p] -isl.isl_schedule_to_str.restype = POINTER(c_char) -isl.isl_schedule_to_str.argtypes = [c_void_p] +isl.isl_schedule_node_copy.restype = c_void_p +isl.isl_schedule_node_copy.argtypes = [c_void_p] +isl.isl_schedule_node_free.restype = c_void_p +isl.isl_schedule_node_free.argtypes = [c_void_p] +isl.isl_schedule_node_to_str.restype = POINTER(c_char) +isl.isl_schedule_node_to_str.argtypes = [c_void_p] -class schedule_constraints(object): +class space(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] - return - if len(args) == 1 and type(args[0]) == str: - self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_schedule_constraints_read_from_str(self.ctx, args[0].encode('ascii')) return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_schedule_constraints_free(self.ptr) + isl.isl_space_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise - ptr = isl.isl_schedule_constraints_to_str(arg0.ptr) + ptr = isl.isl_space_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.schedule_constraints("""%s""")' % s + return 'isl.space("""%s""")' % s else: - return 'isl.schedule_constraints("%s")' % s - def compute_schedule(arg0): + return 'isl.space("%s")' % s + def add_named_tuple(*args): + if len(args) == 3 and (args[1].__class__ is id or type(args[1]) == str) and type(args[2]) == int: + args = list(args) + try: + if not args[1].__class__ is id: + args[1] = id(args[1]) + except: + raise + ctx = args[0].ctx + res = isl.isl_space_add_named_tuple_id_ui(isl.isl_space_copy(args[0].ptr), isl.isl_id_copy(args[1].ptr), args[2]) + obj = space(ctx=ctx, ptr=res) + return obj + raise Error + def add_unnamed_tuple(*args): + if len(args) == 2 and type(args[1]) == int: + ctx = args[0].ctx + res = isl.isl_space_add_unnamed_tuple_ui(isl.isl_space_copy(args[0].ptr), args[1]) + obj = space(ctx=ctx, ptr=res) + return obj + raise Error + def domain(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_compute_schedule(isl.isl_schedule_constraints_copy(arg0.ptr)) - return schedule(ctx=ctx, ptr=res) - def get_coincidence(arg0): + res = isl.isl_space_domain(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def flatten_domain(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_coincidence(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_conditional_validity(arg0): + res = isl.isl_space_flatten_domain(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def flatten_range(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_conditional_validity(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_conditional_validity_condition(arg0): + res = isl.isl_space_flatten_range(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def is_equal(arg0, arg1): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + try: + if not arg1.__class__ is space: + arg1 = space(arg1) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_conditional_validity_condition(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_context(arg0): + res = isl.isl_space_is_equal(arg0.ptr, arg1.ptr) + if res < 0: + raise + return bool(res) + def is_wrapping(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_context(arg0.ptr) - return set(ctx=ctx, ptr=res) - def get_domain(arg0): + res = isl.isl_space_is_wrapping(arg0.ptr) + if res < 0: + raise + return bool(res) + def map_from_set(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_domain(arg0.ptr) - return union_set(ctx=ctx, ptr=res) - def get_proximity(arg0): + res = isl.isl_space_map_from_set(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def params(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_proximity(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_validity(arg0): + res = isl.isl_space_params(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def range(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_get_validity(arg0.ptr) - return union_map(ctx=ctx, ptr=res) + res = isl.isl_space_range(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj @staticmethod - def on_domain(arg0): + def unit(): + ctx = Context.getDefaultInstance() + res = isl.isl_space_unit(ctx) + obj = space(ctx=ctx, ptr=res) + return obj + def unwrap(arg0): try: - if not arg0.__class__ is union_set: - arg0 = union_set(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_on_domain(isl.isl_union_set_copy(arg0.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) - def set_coincidence(arg0, arg1): + res = isl.isl_space_unwrap(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + def wrap(arg0): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is space: + arg0 = space(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_space_wrap(isl.isl_space_copy(arg0.ptr)) + obj = space(ctx=ctx, ptr=res) + return obj + +isl.isl_space_add_named_tuple_id_ui.restype = c_void_p +isl.isl_space_add_named_tuple_id_ui.argtypes = [c_void_p, c_void_p, c_int] +isl.isl_space_add_unnamed_tuple_ui.restype = c_void_p +isl.isl_space_add_unnamed_tuple_ui.argtypes = [c_void_p, c_int] +isl.isl_space_domain.restype = c_void_p +isl.isl_space_domain.argtypes = [c_void_p] +isl.isl_space_flatten_domain.restype = c_void_p +isl.isl_space_flatten_domain.argtypes = [c_void_p] +isl.isl_space_flatten_range.restype = c_void_p +isl.isl_space_flatten_range.argtypes = [c_void_p] +isl.isl_space_is_equal.argtypes = [c_void_p, c_void_p] +isl.isl_space_is_wrapping.argtypes = [c_void_p] +isl.isl_space_map_from_set.restype = c_void_p +isl.isl_space_map_from_set.argtypes = [c_void_p] +isl.isl_space_params.restype = c_void_p +isl.isl_space_params.argtypes = [c_void_p] +isl.isl_space_range.restype = c_void_p +isl.isl_space_range.argtypes = [c_void_p] +isl.isl_space_unit.restype = c_void_p +isl.isl_space_unit.argtypes = [Context] +isl.isl_space_unwrap.restype = c_void_p +isl.isl_space_unwrap.argtypes = [c_void_p] +isl.isl_space_wrap.restype = c_void_p +isl.isl_space_wrap.argtypes = [c_void_p] +isl.isl_space_copy.restype = c_void_p +isl.isl_space_copy.argtypes = [c_void_p] +isl.isl_space_free.restype = c_void_p +isl.isl_space_free.argtypes = [c_void_p] +isl.isl_space_to_str.restype = POINTER(c_char) +isl.isl_space_to_str.argtypes = [c_void_p] + +class union_access_info(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and args[0].__class__ is union_map: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_access_info_from_sink(isl.isl_union_map_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_union_access_info_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise + ptr = isl.isl_union_access_info_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.union_access_info("""%s""")' % s + else: + return 'isl.union_access_info("%s")' % s + def compute_flow(arg0): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_set_coincidence(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) - def set_conditional_validity(arg0, arg1, arg2): + res = isl.isl_union_access_info_compute_flow(isl.isl_union_access_info_copy(arg0.ptr)) + obj = union_flow(ctx=ctx, ptr=res) + return obj + def set_kill(arg0, arg1): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise try: @@ -4609,46 +12450,59 @@ arg1 = union_map(arg1) except: raise + ctx = arg0.ctx + res = isl.isl_union_access_info_set_kill(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_access_info(ctx=ctx, ptr=res) + return obj + def set_may_source(arg0, arg1): try: - if not arg2.__class__ is union_map: - arg2 = union_map(arg2) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) + except: + raise + try: + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_set_conditional_validity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr), isl.isl_union_map_copy(arg2.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) - def set_context(arg0, arg1): + res = isl.isl_union_access_info_set_may_source(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_access_info(ctx=ctx, ptr=res) + return obj + def set_must_source(arg0, arg1): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise try: - if not arg1.__class__ is set: - arg1 = set(arg1) + if not arg1.__class__ is union_map: + arg1 = union_map(arg1) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_set_context(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_set_copy(arg1.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) - def set_proximity(arg0, arg1): + res = isl.isl_union_access_info_set_must_source(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_access_info(ctx=ctx, ptr=res) + return obj + def set_schedule(arg0, arg1): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is schedule: + arg1 = schedule(arg1) except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_set_proximity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) - def set_validity(arg0, arg1): + res = isl.isl_union_access_info_set_schedule(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_schedule_copy(arg1.ptr)) + obj = union_access_info(ctx=ctx, ptr=res) + return obj + def set_schedule_map(arg0, arg1): try: - if not arg0.__class__ is schedule_constraints: - arg0 = schedule_constraints(arg0) + if not arg0.__class__ is union_access_info: + arg0 = union_access_info(arg0) except: raise try: @@ -4657,47 +12511,32 @@ except: raise ctx = arg0.ctx - res = isl.isl_schedule_constraints_set_validity(isl.isl_schedule_constraints_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return schedule_constraints(ctx=ctx, ptr=res) + res = isl.isl_union_access_info_set_schedule_map(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) + obj = union_access_info(ctx=ctx, ptr=res) + return obj -isl.isl_schedule_constraints_read_from_str.restype = c_void_p -isl.isl_schedule_constraints_read_from_str.argtypes = [Context, c_char_p] -isl.isl_schedule_constraints_compute_schedule.restype = c_void_p -isl.isl_schedule_constraints_compute_schedule.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_coincidence.restype = c_void_p -isl.isl_schedule_constraints_get_coincidence.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_conditional_validity.restype = c_void_p -isl.isl_schedule_constraints_get_conditional_validity.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_conditional_validity_condition.restype = c_void_p -isl.isl_schedule_constraints_get_conditional_validity_condition.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_context.restype = c_void_p -isl.isl_schedule_constraints_get_context.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_domain.restype = c_void_p -isl.isl_schedule_constraints_get_domain.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_proximity.restype = c_void_p -isl.isl_schedule_constraints_get_proximity.argtypes = [c_void_p] -isl.isl_schedule_constraints_get_validity.restype = c_void_p -isl.isl_schedule_constraints_get_validity.argtypes = [c_void_p] -isl.isl_schedule_constraints_on_domain.restype = c_void_p -isl.isl_schedule_constraints_on_domain.argtypes = [c_void_p] -isl.isl_schedule_constraints_set_coincidence.restype = c_void_p -isl.isl_schedule_constraints_set_coincidence.argtypes = [c_void_p, c_void_p] -isl.isl_schedule_constraints_set_conditional_validity.restype = c_void_p -isl.isl_schedule_constraints_set_conditional_validity.argtypes = [c_void_p, c_void_p, c_void_p] -isl.isl_schedule_constraints_set_context.restype = c_void_p -isl.isl_schedule_constraints_set_context.argtypes = [c_void_p, c_void_p] -isl.isl_schedule_constraints_set_proximity.restype = c_void_p -isl.isl_schedule_constraints_set_proximity.argtypes = [c_void_p, c_void_p] -isl.isl_schedule_constraints_set_validity.restype = c_void_p -isl.isl_schedule_constraints_set_validity.argtypes = [c_void_p, c_void_p] -isl.isl_schedule_constraints_copy.restype = c_void_p -isl.isl_schedule_constraints_copy.argtypes = [c_void_p] -isl.isl_schedule_constraints_free.restype = c_void_p -isl.isl_schedule_constraints_free.argtypes = [c_void_p] -isl.isl_schedule_constraints_to_str.restype = POINTER(c_char) -isl.isl_schedule_constraints_to_str.argtypes = [c_void_p] +isl.isl_union_access_info_from_sink.restype = c_void_p +isl.isl_union_access_info_from_sink.argtypes = [c_void_p] +isl.isl_union_access_info_compute_flow.restype = c_void_p +isl.isl_union_access_info_compute_flow.argtypes = [c_void_p] +isl.isl_union_access_info_set_kill.restype = c_void_p +isl.isl_union_access_info_set_kill.argtypes = [c_void_p, c_void_p] +isl.isl_union_access_info_set_may_source.restype = c_void_p +isl.isl_union_access_info_set_may_source.argtypes = [c_void_p, c_void_p] +isl.isl_union_access_info_set_must_source.restype = c_void_p +isl.isl_union_access_info_set_must_source.argtypes = [c_void_p, c_void_p] +isl.isl_union_access_info_set_schedule.restype = c_void_p +isl.isl_union_access_info_set_schedule.argtypes = [c_void_p, c_void_p] +isl.isl_union_access_info_set_schedule_map.restype = c_void_p +isl.isl_union_access_info_set_schedule_map.argtypes = [c_void_p, c_void_p] +isl.isl_union_access_info_copy.restype = c_void_p +isl.isl_union_access_info_copy.argtypes = [c_void_p] +isl.isl_union_access_info_free.restype = c_void_p +isl.isl_union_access_info_free.argtypes = [c_void_p] +isl.isl_union_access_info_to_str.restype = POINTER(c_char) +isl.isl_union_access_info_to_str.argtypes = [c_void_p] -class schedule_node(object): +class union_flow(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] @@ -4706,351 +12545,400 @@ raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_schedule_node_free(self.ptr) + isl.isl_union_flow_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise - ptr = isl.isl_schedule_node_to_str(arg0.ptr) + ptr = isl.isl_union_flow_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.schedule_node("""%s""")' % s + return 'isl.union_flow("""%s""")' % s else: - return 'isl.schedule_node("%s")' % s - def band_member_get_coincident(arg0, arg1): - try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) - except: - raise - ctx = arg0.ctx - res = isl.isl_schedule_node_band_member_get_coincident(arg0.ptr, arg1) - if res < 0: - raise - return bool(res) - def band_member_set_coincident(arg0, arg1, arg2): - try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) - except: - raise - ctx = arg0.ctx - res = isl.isl_schedule_node_band_member_set_coincident(isl.isl_schedule_node_copy(arg0.ptr), arg1, arg2) - return schedule_node(ctx=ctx, ptr=res) - def child(arg0, arg1): + return 'isl.union_flow("%s")' % s + def full_may_dependence(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_child(isl.isl_schedule_node_copy(arg0.ptr), arg1) - return schedule_node(ctx=ctx, ptr=res) - def get_prefix_schedule_multi_union_pw_aff(arg0): + res = isl.isl_union_flow_get_full_may_dependence(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_full_may_dependence(arg0): + return arg0.full_may_dependence() + def full_must_dependence(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff(arg0.ptr) - return multi_union_pw_aff(ctx=ctx, ptr=res) - def get_prefix_schedule_union_map(arg0): + res = isl.isl_union_flow_get_full_must_dependence(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_full_must_dependence(arg0): + return arg0.full_must_dependence() + def may_dependence(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_get_prefix_schedule_union_map(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_prefix_schedule_union_pw_multi_aff(arg0): + res = isl.isl_union_flow_get_may_dependence(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_may_dependence(arg0): + return arg0.may_dependence() + def may_no_source(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff(arg0.ptr) - return union_pw_multi_aff(ctx=ctx, ptr=res) - def get_schedule(arg0): + res = isl.isl_union_flow_get_may_no_source(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_may_no_source(arg0): + return arg0.may_no_source() + def must_dependence(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_get_schedule(arg0.ptr) - return schedule(ctx=ctx, ptr=res) - def parent(arg0): + res = isl.isl_union_flow_get_must_dependence(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_must_dependence(arg0): + return arg0.must_dependence() + def must_no_source(arg0): try: - if not arg0.__class__ is schedule_node: - arg0 = schedule_node(arg0) + if not arg0.__class__ is union_flow: + arg0 = union_flow(arg0) except: raise ctx = arg0.ctx - res = isl.isl_schedule_node_parent(isl.isl_schedule_node_copy(arg0.ptr)) - return schedule_node(ctx=ctx, ptr=res) + res = isl.isl_union_flow_get_must_no_source(arg0.ptr) + obj = union_map(ctx=ctx, ptr=res) + return obj + def get_must_no_source(arg0): + return arg0.must_no_source() -isl.isl_schedule_node_band_member_get_coincident.restype = c_bool -isl.isl_schedule_node_band_member_get_coincident.argtypes = [c_void_p, c_int] -isl.isl_schedule_node_band_member_set_coincident.restype = c_void_p -isl.isl_schedule_node_band_member_set_coincident.argtypes = [c_void_p, c_int, c_int] -isl.isl_schedule_node_child.restype = c_void_p -isl.isl_schedule_node_child.argtypes = [c_void_p, c_int] -isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff.restype = c_void_p -isl.isl_schedule_node_get_prefix_schedule_multi_union_pw_aff.argtypes = [c_void_p] -isl.isl_schedule_node_get_prefix_schedule_union_map.restype = c_void_p -isl.isl_schedule_node_get_prefix_schedule_union_map.argtypes = [c_void_p] -isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff.restype = c_void_p -isl.isl_schedule_node_get_prefix_schedule_union_pw_multi_aff.argtypes = [c_void_p] -isl.isl_schedule_node_get_schedule.restype = c_void_p -isl.isl_schedule_node_get_schedule.argtypes = [c_void_p] -isl.isl_schedule_node_parent.restype = c_void_p -isl.isl_schedule_node_parent.argtypes = [c_void_p] -isl.isl_schedule_node_copy.restype = c_void_p -isl.isl_schedule_node_copy.argtypes = [c_void_p] -isl.isl_schedule_node_free.restype = c_void_p -isl.isl_schedule_node_free.argtypes = [c_void_p] -isl.isl_schedule_node_to_str.restype = POINTER(c_char) -isl.isl_schedule_node_to_str.argtypes = [c_void_p] +isl.isl_union_flow_get_full_may_dependence.restype = c_void_p +isl.isl_union_flow_get_full_may_dependence.argtypes = [c_void_p] +isl.isl_union_flow_get_full_must_dependence.restype = c_void_p +isl.isl_union_flow_get_full_must_dependence.argtypes = [c_void_p] +isl.isl_union_flow_get_may_dependence.restype = c_void_p +isl.isl_union_flow_get_may_dependence.argtypes = [c_void_p] +isl.isl_union_flow_get_may_no_source.restype = c_void_p +isl.isl_union_flow_get_may_no_source.argtypes = [c_void_p] +isl.isl_union_flow_get_must_dependence.restype = c_void_p +isl.isl_union_flow_get_must_dependence.argtypes = [c_void_p] +isl.isl_union_flow_get_must_no_source.restype = c_void_p +isl.isl_union_flow_get_must_no_source.argtypes = [c_void_p] +isl.isl_union_flow_copy.restype = c_void_p +isl.isl_union_flow_copy.argtypes = [c_void_p] +isl.isl_union_flow_free.restype = c_void_p +isl.isl_union_flow_free.argtypes = [c_void_p] +isl.isl_union_flow_to_str.restype = POINTER(c_char) +isl.isl_union_flow_to_str.argtypes = [c_void_p] -class union_access_info(object): +class union_pw_aff_list(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return - if len(args) == 1 and args[0].__class__ is union_map: + if len(args) == 1 and type(args[0]) == int: self.ctx = Context.getDefaultInstance() - self.ptr = isl.isl_union_access_info_from_sink(isl.isl_union_map_copy(args[0].ptr)) + self.ptr = isl.isl_union_pw_aff_list_alloc(self.ctx, args[0]) return + if len(args) == 1 and args[0].__class__ is union_pw_aff: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_pw_aff_list_from_union_pw_aff(isl.isl_union_pw_aff_copy(args[0].ptr)) + return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_union_access_info_free(self.ptr) + isl.isl_union_pw_aff_list_free(self.ptr) def __str__(arg0): - try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) - except: - raise - ptr = isl.isl_union_access_info_to_str(arg0.ptr) - res = cast(ptr, c_char_p).value.decode('ascii') - libc.free(ptr) - return res - def __repr__(self): - s = str(self) - if '"' in s: - return 'isl.union_access_info("""%s""")' % s - else: - return 'isl.union_access_info("%s")' % s - def compute_flow(arg0): - try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) - except: - raise - ctx = arg0.ctx - res = isl.isl_union_access_info_compute_flow(isl.isl_union_access_info_copy(arg0.ptr)) - return union_flow(ctx=ctx, ptr=res) - def set_kill(arg0, arg1): - try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) - except: - raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_access_info_set_kill(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_access_info(ctx=ctx, ptr=res) - def set_may_source(arg0, arg1): + ptr = isl.isl_union_pw_aff_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.union_pw_aff_list("""%s""")' % s + else: + return 'isl.union_pw_aff_list("%s")' % s + def add(arg0, arg1): try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg1.__class__ is union_pw_aff: + arg1 = union_pw_aff(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_access_info_set_may_source(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_access_info(ctx=ctx, ptr=res) - def set_must_source(arg0, arg1): + res = isl.isl_union_pw_aff_list_add(isl.isl_union_pw_aff_list_copy(arg0.ptr), isl.isl_union_pw_aff_copy(arg1.ptr)) + obj = union_pw_aff_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_union_pw_aff_list_clear(isl.isl_union_pw_aff_list_copy(arg0.ptr)) + obj = union_pw_aff_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise - ctx = arg0.ctx - res = isl.isl_union_access_info_set_must_source(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_access_info(ctx=ctx, ptr=res) - def set_schedule(arg0, arg1): try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) + if not arg1.__class__ is union_pw_aff_list: + arg1 = union_pw_aff_list(arg1) except: raise + ctx = arg0.ctx + res = isl.isl_union_pw_aff_list_concat(isl.isl_union_pw_aff_list_copy(arg0.ptr), isl.isl_union_pw_aff_list_copy(arg1.ptr)) + obj = union_pw_aff_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): try: - if not arg1.__class__ is schedule: - arg1 = schedule(arg1) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = union_pw_aff(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_access_info_set_schedule(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_schedule_copy(arg1.ptr)) - return union_access_info(ctx=ctx, ptr=res) - def set_schedule_map(arg0, arg1): + res = isl.isl_union_pw_aff_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): try: - if not arg0.__class__ is union_access_info: - arg0 = union_access_info(arg0) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise + ctx = arg0.ctx + res = isl.isl_union_pw_aff_list_get_at(arg0.ptr, arg1) + obj = union_pw_aff(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): try: - if not arg1.__class__ is union_map: - arg1 = union_map(arg1) + if not arg0.__class__ is union_pw_aff_list: + arg0 = union_pw_aff_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_access_info_set_schedule_map(isl.isl_union_access_info_copy(arg0.ptr), isl.isl_union_map_copy(arg1.ptr)) - return union_access_info(ctx=ctx, ptr=res) + res = isl.isl_union_pw_aff_list_size(arg0.ptr) + if res < 0: + raise + return int(res) -isl.isl_union_access_info_from_sink.restype = c_void_p -isl.isl_union_access_info_from_sink.argtypes = [c_void_p] -isl.isl_union_access_info_compute_flow.restype = c_void_p -isl.isl_union_access_info_compute_flow.argtypes = [c_void_p] -isl.isl_union_access_info_set_kill.restype = c_void_p -isl.isl_union_access_info_set_kill.argtypes = [c_void_p, c_void_p] -isl.isl_union_access_info_set_may_source.restype = c_void_p -isl.isl_union_access_info_set_may_source.argtypes = [c_void_p, c_void_p] -isl.isl_union_access_info_set_must_source.restype = c_void_p -isl.isl_union_access_info_set_must_source.argtypes = [c_void_p, c_void_p] -isl.isl_union_access_info_set_schedule.restype = c_void_p -isl.isl_union_access_info_set_schedule.argtypes = [c_void_p, c_void_p] -isl.isl_union_access_info_set_schedule_map.restype = c_void_p -isl.isl_union_access_info_set_schedule_map.argtypes = [c_void_p, c_void_p] -isl.isl_union_access_info_copy.restype = c_void_p -isl.isl_union_access_info_copy.argtypes = [c_void_p] -isl.isl_union_access_info_free.restype = c_void_p -isl.isl_union_access_info_free.argtypes = [c_void_p] -isl.isl_union_access_info_to_str.restype = POINTER(c_char) -isl.isl_union_access_info_to_str.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_alloc.restype = c_void_p +isl.isl_union_pw_aff_list_alloc.argtypes = [Context, c_int] +isl.isl_union_pw_aff_list_from_union_pw_aff.restype = c_void_p +isl.isl_union_pw_aff_list_from_union_pw_aff.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_add.restype = c_void_p +isl.isl_union_pw_aff_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_list_clear.restype = c_void_p +isl.isl_union_pw_aff_list_clear.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_concat.restype = c_void_p +isl.isl_union_pw_aff_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_union_pw_aff_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_pw_aff_list_get_at.restype = c_void_p +isl.isl_union_pw_aff_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_union_pw_aff_list_size.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_copy.restype = c_void_p +isl.isl_union_pw_aff_list_copy.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_free.restype = c_void_p +isl.isl_union_pw_aff_list_free.argtypes = [c_void_p] +isl.isl_union_pw_aff_list_to_str.restype = POINTER(c_char) +isl.isl_union_pw_aff_list_to_str.argtypes = [c_void_p] -class union_flow(object): +class union_set_list(object): def __init__(self, *args, **keywords): if "ptr" in keywords: self.ctx = keywords["ctx"] self.ptr = keywords["ptr"] return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and args[0].__class__ is union_set: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_union_set_list_from_union_set(isl.isl_union_set_copy(args[0].ptr)) + return raise Error def __del__(self): if hasattr(self, 'ptr'): - isl.isl_union_flow_free(self.ptr) + isl.isl_union_set_list_free(self.ptr) def __str__(arg0): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise - ptr = isl.isl_union_flow_to_str(arg0.ptr) + ptr = isl.isl_union_set_list_to_str(arg0.ptr) res = cast(ptr, c_char_p).value.decode('ascii') libc.free(ptr) return res def __repr__(self): s = str(self) if '"' in s: - return 'isl.union_flow("""%s""")' % s + return 'isl.union_set_list("""%s""")' % s else: - return 'isl.union_flow("%s")' % s - def get_full_may_dependence(arg0): + return 'isl.union_set_list("%s")' % s + def add(arg0, arg1): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) + except: + raise + try: + if not arg1.__class__ is union_set: + arg1 = union_set(arg1) except: raise ctx = arg0.ctx - res = isl.isl_union_flow_get_full_may_dependence(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_full_must_dependence(arg0): + res = isl.isl_union_set_list_add(isl.isl_union_set_list_copy(arg0.ptr), isl.isl_union_set_copy(arg1.ptr)) + obj = union_set_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_flow_get_full_must_dependence(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_may_dependence(arg0): + res = isl.isl_union_set_list_clear(isl.isl_union_set_list_copy(arg0.ptr)) + obj = union_set_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise + try: + if not arg1.__class__ is union_set_list: + arg1 = union_set_list(arg1) + except: + raise ctx = arg0.ctx - res = isl.isl_union_flow_get_may_dependence(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_may_no_source(arg0): + res = isl.isl_union_set_list_concat(isl.isl_union_set_list_copy(arg0.ptr), isl.isl_union_set_list_copy(arg1.ptr)) + obj = union_set_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = union_set(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) ctx = arg0.ctx - res = isl.isl_union_flow_get_may_no_source(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_must_dependence(arg0): + res = isl.isl_union_set_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_flow_get_must_dependence(arg0.ptr) - return union_map(ctx=ctx, ptr=res) - def get_must_no_source(arg0): + res = isl.isl_union_set_list_get_at(arg0.ptr, arg1) + obj = union_set(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): try: - if not arg0.__class__ is union_flow: - arg0 = union_flow(arg0) + if not arg0.__class__ is union_set_list: + arg0 = union_set_list(arg0) except: raise ctx = arg0.ctx - res = isl.isl_union_flow_get_must_no_source(arg0.ptr) - return union_map(ctx=ctx, ptr=res) + res = isl.isl_union_set_list_size(arg0.ptr) + if res < 0: + raise + return int(res) -isl.isl_union_flow_get_full_may_dependence.restype = c_void_p -isl.isl_union_flow_get_full_may_dependence.argtypes = [c_void_p] -isl.isl_union_flow_get_full_must_dependence.restype = c_void_p -isl.isl_union_flow_get_full_must_dependence.argtypes = [c_void_p] -isl.isl_union_flow_get_may_dependence.restype = c_void_p -isl.isl_union_flow_get_may_dependence.argtypes = [c_void_p] -isl.isl_union_flow_get_may_no_source.restype = c_void_p -isl.isl_union_flow_get_may_no_source.argtypes = [c_void_p] -isl.isl_union_flow_get_must_dependence.restype = c_void_p -isl.isl_union_flow_get_must_dependence.argtypes = [c_void_p] -isl.isl_union_flow_get_must_no_source.restype = c_void_p -isl.isl_union_flow_get_must_no_source.argtypes = [c_void_p] -isl.isl_union_flow_copy.restype = c_void_p -isl.isl_union_flow_copy.argtypes = [c_void_p] -isl.isl_union_flow_free.restype = c_void_p -isl.isl_union_flow_free.argtypes = [c_void_p] -isl.isl_union_flow_to_str.restype = POINTER(c_char) -isl.isl_union_flow_to_str.argtypes = [c_void_p] +isl.isl_union_set_list_alloc.restype = c_void_p +isl.isl_union_set_list_alloc.argtypes = [Context, c_int] +isl.isl_union_set_list_from_union_set.restype = c_void_p +isl.isl_union_set_list_from_union_set.argtypes = [c_void_p] +isl.isl_union_set_list_add.restype = c_void_p +isl.isl_union_set_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_list_clear.restype = c_void_p +isl.isl_union_set_list_clear.argtypes = [c_void_p] +isl.isl_union_set_list_concat.restype = c_void_p +isl.isl_union_set_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_union_set_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_union_set_list_get_at.restype = c_void_p +isl.isl_union_set_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_union_set_list_size.argtypes = [c_void_p] +isl.isl_union_set_list_copy.restype = c_void_p +isl.isl_union_set_list_copy.argtypes = [c_void_p] +isl.isl_union_set_list_free.restype = c_void_p +isl.isl_union_set_list_free.argtypes = [c_void_p] +isl.isl_union_set_list_to_str.restype = POINTER(c_char) +isl.isl_union_set_list_to_str.argtypes = [c_void_p] class val(object): def __init__(self, *args, **keywords): @@ -5094,7 +12982,8 @@ raise ctx = arg0.ctx res = isl.isl_val_abs(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def abs_eq(arg0, arg1): try: if not arg0.__class__ is val: @@ -5124,7 +13013,8 @@ raise ctx = arg0.ctx res = isl.isl_val_add(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def ceil(arg0): try: if not arg0.__class__ is val: @@ -5133,7 +13023,8 @@ raise ctx = arg0.ctx res = isl.isl_val_ceil(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def cmp_si(arg0, arg1): try: if not arg0.__class__ is val: @@ -5156,7 +13047,8 @@ raise ctx = arg0.ctx res = isl.isl_val_div(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def eq(arg0, arg1): try: if not arg0.__class__ is val: @@ -5181,7 +13073,8 @@ raise ctx = arg0.ctx res = isl.isl_val_floor(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def gcd(arg0, arg1): try: if not arg0.__class__ is val: @@ -5195,7 +13088,8 @@ raise ctx = arg0.ctx res = isl.isl_val_gcd(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def ge(arg0, arg1): try: if not arg0.__class__ is val: @@ -5212,6 +13106,28 @@ if res < 0: raise return bool(res) + def den_si(arg0): + try: + if not arg0.__class__ is val: + arg0 = val(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_get_den_si(arg0.ptr) + return res + def get_den_si(arg0): + return arg0.den_si() + def num_si(arg0): + try: + if not arg0.__class__ is val: + arg0 = val(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_get_num_si(arg0.ptr) + return res + def get_num_si(arg0): + return arg0.num_si() def gt(arg0, arg1): try: if not arg0.__class__ is val: @@ -5232,7 +13148,8 @@ def infty(): ctx = Context.getDefaultInstance() res = isl.isl_val_infty(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def inv(arg0): try: if not arg0.__class__ is val: @@ -5241,7 +13158,8 @@ raise ctx = arg0.ctx res = isl.isl_val_inv(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def is_divisible_by(arg0, arg1): try: if not arg0.__class__ is val: @@ -5435,7 +13353,8 @@ raise ctx = arg0.ctx res = isl.isl_val_max(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def min(arg0, arg1): try: if not arg0.__class__ is val: @@ -5449,7 +13368,8 @@ raise ctx = arg0.ctx res = isl.isl_val_min(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def mod(arg0, arg1): try: if not arg0.__class__ is val: @@ -5463,7 +13383,8 @@ raise ctx = arg0.ctx res = isl.isl_val_mod(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def mul(arg0, arg1): try: if not arg0.__class__ is val: @@ -5477,12 +13398,14 @@ raise ctx = arg0.ctx res = isl.isl_val_mul(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj @staticmethod def nan(): ctx = Context.getDefaultInstance() res = isl.isl_val_nan(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def ne(arg0, arg1): try: if not arg0.__class__ is val: @@ -5507,22 +13430,36 @@ raise ctx = arg0.ctx res = isl.isl_val_neg(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj @staticmethod def neginfty(): ctx = Context.getDefaultInstance() res = isl.isl_val_neginfty(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj @staticmethod def negone(): ctx = Context.getDefaultInstance() res = isl.isl_val_negone(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj @staticmethod def one(): ctx = Context.getDefaultInstance() res = isl.isl_val_one(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj + def pow2(arg0): + try: + if not arg0.__class__ is val: + arg0 = val(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_pow2(isl.isl_val_copy(arg0.ptr)) + obj = val(ctx=ctx, ptr=res) + return obj def sgn(arg0): try: if not arg0.__class__ is val: @@ -5545,7 +13482,8 @@ raise ctx = arg0.ctx res = isl.isl_val_sub(isl.isl_val_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj def trunc(arg0): try: if not arg0.__class__ is val: @@ -5554,12 +13492,14 @@ raise ctx = arg0.ctx res = isl.isl_val_trunc(isl.isl_val_copy(arg0.ptr)) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj @staticmethod def zero(): ctx = Context.getDefaultInstance() res = isl.isl_val_zero(ctx) - return val(ctx=ctx, ptr=res) + obj = val(ctx=ctx, ptr=res) + return obj isl.isl_val_int_from_si.restype = c_void_p isl.isl_val_int_from_si.argtypes = [Context, c_long] @@ -5567,7 +13507,6 @@ isl.isl_val_read_from_str.argtypes = [Context, c_char_p] isl.isl_val_abs.restype = c_void_p isl.isl_val_abs.argtypes = [c_void_p] -isl.isl_val_abs_eq.restype = c_bool isl.isl_val_abs_eq.argtypes = [c_void_p, c_void_p] isl.isl_val_add.restype = c_void_p isl.isl_val_add.argtypes = [c_void_p, c_void_p] @@ -5576,49 +13515,33 @@ isl.isl_val_cmp_si.argtypes = [c_void_p, c_long] isl.isl_val_div.restype = c_void_p isl.isl_val_div.argtypes = [c_void_p, c_void_p] -isl.isl_val_eq.restype = c_bool isl.isl_val_eq.argtypes = [c_void_p, c_void_p] isl.isl_val_floor.restype = c_void_p isl.isl_val_floor.argtypes = [c_void_p] isl.isl_val_gcd.restype = c_void_p isl.isl_val_gcd.argtypes = [c_void_p, c_void_p] -isl.isl_val_ge.restype = c_bool isl.isl_val_ge.argtypes = [c_void_p, c_void_p] -isl.isl_val_gt.restype = c_bool +isl.isl_val_get_den_si.argtypes = [c_void_p] +isl.isl_val_get_num_si.argtypes = [c_void_p] isl.isl_val_gt.argtypes = [c_void_p, c_void_p] isl.isl_val_infty.restype = c_void_p isl.isl_val_infty.argtypes = [Context] isl.isl_val_inv.restype = c_void_p isl.isl_val_inv.argtypes = [c_void_p] -isl.isl_val_is_divisible_by.restype = c_bool isl.isl_val_is_divisible_by.argtypes = [c_void_p, c_void_p] -isl.isl_val_is_infty.restype = c_bool isl.isl_val_is_infty.argtypes = [c_void_p] -isl.isl_val_is_int.restype = c_bool isl.isl_val_is_int.argtypes = [c_void_p] -isl.isl_val_is_nan.restype = c_bool isl.isl_val_is_nan.argtypes = [c_void_p] -isl.isl_val_is_neg.restype = c_bool isl.isl_val_is_neg.argtypes = [c_void_p] -isl.isl_val_is_neginfty.restype = c_bool isl.isl_val_is_neginfty.argtypes = [c_void_p] -isl.isl_val_is_negone.restype = c_bool isl.isl_val_is_negone.argtypes = [c_void_p] -isl.isl_val_is_nonneg.restype = c_bool isl.isl_val_is_nonneg.argtypes = [c_void_p] -isl.isl_val_is_nonpos.restype = c_bool isl.isl_val_is_nonpos.argtypes = [c_void_p] -isl.isl_val_is_one.restype = c_bool isl.isl_val_is_one.argtypes = [c_void_p] -isl.isl_val_is_pos.restype = c_bool isl.isl_val_is_pos.argtypes = [c_void_p] -isl.isl_val_is_rat.restype = c_bool isl.isl_val_is_rat.argtypes = [c_void_p] -isl.isl_val_is_zero.restype = c_bool isl.isl_val_is_zero.argtypes = [c_void_p] -isl.isl_val_le.restype = c_bool isl.isl_val_le.argtypes = [c_void_p, c_void_p] -isl.isl_val_lt.restype = c_bool isl.isl_val_lt.argtypes = [c_void_p, c_void_p] isl.isl_val_max.restype = c_void_p isl.isl_val_max.argtypes = [c_void_p, c_void_p] @@ -5630,7 +13553,6 @@ isl.isl_val_mul.argtypes = [c_void_p, c_void_p] isl.isl_val_nan.restype = c_void_p isl.isl_val_nan.argtypes = [Context] -isl.isl_val_ne.restype = c_bool isl.isl_val_ne.argtypes = [c_void_p, c_void_p] isl.isl_val_neg.restype = c_void_p isl.isl_val_neg.argtypes = [c_void_p] @@ -5640,6 +13562,8 @@ isl.isl_val_negone.argtypes = [Context] isl.isl_val_one.restype = c_void_p isl.isl_val_one.argtypes = [Context] +isl.isl_val_pow2.restype = c_void_p +isl.isl_val_pow2.argtypes = [c_void_p] isl.isl_val_sgn.argtypes = [c_void_p] isl.isl_val_sub.restype = c_void_p isl.isl_val_sub.argtypes = [c_void_p, c_void_p] @@ -5653,3 +13577,152 @@ isl.isl_val_free.argtypes = [c_void_p] isl.isl_val_to_str.restype = POINTER(c_char) isl.isl_val_to_str.argtypes = [c_void_p] + +class val_list(object): + def __init__(self, *args, **keywords): + if "ptr" in keywords: + self.ctx = keywords["ctx"] + self.ptr = keywords["ptr"] + return + if len(args) == 1 and type(args[0]) == int: + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_val_list_alloc(self.ctx, args[0]) + return + if len(args) == 1 and (args[0].__class__ is val or type(args[0]) == int): + args = list(args) + try: + if not args[0].__class__ is val: + args[0] = val(args[0]) + except: + raise + self.ctx = Context.getDefaultInstance() + self.ptr = isl.isl_val_list_from_val(isl.isl_val_copy(args[0].ptr)) + return + raise Error + def __del__(self): + if hasattr(self, 'ptr'): + isl.isl_val_list_free(self.ptr) + def __str__(arg0): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + ptr = isl.isl_val_list_to_str(arg0.ptr) + res = cast(ptr, c_char_p).value.decode('ascii') + libc.free(ptr) + return res + def __repr__(self): + s = str(self) + if '"' in s: + return 'isl.val_list("""%s""")' % s + else: + return 'isl.val_list("%s")' % s + def add(arg0, arg1): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + try: + if not arg1.__class__ is val: + arg1 = val(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_list_add(isl.isl_val_list_copy(arg0.ptr), isl.isl_val_copy(arg1.ptr)) + obj = val_list(ctx=ctx, ptr=res) + return obj + def clear(arg0): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_list_clear(isl.isl_val_list_copy(arg0.ptr)) + obj = val_list(ctx=ctx, ptr=res) + return obj + def concat(arg0, arg1): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + try: + if not arg1.__class__ is val_list: + arg1 = val_list(arg1) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_list_concat(isl.isl_val_list_copy(arg0.ptr), isl.isl_val_list_copy(arg1.ptr)) + obj = val_list(ctx=ctx, ptr=res) + return obj + def foreach(arg0, arg1): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + exc_info = [None] + fn = CFUNCTYPE(c_int, c_void_p, c_void_p) + def cb_func(cb_arg0, cb_arg1): + cb_arg0 = val(ctx=arg0.ctx, ptr=(cb_arg0)) + try: + arg1(cb_arg0) + except: + import sys + exc_info[0] = sys.exc_info() + return -1 + return 0 + cb = fn(cb_func) + ctx = arg0.ctx + res = isl.isl_val_list_foreach(arg0.ptr, cb, None) + if exc_info[0] != None: + raise (exc_info[0][0], exc_info[0][1], exc_info[0][2]) + if res < 0: + raise + def at(arg0, arg1): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_list_get_at(arg0.ptr, arg1) + obj = val(ctx=ctx, ptr=res) + return obj + def get_at(arg0, arg1): + return arg0.at(arg1) + def size(arg0): + try: + if not arg0.__class__ is val_list: + arg0 = val_list(arg0) + except: + raise + ctx = arg0.ctx + res = isl.isl_val_list_size(arg0.ptr) + if res < 0: + raise + return int(res) + +isl.isl_val_list_alloc.restype = c_void_p +isl.isl_val_list_alloc.argtypes = [Context, c_int] +isl.isl_val_list_from_val.restype = c_void_p +isl.isl_val_list_from_val.argtypes = [c_void_p] +isl.isl_val_list_add.restype = c_void_p +isl.isl_val_list_add.argtypes = [c_void_p, c_void_p] +isl.isl_val_list_clear.restype = c_void_p +isl.isl_val_list_clear.argtypes = [c_void_p] +isl.isl_val_list_concat.restype = c_void_p +isl.isl_val_list_concat.argtypes = [c_void_p, c_void_p] +isl.isl_val_list_foreach.argtypes = [c_void_p, c_void_p, c_void_p] +isl.isl_val_list_get_at.restype = c_void_p +isl.isl_val_list_get_at.argtypes = [c_void_p, c_int] +isl.isl_val_list_size.argtypes = [c_void_p] +isl.isl_val_list_copy.restype = c_void_p +isl.isl_val_list_copy.argtypes = [c_void_p] +isl.isl_val_list_free.restype = c_void_p +isl.isl_val_list_free.argtypes = [c_void_p] +isl.isl_val_list_to_str.restype = POINTER(c_char) +isl.isl_val_list_to_str.argtypes = [c_void_p] diff --git a/gcc/isl/interface/isl.py.top b/gcc/isl/interface/isl.py.top deleted file mode 100644 index 71c2b0d..0000000 100644 --- a/gcc/isl/interface/isl.py.top +++ /dev/null @@ -1,29 +1,0 @@ -from ctypes import * - -isl = cdll.LoadLibrary("libisl.so") -libc = cdll.LoadLibrary("libc.so.6") - -class Error(Exception): - pass - -class Context: - defaultInstance = None - - def __init__(self): - ptr = isl.isl_ctx_alloc() - self.ptr = ptr - - def __del__(self): - isl.isl_ctx_free(self) - - def from_param(self): - return c_void_p(self.ptr) - - @staticmethod - def getDefaultInstance(): - if Context.defaultInstance == None: - Context.defaultInstance = Context() - return Context.defaultInstance - -isl.isl_ctx_alloc.restype = c_void_p -isl.isl_ctx_free.argtypes = [Context] diff --git a/gcc/isl/interface/isl_test_python.py b/gcc/isl/interface/isl_test_python.py deleted file mode 100755 index 10b9c95..0000000 100755 --- a/gcc/isl/interface/isl_test_python.py +++ /dev/null @@ -1,201 +1,0 @@ -# Copyright 2016-2017 Tobias Grosser -# -# Use of this software is governed by the MIT license -# -# Written by Tobias Grosser, Weststrasse 47, CH-8003, Zurich - -import sys -import isl - -# Test that isl objects can be constructed. -# -# This tests: -# - construction from a string -# - construction from an integer -# - static constructor without a parameter -# - conversion construction -# -# The tests to construct from integers and strings cover functionality that -# is also tested in the parameter type tests, but here the presence of -# multiple overloaded constructors and overload resolution is tested. -# -def test_constructors(): - zero1 = isl.val("0") - assert(zero1.is_zero()) - - zero2 = isl.val(0) - assert(zero2.is_zero()) - - zero3 = isl.val.zero() - assert(zero3.is_zero()) - - bs = isl.basic_set("{ [1] }") - result = isl.set("{ [1] }") - s = isl.set(bs) - assert(s.is_equal(result)) - -# Test integer function parameters for a particular integer value. -# -def test_int(i): - val_int = isl.val(i) - val_str = isl.val(str(i)) - assert(val_int.eq(val_str)) - -# Test integer function parameters. -# -# Verify that extreme values and zero work. -# -def test_parameters_int(): - test_int(sys.maxsize) - test_int(-sys.maxsize - 1) - test_int(0) - -# Test isl objects parameters. -# -# Verify that isl objects can be passed as lvalue and rvalue parameters. -# Also verify that isl object parameters are automatically type converted if -# there is an inheritance relation. Finally, test function calls without -# any additional parameters, apart from the isl object on which -# the method is called. -# -def test_parameters_obj(): - a = isl.set("{ [0] }") - b = isl.set("{ [1] }") - c = isl.set("{ [2] }") - expected = isl.set("{ [i] : 0 <= i <= 2 }") - - tmp = a.union(b) - res_lvalue_param = tmp.union(c) - assert(res_lvalue_param.is_equal(expected)) - - res_rvalue_param = a.union(b).union(c) - assert(res_rvalue_param.is_equal(expected)) - - a2 = isl.basic_set("{ [0] }") - assert(a.is_equal(a2)) - - two = isl.val(2) - half = isl.val("1/2") - res_only_this_param = two.inv() - assert(res_only_this_param.eq(half)) - -# Test different kinds of parameters to be passed to functions. -# -# This includes integer and isl object parameters. -# -def test_parameters(): - test_parameters_int() - test_parameters_obj() - -# Test that isl objects are returned correctly. -# -# This only tests that after combining two objects, the result is successfully -# returned. -# -def test_return_obj(): - one = isl.val("1") - two = isl.val("2") - three = isl.val("3") - - res = one.add(two) - - assert(res.eq(three)) - -# Test that integer values are returned correctly. -# -def test_return_int(): - one = isl.val("1") - neg_one = isl.val("-1") - zero = isl.val("0") - - assert(one.sgn() > 0) - assert(neg_one.sgn() < 0) - assert(zero.sgn() == 0) - -# Test that isl_bool values are returned correctly. -# -# In particular, check the conversion to bool in case of true and false. -# -def test_return_bool(): - empty = isl.set("{ : false }") - univ = isl.set("{ : }") - - b_true = empty.is_empty() - b_false = univ.is_empty() - - assert(b_true) - assert(not b_false) - -# Test that strings are returned correctly. -# Do so by calling overloaded isl.ast_build.from_expr methods. -# -def test_return_string(): - context = isl.set("[n] -> { : }") - build = isl.ast_build.from_context(context) - pw_aff = isl.pw_aff("[n] -> { [n] }") - set = isl.set("[n] -> { : n >= 0 }") - - expr = build.expr_from(pw_aff) - expected_string = "n" - assert(expected_string == expr.to_C_str()) - - expr = build.expr_from(set) - expected_string = "n >= 0" - assert(expected_string == expr.to_C_str()) - -# Test that return values are handled correctly. -# -# Test that isl objects, integers, boolean values, and strings are -# returned correctly. -# -def test_return(): - test_return_obj() - test_return_int() - test_return_bool() - test_return_string() - -# Test that foreach functions are modeled correctly. -# -# Verify that closures are correctly called as callback of a 'foreach' -# function and that variables captured by the closure work correctly. Also -# check that the foreach function handles exceptions thrown from -# the closure and that it propagates the exception. -# -def test_foreach(): - s = isl.set("{ [0]; [1]; [2] }") - - list = [] - def add(bs): - list.append(bs) - s.foreach_basic_set(add) - - assert(len(list) == 3) - assert(list[0].is_subset(s)) - assert(list[1].is_subset(s)) - assert(list[2].is_subset(s)) - assert(not list[0].is_equal(list[1])) - assert(not list[0].is_equal(list[2])) - assert(not list[1].is_equal(list[2])) - - def fail(bs): - raise "fail" - - caught = False - try: - s.foreach_basic_set(fail) - except: - caught = True - assert(caught) - -# Test the isl Python interface -# -# This includes: -# - Object construction -# - Different parameter types -# - Different return types -# - Foreach functions -# -test_constructors() -test_parameters() -test_return() -test_foreach() diff --git a/gcc/isl/interface/python.cc b/gcc/isl/interface/python.cc index 68fdbb8..4212a32 100644 --- a/gcc/isl/interface/python.cc +++ a/gcc/isl/interface/python.cc @@ -33,13 +33,23 @@ #include "isl_config.h" +#include #include + +#include #include #include #include #include "python.h" #include "generator.h" + +/* Argument format for Python methods with a fixed number of arguments. + */ +static const char *fixed_arg_fmt = "arg%d"; +/* Argument format for Python methods with a variable number of arguments. + */ +static const char *var_arg_fmt = "args[%d]"; /* Drop the "isl_" initial part of the type name "name". */ @@ -48,14 +58,25 @@ return name.substr(4); } -/* Print the header of the method "name" with "n_arg" arguments. +/* Print the arguments of a method with "n_arg" arguments, starting at "first". + */ +void python_generator::print_method_arguments(int first, int n_arg) +{ + for (int i = first; i < n_arg; ++i) { + if (i > first) + printf(", "); + printf("arg%d", i); + } +} + +/* Print the start of a definition for method "name" + * (without specifying the arguments). * If "is_static" is set, then mark the python method as static. * * If the method is called "from", then rename it to "convert_from" * because "from" is a python keyword. */ -void python_generator::print_method_header(bool is_static, const string &name, - int n_arg) +static void print_method_def(bool is_static, const string &name) { const char *s; @@ -66,16 +87,35 @@ if (name == "from") s = "convert_from"; - printf(" def %s(", s); - for (int i = 0; i < n_arg; ++i) { - if (i) - printf(", "); - printf("arg%d", i); - } + printf(" def %s", s); +} + +/* Print the header of the method "name" with "n_arg" arguments. + * If "is_static" is set, then mark the python method as static. + */ +void python_generator::print_method_header(bool is_static, const string &name, + int n_arg) +{ + print_method_def(is_static, name); + printf("("); + print_method_arguments(0, n_arg); printf("):\n"); +} + +/* Print formatted output with the given indentation. + */ +static void print_indent(int indent, const char *format, ...) +{ + va_list args; + + printf("%*s", indent, " "); + va_start(args, format); + vprintf(format, args); + va_end(args); } -/* Print a check that the argument in position "pos" is of type "type". +/* Print a check that the argument in position "pos" is of type "type" + * with the given indentation. * If this fails and if "upcast" is set, then convert the first * argument to "super" and call the method "name" on it, passing * the remaining of the "n" arguments. @@ -83,44 +123,107 @@ * an exception. * If "upcast" is not set, then the "super", "name" and "n" arguments * to this function are ignored. + * "fmt" is the format for printing Python method arguments. */ -void python_generator::print_type_check(const string &type, int pos, - bool upcast, const string &super, const string &name, int n) -{ - printf(" try:\n"); - printf(" if not arg%d.__class__ is %s:\n", - pos, type.c_str()); - printf(" arg%d = %s(arg%d)\n", - pos, type.c_str(), pos); - printf(" except:\n"); +void python_generator::print_type_check(int indent, const string &type, + const char *fmt, int pos, bool upcast, const string &super, + const string &name, int n) +{ + print_indent(indent, "try:\n"); + print_indent(indent, " if not "); + printf(fmt, pos); + printf(".__class__ is %s:\n", type.c_str()); + print_indent(indent, " "); + printf(fmt, pos); + printf(" = %s(", type.c_str()); + printf(fmt, pos); + printf(")\n"); + print_indent(indent, "except:\n"); if (upcast) { - printf(" return %s(arg0).%s(", - type2python(super).c_str(), name.c_str()); + print_indent(indent, " return %s(", + type2python(super).c_str()); + printf(fmt, 0); + printf(").%s(", name.c_str()); for (int i = 1; i < n; ++i) { if (i != 1) printf(", "); - printf("arg%d", i); + printf(fmt, i); } printf(")\n"); } else - printf(" raise\n"); + print_indent(indent, " raise\n"); +} + +/* For each of the "n" initial arguments of the function "method" + * that refer to an isl structure, + * including the object on which the method is called, + * check if the corresponding actual argument is of the right type. + * If not, try and convert it to the right type. + * If that doesn't work and if "super" contains at least one element, + * try and convert self to the type of the first superclass in "super" and + * call the corresponding method. + * If "first_is_ctx" is set, then the first argument is skipped. + */ +void python_generator::print_type_checks(const string &cname, + FunctionDecl *method, bool first_is_ctx, int n, + const vector &super) +{ + for (int i = first_is_ctx; i < n; ++i) { + ParmVarDecl *param = method->getParamDecl(i); + string type; + + if (!is_isl_type(param->getOriginalType())) + continue; + type = type2python(extract_type(param->getOriginalType())); + if (!first_is_ctx && i > 0 && super.size() > 0) + print_type_check(8, type, fixed_arg_fmt, + i - first_is_ctx, true, + super[0], cname, n); + else + print_type_check(8, type, fixed_arg_fmt, + i - first_is_ctx, false, "", cname, -1); + } +} + +/* Print a call to the *_copy function corresponding to "type". + */ +void python_generator::print_copy(QualType type) +{ + string type_s = extract_type(type); + + printf("isl.%s_copy", type_s.c_str()); } -/* Construct a wrapper for a callback argument (at position "arg"). +/* Construct a wrapper for callback argument "param" (at position "arg"). * Assign the wrapper to "cb". We assume here that a function call * has at most one callback argument. * - * The wrapper converts the arguments of the callback to python types. + * The wrapper converts the arguments of the callback to python types, + * taking a copy if the C callback does not take its arguments. * If any exception is thrown, the wrapper keeps track of it in exc_info[0] - * and returns -1. Otherwise the wrapper returns 0. + * and returns a value indicating an error. Otherwise the wrapper + * returns a value indicating success. + * In case the C callback is expected to return an isl_stat, + * the error value is -1 and the success value is 0. + * In case the C callback is expected to return an isl_bool, + * the error value is -1 and the success value is 1 or 0 depending + * on the result of the Python callback. + * Otherwise, None is returned to indicate an error and + * a copy of the object in case of success. */ -void python_generator::print_callback(QualType type, int arg) +void python_generator::print_callback(ParmVarDecl *param, int arg) { - const FunctionProtoType *fn = type->getAs(); + QualType type = param->getOriginalType(); + const FunctionProtoType *fn = extract_prototype(type); + QualType return_type = fn->getReturnType(); unsigned n_arg = fn->getNumArgs(); printf(" exc_info = [None]\n"); - printf(" fn = CFUNCTYPE(c_int"); + printf(" fn = CFUNCTYPE("); + if (is_isl_stat(return_type) || is_isl_bool(return_type)) + printf("c_int"); + else + printf("c_void_p"); for (unsigned i = 0; i < n_arg - 1; ++i) { if (!is_isl_type(fn->getArgType(i))) die("Argument has non-isl type"); @@ -137,11 +240,17 @@ for (unsigned i = 0; i < n_arg - 1; ++i) { string arg_type; arg_type = type2python(extract_type(fn->getArgType(i))); - printf(" cb_arg%d = %s(ctx=arg0.ctx, " - "ptr=cb_arg%d)\n", i, arg_type.c_str(), i); + printf(" cb_arg%d = %s(ctx=arg0.ctx, ptr=", + i, arg_type.c_str()); + if (!callback_takes_argument(param, i)) + print_copy(fn->getArgType(i)); + printf("(cb_arg%d))\n", i); } printf(" try:\n"); - printf(" arg%d(", arg); + if (is_isl_stat(return_type)) + printf(" arg%d(", arg); + else + printf(" res = arg%d(", arg); for (unsigned i = 0; i < n_arg - 1; ++i) { if (i) printf(", "); @@ -151,77 +260,240 @@ printf(" except:\n"); printf(" import sys\n"); printf(" exc_info[0] = sys.exc_info()\n"); - printf(" return -1\n"); - printf(" return 0\n"); + if (is_isl_stat(return_type) || is_isl_bool(return_type)) + printf(" return -1\n"); + else + printf(" return None\n"); + if (is_isl_stat(return_type)) { + printf(" return 0\n"); + } else if (is_isl_bool(return_type)) { + printf(" return 1 if res else 0\n"); + } else { + printf(" return "); + print_copy(return_type); + printf("(res.ptr)\n"); + } printf(" cb = fn(cb_func)\n"); } /* Print the argument at position "arg" in call to "fd". + * "fmt" is the format for printing Python method arguments. * "skip" is the number of initial arguments of "fd" that are * skipped in the Python method. * - * If the argument is a callback, then print a reference to + * If the (first) argument is an isl_ctx, then print "ctx", + * assuming that the caller has made the context available + * in a "ctx" variable. + * Otherwise, if the argument is a callback, then print a reference to * the callback wrapper "cb". * Otherwise, if the argument is marked as consuming a reference, * then pass a copy of the pointer stored in the corresponding * argument passed to the Python method. + * Otherwise, if the argument is a string, then the python string is first + * encoded as a byte sequence, using 'ascii' as encoding. This assumes + * that all strings passed to isl can be converted to 'ascii'. * Otherwise, if the argument is a pointer, then pass this pointer itself. * Otherwise, pass the argument directly. */ -void python_generator::print_arg_in_call(FunctionDecl *fd, int arg, int skip) +void python_generator::print_arg_in_call(FunctionDecl *fd, const char *fmt, + int arg, int skip) { ParmVarDecl *param = fd->getParamDecl(arg); QualType type = param->getOriginalType(); - if (is_callback(type)) { + if (is_isl_ctx(type)) { + printf("ctx"); + } else if (is_callback(type)) { printf("cb"); } else if (takes(param)) { - string type_s = extract_type(type); - printf("isl.%s_copy(arg%d.ptr)", type_s.c_str(), arg - skip); + print_copy(type); + printf("("); + printf(fmt, arg - skip); + printf(".ptr)"); + } else if (is_string(type)) { + printf(fmt, arg - skip); + printf(".encode('ascii')"); } else if (type->isPointerType()) { - printf("arg%d.ptr", arg - skip); + printf(fmt, arg - skip); + printf(".ptr"); } else { - printf("arg%d", arg - skip); + printf(fmt, arg - skip); + } +} + +/* Generate code that raises the exception captured in "exc_info", if any, + * with the given indentation. + */ +static void print_rethrow(int indent, const char *exc_info) +{ + print_indent(indent, "if %s != None:\n", exc_info); + print_indent(indent, " raise (%s[0], %s[1], %s[2])\n", + exc_info, exc_info, exc_info); +} + +/* Print code with the given indentation that checks + * whether any of the persistent callbacks of "clazz" + * is set and if it failed with an exception. If so, the 'exc_info' + * field contains the exception and is raised again. + * The field is cleared because the callback and its data may get reused. + * "fmt" is the format for printing Python method arguments. + */ +static void print_persistent_callback_failure_check(int indent, + const isl_class &clazz, const char *fmt) +{ + const set &callbacks = clazz.persistent_callbacks; + set::const_iterator in; + + for (in = callbacks.begin(); in != callbacks.end(); ++in) { + string callback_name = clazz.persistent_callback_name(*in); + + print_indent(indent, "if hasattr("); + printf(fmt, 0); + printf(", '%s') and ", callback_name.c_str()); + printf(fmt, 0); + printf(".%s['exc_info'] != None:\n", callback_name.c_str()); + print_indent(indent, " exc_info = "); + printf(fmt, 0); + printf(".%s['exc_info'][0]\n", callback_name.c_str()); + print_indent(indent, " "); + printf(fmt, 0); + printf(".%s['exc_info'][0] = None\n", callback_name.c_str()); + print_rethrow(indent + 4, "exc_info"); } } /* Print the return statement of the python method corresponding - * to the C function "method". + * to the C function "method" with the given indentation. + * If the object on which the method was called + * may have a persistent callback, then first check if any of those failed. + * "fmt" is the format for printing Python method arguments. * + * If the method returns a new instance of the same object type and + * if the class has any persistent callbacks, then the data + * for these callbacks are copied from the original to the new object. + * If the method it itself setting a persistent callback, + * then keep track of the constructed C callback (such that it doesn't + * get destroyed) and the data structure that holds the captured exception + * (such that it can be raised again). + * * If the return type is a (const) char *, then convert the result * to a Python string, raising an error on NULL and freeing * the C string if needed. For python 3 compatibility, the string returned * by isl is explicitly decoded as an 'ascii' string. This is correct * as all strings returned by isl are expected to be 'ascii'. * - * If the return type is isl_bool, then convert the result to - * a Python boolean, raising an error on isl_bool_error. + * If the return type is isl_stat, isl_bool or isl_size, then + * raise an error on isl_stat_error, isl_bool_error or isl_size_error. + * In case of isl_bool, the result is converted to + * a Python boolean. + * In case of isl_size, the result is converted to a Python int. */ -void python_generator::print_method_return(FunctionDecl *method) +void python_generator::print_method_return(int indent, const isl_class &clazz, + FunctionDecl *method, const char *fmt) { QualType return_type = method->getReturnType(); + if (!is_static(clazz, method)) + print_persistent_callback_failure_check(indent, clazz, fmt); + if (is_isl_type(return_type)) { string type; type = type2python(extract_type(return_type)); - printf(" return %s(ctx=ctx, ptr=res)\n", type.c_str()); + print_indent(indent, + "obj = %s(ctx=ctx, ptr=res)\n", type.c_str()); + if (is_mutator(clazz, method) && + clazz.has_persistent_callbacks()) + print_indent(indent, "obj.copy_callbacks(arg0)\n"); + if (clazz.persistent_callbacks.count(method)) { + string callback_name; + + callback_name = clazz.persistent_callback_name(method); + print_indent(indent, "obj.%s = { 'func': cb, " + "'exc_info': exc_info }\n", + callback_name.c_str()); + } + print_indent(indent, "return obj\n"); } else if (is_string(return_type)) { - printf(" if res == 0:\n"); - printf(" raise\n"); - printf(" string = " + print_indent(indent, "if res == 0:\n"); + print_indent(indent, " raise\n"); + print_indent(indent, "string = " "cast(res, c_char_p).value.decode('ascii')\n"); if (gives(method)) - printf(" libc.free(res)\n"); + print_indent(indent, "libc.free(res)\n"); + + print_indent(indent, "return string\n"); + } else if (is_isl_neg_error(return_type)) { + print_indent(indent, "if res < 0:\n"); + print_indent(indent, " raise\n"); + if (is_isl_bool(return_type)) + print_indent(indent, "return bool(res)\n"); + else if (is_isl_size(return_type)) + print_indent(indent, "return int(res)\n"); + } else { + print_indent(indent, "return res\n"); + } +} - printf(" return string\n"); - } else if (is_isl_bool(return_type)) { - printf(" if res < 0:\n"); - printf(" raise\n"); - printf(" return bool(res)\n"); +/* Print a python "get" method corresponding to the C function "fd" + * in class "clazz" using a name that includes the "get_" prefix. + * + * This method simply calls the variant without the "get_" prefix and + * returns its result. + * Note that static methods are not considered to be "get" methods. + */ +void python_generator::print_get_method(const isl_class &clazz, + FunctionDecl *fd) +{ + string get_name = clazz.base_method_name(fd); + string name = clazz.method_name(fd); + int num_params = fd->getNumParams(); + + print_method_header(false, get_name, num_params); + printf(" return arg0.%s(", name.c_str()); + print_method_arguments(1, num_params); + printf(")\n"); +} + +/* Print a call to "method", along with the corresponding + * return statement, with the given indentation. + * "drop_ctx" is set if the first argument is an isl_ctx. + * "drop_user" is set if the last argument is a "user" argument + * corresponding to a callback argument. + * + * A "ctx" variable is first initialized as it may be needed + * in the first call to print_arg_in_call and in print_method_return. + * + * If the method has a callback function, then any exception + * thrown in the callback also need to be rethrown. + */ +void python_generator::print_method_call(int indent, const isl_class &clazz, + FunctionDecl *method, const char *fmt, int drop_ctx, int drop_user) +{ + string fullname = method->getName(); + int num_params = method->getNumParams(); + + if (drop_ctx) { + print_indent(indent, "ctx = Context.getDefaultInstance()\n"); } else { - printf(" return res\n"); + print_indent(indent, "ctx = "); + printf(fmt, 0); + printf(".ctx\n"); } + print_indent(indent, "res = isl.%s(", fullname.c_str()); + for (int i = 0; i < num_params - drop_user; ++i) { + if (i > 0) + printf(", "); + print_arg_in_call(method, fmt, i, drop_ctx); + } + if (drop_user) + printf(", None"); + printf(")\n"); + + if (drop_user) + print_rethrow(indent, "exc_info[0]"); + + print_method_return(indent, clazz, method, fmt); } /* Print a python method corresponding to the C function "method". @@ -241,22 +513,17 @@ * a user argument in the Python interface, so we simply drop it. * We also create a wrapper ("cb") for the callback. * - * For each argument of the function that refers to an isl structure, - * including the object on which the method is called, - * we check if the corresponding actual argument is of the right type. - * If not, we try to convert it to the right type. - * If that doesn't work and if "super" contains at least one element, we try - * to convert self to the type of the first superclass in "super" and - * call the corresponding method. - * * If the function consumes a reference, then we pass it a copy of * the actual argument. + * + * For methods that are identified as "get" methods, also + * print a variant of the method using a name that includes + * the "get_" prefix. */ void python_generator::print_method(const isl_class &clazz, FunctionDecl *method, vector super) { - string fullname = method->getName(); - string cname = fullname.substr(clazz.name.length() + 1); + string cname = clazz.method_name(method); int num_params = method->getNumParams(); int drop_user = 0; int drop_ctx = first_arg_is_isl_ctx(method); @@ -271,54 +538,98 @@ print_method_header(is_static(clazz, method), cname, num_params - drop_ctx - drop_user); - for (int i = drop_ctx; i < num_params; ++i) { - ParmVarDecl *param = method->getParamDecl(i); - string type; - if (!is_isl_type(param->getOriginalType())) - continue; - type = type2python(extract_type(param->getOriginalType())); - if (!drop_ctx && i > 0 && super.size() > 0) - print_type_check(type, i - drop_ctx, true, super[0], - cname, num_params - drop_user); - else - print_type_check(type, i - drop_ctx, false, "", - cname, -1); - } + print_type_checks(cname, method, drop_ctx, + num_params - drop_user, super); for (int i = 1; i < num_params; ++i) { ParmVarDecl *param = method->getParamDecl(i); QualType type = param->getOriginalType(); if (!is_callback(type)) continue; - print_callback(type->getPointeeType(), i - drop_ctx); + print_callback(param, i - drop_ctx); } - if (drop_ctx) - printf(" ctx = Context.getDefaultInstance()\n"); - else - printf(" ctx = arg0.ctx\n"); - printf(" res = isl.%s(", fullname.c_str()); - if (drop_ctx) - printf("ctx"); - else - print_arg_in_call(method, 0, 0); - for (int i = 1; i < num_params - drop_user; ++i) { - printf(", "); - print_arg_in_call(method, i, drop_ctx); + print_method_call(8, clazz, method, fixed_arg_fmt, drop_ctx, drop_user); + + if (clazz.is_get_method(method)) + print_get_method(clazz, method); +} + +/* Print a condition that checks whether Python method argument "i" + * corresponds to the C function argument type "type". + */ +static void print_argument_check(QualType type, int i) +{ + if (generator::is_isl_type(type)) { + string type_str; + type_str = generator::extract_type(type); + type_str = type2python(type_str); + printf("args[%d].__class__ is %s", i, type_str.c_str()); + } else if (type->isPointerType()) { + printf("type(args[%d]) == str", i); + } else { + printf("type(args[%d]) == int", i); } - if (drop_user) - printf(", None"); - printf(")\n"); +} + +/* Print a test that checks whether the arguments passed + * to the Python method correspond to the arguments + * expected by "fd". + * "drop_ctx" is set if the first argument of "fd" is an isl_ctx, + * which does not appear as an argument to the Python method. + * + * If an automatic conversion function is available for any + * of the argument types, then also allow the argument + * to be of the type as prescribed by the second input argument + * of the conversion function. + * The corresponding arguments are then converted to the expected types + * if needed. The argument tuple first needs to be converted to a list + * in order to be able to modify the entries. + */ +void python_generator::print_argument_checks(const isl_class &clazz, + FunctionDecl *fd, int drop_ctx) +{ + int num_params = fd->getNumParams(); + int first = generator::is_static(clazz, fd) ? drop_ctx : 1; + std::vector convert(num_params); - if (drop_user) { - printf(" if exc_info[0] != None:\n"); - printf(" raise (exc_info[0][0], " - "exc_info[0][1], exc_info[0][2])\n"); + printf(" if len(args) == %d", num_params - drop_ctx); + for (int i = first; i < num_params; ++i) { + ParmVarDecl *param = fd->getParamDecl(i); + QualType type = param->getOriginalType(); + const Type *ptr = type.getTypePtr(); + + printf(" and "); + if (conversions.count(ptr) == 0) { + print_argument_check(type, i - drop_ctx); + } else { + QualType type2 = conversions.at(ptr)->getOriginalType(); + convert[i] = true; + printf("("); + print_argument_check(type, i - drop_ctx); + printf(" or "); + print_argument_check(type2, i - drop_ctx); + printf(")"); + } } + printf(":\n"); + + if (std::find(convert.begin(), convert.end(), true) == convert.end()) + return; + print_indent(12, "args = list(args)\n"); + for (int i = first; i < num_params; ++i) { + ParmVarDecl *param = fd->getParamDecl(i); + string type; - print_method_return(method); + if (!convert[i]) + continue; + type = type2python(extract_type(param->getOriginalType())); + print_type_check(12, type, var_arg_fmt, + i - drop_ctx, false, "", "", -1); + } } /* Print part of an overloaded python method corresponding to the C function * "method". + * "drop_ctx" is set if the first argument of "method" is an isl_ctx. * * In particular, print code to test whether the arguments passed to * the python method correspond to the arguments expected by "method" @@ -327,36 +638,10 @@ void python_generator::print_method_overload(const isl_class &clazz, FunctionDecl *method) { - string fullname = method->getName(); - int num_params = method->getNumParams(); - int first; - string type; - - first = is_static(clazz, method) ? 0 : 1; + int drop_ctx = first_arg_is_isl_ctx(method); - printf(" if "); - for (int i = first; i < num_params; ++i) { - if (i > first) - printf(" and "); - ParmVarDecl *param = method->getParamDecl(i); - if (is_isl_type(param->getOriginalType())) { - string type; - type = extract_type(param->getOriginalType()); - type = type2python(type); - printf("arg%d.__class__ is %s", i, type.c_str()); - } else - printf("type(arg%d) == str", i); - } - printf(":\n"); - printf(" res = isl.%s(", fullname.c_str()); - print_arg_in_call(method, 0, 0); - for (int i = 1; i < num_params; ++i) { - printf(", "); - print_arg_in_call(method, i, 0); - } - printf(")\n"); - type = type2python(extract_type(method->getReturnType())); - printf(" return %s(ctx=arg0.ctx, ptr=res)\n", type.c_str()); + print_argument_checks(clazz, method, drop_ctx); + print_method_call(12, clazz, method, var_arg_fmt, drop_ctx, 0); } /* Print a python method with a name derived from "fullname" @@ -369,12 +654,11 @@ * to each function in "methods". */ void python_generator::print_method(const isl_class &clazz, - const string &fullname, const set &methods, + const string &fullname, const function_set &methods, vector super) { string cname; - set::const_iterator it; - int num_params; + function_set::const_iterator it; FunctionDecl *any_method; any_method = *methods.begin(); @@ -383,13 +667,66 @@ return; } - cname = fullname.substr(clazz.name.length() + 1); - num_params = any_method->getNumParams(); + cname = clazz.method_name(any_method); - print_method_header(is_static(clazz, any_method), cname, num_params); + print_method_def(is_static(clazz, any_method), cname); + printf("(*args):\n"); for (it = methods.begin(); it != methods.end(); ++it) print_method_overload(clazz, *it); + printf(" raise Error\n"); +} + +/* Print a python method "name" corresponding to "fd" setting + * the enum value "value". + * "super" contains the superclasses of the class to which the method belongs, + * with the first element corresponding to the annotation that appears + * closest to the annotated type. + * + * The last argument of the C function does not appear in the method call, + * but is fixed to "value" instead. + * Other than that, the method printed here is similar to one + * printed by python_generator::print_method, except that + * some of the special cases do not occur. + */ +void python_generator::print_set_enum(const isl_class &clazz, + FunctionDecl *fd, int value, const string &name, + const vector &super) +{ + string fullname = fd->getName(); + int num_params = fd->getNumParams(); + + print_method_header(is_static(clazz, fd), name, num_params - 1); + + print_type_checks(name, fd, false, num_params - 1, super); + printf(" ctx = arg0.ctx\n"); + printf(" res = isl.%s(", fullname.c_str()); + for (int i = 0; i < num_params - 1; ++i) { + if (i) + printf(", "); + print_arg_in_call(fd, fixed_arg_fmt, i, 0); + } + printf(", %d", value); + printf(")\n"); + print_method_return(8, clazz, fd, fixed_arg_fmt); +} + +/* Print python methods corresponding to "fd", which sets an enum. + * "super" contains the superclasses of the class to which the method belongs, + * with the first element corresponding to the annotation that appears + * closest to the annotated type. + * + * A method is generated for each value in the enum, setting + * the enum to that value. + */ +void python_generator::print_set_enum(const isl_class &clazz, + FunctionDecl *fd, const vector &super) +{ + vector::const_iterator it; + const vector &set_enums = clazz.set_enums.at(fd); + + for (it = set_enums.begin(); it != set_enums.end(); ++it) + print_set_enum(clazz, fd, it->value, it->method_name, super); } /* Print part of the constructor for this isl_class. @@ -397,68 +734,57 @@ * In particular, check if the actual arguments correspond to the * formal arguments of "cons" and if so call "cons" and put the * result in self.ptr and a reference to the default context in self.ctx. - * - * If the function consumes a reference, then we pass it a copy of - * the actual argument. - * - * If the function takes a string argument, the python string is first - * encoded as a byte sequence, using 'ascii' as encoding. This assumes - * that all strings passed to isl can be converted to 'ascii'. */ void python_generator::print_constructor(const isl_class &clazz, FunctionDecl *cons) { string fullname = cons->getName(); - string cname = fullname.substr(clazz.name.length() + 1); + string cname = clazz.method_name(cons); int num_params = cons->getNumParams(); int drop_ctx = first_arg_is_isl_ctx(cons); - printf(" if len(args) == %d", num_params - drop_ctx); - for (int i = drop_ctx; i < num_params; ++i) { - ParmVarDecl *param = cons->getParamDecl(i); - QualType type = param->getOriginalType(); - if (is_isl_type(type)) { - string s; - s = type2python(extract_type(type)); - printf(" and args[%d].__class__ is %s", - i - drop_ctx, s.c_str()); - } else if (type->isPointerType()) { - printf(" and type(args[%d]) == str", i - drop_ctx); - } else { - printf(" and type(args[%d]) == int", i - drop_ctx); - } - } - printf(":\n"); + print_argument_checks(clazz, cons, drop_ctx); printf(" self.ctx = Context.getDefaultInstance()\n"); printf(" self.ptr = isl.%s(", fullname.c_str()); if (drop_ctx) printf("self.ctx"); for (int i = drop_ctx; i < num_params; ++i) { - ParmVarDecl *param = cons->getParamDecl(i); - QualType type = param->getOriginalType(); if (i) printf(", "); - if (is_isl_type(type)) { - if (takes(param)) { - string type; - type = extract_type(param->getOriginalType()); - printf("isl.%s_copy(args[%d].ptr)", - type.c_str(), i - drop_ctx); - } else - printf("args[%d].ptr", i - drop_ctx); - } else if (is_string(type)) { - printf("args[%d].encode('ascii')", i - drop_ctx); - } else { - printf("args[%d]", i - drop_ctx); - } + print_arg_in_call(cons, var_arg_fmt, i, drop_ctx); } printf(")\n"); printf(" return\n"); +} + +/* If "clazz" has a type function describing subclasses, + * then add constructors that allow each of these subclasses + * to be treated as an object to the superclass. + */ +void python_generator::print_upcast_constructors(const isl_class &clazz) +{ + map::const_iterator i; + + if (!clazz.fn_type) + return; + + for (i = clazz.type_subclasses.begin(); + i != clazz.type_subclasses.end(); ++i) { + printf(" if len(args) == 1 and " + "isinstance(args[0], %s):\n", + type2python(i->second).c_str()); + printf(" self.ctx = args[0].ctx\n"); + printf(" self.ptr = isl.%s_copy(args[0].ptr)\n", + clazz.name.c_str()); + printf(" return\n"); + } } /* Print the header of the class "name" with superclasses "super". * The order of the superclasses is the opposite of the order * in which the corresponding annotations appear in the source code. + * If "clazz" is a subclass derived from a type function, + * then the immediate superclass is recorded in "clazz" itself. */ void python_generator::print_class_header(const isl_class &clazz, const string &name, const vector &super) @@ -472,6 +798,8 @@ printf("%s", type2python(super[i]).c_str()); } printf(")"); + } else if (clazz.is_type_subclass()) { + printf("(%s)", type2python(clazz.superclass_name).c_str()); } else { printf("(object)"); } @@ -481,9 +809,11 @@ /* Tell ctypes about the return type of "fd". * In particular, if "fd" returns a pointer to an isl object, * then tell ctypes it returns a "c_void_p". - * Similarly, if "fd" returns an isl_bool, - * then tell ctypes it returns a "c_bool". * If "fd" returns a char *, then simply tell ctypes. + * + * Nothing needs to be done for functions returning + * isl_bool, isl_stat or isl_size since they are represented by an int and + * ctypes assumes that a function returns int by default. */ void python_generator::print_restype(FunctionDecl *fd) { @@ -491,8 +821,6 @@ QualType type = fd->getReturnType(); if (is_isl_type(type)) printf("isl.%s.restype = c_void_p\n", fullname.c_str()); - else if (is_isl_bool(type)) - printf("isl.%s.restype = c_bool\n", fullname.c_str()); else if (is_string(type)) printf("isl.%s.restype = POINTER(c_char)\n", fullname.c_str()); } @@ -535,6 +863,41 @@ { print_restype(fd); print_argtypes(fd); +} + +/* If "clazz" has a type function describing subclasses or + * if it is one of those type subclasses, then print a __new__ method. + * + * In the superclass, the __new__ method constructs an object + * of the subclass type specified by the type function. + * In the subclass, the __new__ method reverts to the original behavior. + */ +void python_generator::print_new(const isl_class &clazz, + const string &python_name) +{ + if (!clazz.fn_type && !clazz.is_type_subclass()) + return; + + printf(" def __new__(cls, *args, **keywords):\n"); + + if (clazz.fn_type) { + map::const_iterator i; + + printf(" if \"ptr\" in keywords:\n"); + printf(" type = isl.%s(keywords[\"ptr\"])\n", + clazz.fn_type->getNameAsString().c_str()); + + for (i = clazz.type_subclasses.begin(); + i != clazz.type_subclasses.end(); ++i) { + printf(" if type == %d:\n", i->first); + printf(" return %s(**keywords)\n", + type2python(i->second).c_str()); + } + printf(" raise\n"); + } + + printf(" return super(%s, cls).__new__(cls)\n", + python_name.c_str()); } /* Print declarations for methods printing the class representation, @@ -559,7 +922,7 @@ return; printf(" def __str__(arg0):\n"); - print_type_check(python_name, 0, false, "", "", -1); + print_type_check(8, python_name, fixed_arg_fmt, 0, false, "", "", -1); printf(" ptr = isl.%s(arg0.ptr)\n", string(clazz.fn_to_str->getName()).c_str()); printf(" res = cast(ptr, c_char_p).value.decode('ascii')\n"); @@ -573,33 +936,66 @@ printf(" else:\n"); printf(" return 'isl.%s(\"%%s\")' %% s\n", python_name.c_str()); +} + +/* If "clazz" has any persistent callbacks, then print the definition + * of a "copy_callbacks" function that copies the persistent callbacks + * from one object to another. + */ +void python_generator::print_copy_callbacks(const isl_class &clazz) +{ + const set &callbacks = clazz.persistent_callbacks; + set::const_iterator in; + + if (!clazz.has_persistent_callbacks()) + return; + + printf(" def copy_callbacks(self, obj):\n"); + for (in = callbacks.begin(); in != callbacks.end(); ++in) { + string callback_name = clazz.persistent_callback_name(*in); + + printf(" if hasattr(obj, '%s'):\n", + callback_name.c_str()); + printf(" self.%s = obj.%s\n", + callback_name.c_str(), callback_name.c_str()); + } } /* Print code to set method type signatures. * * To be able to call C functions it is necessary to explicitly set their * argument and result types. Do this for all exported constructors and - * methods, as well as for the *_to_str method, if it exists. + * methods (including those that set a persistent callback and + * those that set an enum value), + * as well as for the *_to_str and the type function, if they exist. * Assuming each exported class has a *_copy and a *_free method, * also unconditionally set the type of such methods. */ void python_generator::print_method_types(const isl_class &clazz) { - set::const_iterator in; - map >::const_iterator it; + function_set::const_iterator in; + map::const_iterator it; + map >::const_iterator ie; + const set &callbacks = clazz.persistent_callbacks; for (in = clazz.constructors.begin(); in != clazz.constructors.end(); ++in) print_method_type(*in); + for (in = callbacks.begin(); in != callbacks.end(); ++in) + print_method_type(*in); for (it = clazz.methods.begin(); it != clazz.methods.end(); ++it) for (in = it->second.begin(); in != it->second.end(); ++in) print_method_type(*in); + for (ie = clazz.set_enums.begin(); ie != clazz.set_enums.end(); ++ie) + print_method_type(ie->first); print_method_type(clazz.fn_copy); print_method_type(clazz.fn_free); if (clazz.fn_to_str) print_method_type(clazz.fn_to_str); + if (clazz.fn_type) + print_method_type(clazz.fn_type); } /* Print out the definition of this isl_class. @@ -608,11 +1004,12 @@ * If it is, we make sure those superclasses are printed out first. * * Then we print a constructor with several cases, one for constructing - * a Python object from a return value and one for each function that - * was marked as a constructor. + * a Python object from a return value, one for each function that + * was marked as a constructor and for each type based subclass. * * Next, we print out some common methods and the methods corresponding - * to functions that are not marked as constructors. + * to functions that are not marked as constructors, including those + * that set a persistent callback and those that set an enum value. * * Finally, we tell ctypes about the types of the arguments of the * constructor functions and the return types of those function returning @@ -620,15 +1017,19 @@ */ void python_generator::print(const isl_class &clazz) { - string p_name = type2python(clazz.name); - set::const_iterator in; - map >::const_iterator it; + string p_name = type2python(clazz.subclass_name); + function_set::const_iterator in; + map::const_iterator it; + map >::const_iterator ie; vector super = find_superclasses(clazz.type); + const set &callbacks = clazz.persistent_callbacks; for (unsigned i = 0; i < super.size(); ++i) if (done.find(super[i]) == done.end()) print(classes[super[i]]); - done.insert(clazz.name); + if (clazz.is_type_subclass() && done.find(clazz.name) == done.end()) + print(classes[clazz.name]); + done.insert(clazz.subclass_name); printf("\n"); print_class_header(clazz, p_name, super); @@ -642,15 +1043,22 @@ for (in = clazz.constructors.begin(); in != clazz.constructors.end(); ++in) print_constructor(clazz, *in); + print_upcast_constructors(clazz); printf(" raise Error\n"); printf(" def __del__(self):\n"); printf(" if hasattr(self, 'ptr'):\n"); printf(" isl.%s_free(self.ptr)\n", clazz.name.c_str()); + print_new(clazz, p_name); print_representation(clazz, p_name); + print_copy_callbacks(clazz); + for (in = callbacks.begin(); in != callbacks.end(); ++in) + print_method(clazz, *in, super); for (it = clazz.methods.begin(); it != clazz.methods.end(); ++it) print_method(clazz, it->first, it->second, super); + for (ie = clazz.set_enums.begin(); ie != clazz.set_enums.end(); ++ie) + print_set_enum(clazz, ie->first, super); printf("\n"); diff --git a/gcc/isl/interface/python.h b/gcc/isl/interface/python.h index 554e52f..e56c23d 100644 --- a/gcc/isl/interface/python.h +++ a/gcc/isl/interface/python.h @@ -10,36 +10,57 @@ set done; public: - python_generator(set &exported_types, + python_generator(SourceManager &SM, set &exported_types, set exported_functions, set functions) : - generator(exported_types, exported_functions, functions) {} + generator(SM, exported_types, exported_functions, functions) {} virtual void generate(); private: void print(const isl_class &clazz); + void print_method_arguments(int first, int n_arg); void print_method_header(bool is_static, const string &name, int n_arg); void print_class_header(const isl_class &clazz, const string &name, const vector &super); - void print_type_check(const string &type, int pos, bool upcast, - const string &super, const string &name, int n); - void print_callback(QualType type, int arg); - void print_arg_in_call(FunctionDecl *fd, int arg, int skip); + void print_type_check(int indent, const string &type, const char *fmt, + int pos, bool upcast, const string &super, + const string &name, int n); + void print_type_checks(const string &cname, FunctionDecl *method, + bool first_is_ctx, int n, const vector &super); + void print_copy(QualType type); + void print_callback(ParmVarDecl *param, int arg); + void print_arg_in_call(FunctionDecl *fd, const char *fmt, int arg, + int skip); void print_argtypes(FunctionDecl *fd); - void print_method_return(FunctionDecl *method); + void print_method_return(int indent, const isl_class &clazz, + FunctionDecl *method, const char *fmt); void print_restype(FunctionDecl *fd); void print(map &classes, set &done); void print_constructor(const isl_class &clazz, FunctionDecl *method); + void print_upcast_constructors(const isl_class &clazz); + void print_new(const isl_class &clazz, + const string &python_name); void print_representation(const isl_class &clazz, const string &python_name); + void print_copy_callbacks(const isl_class &clazz); void print_method_type(FunctionDecl *fd); void print_method_types(const isl_class &clazz); + void print_get_method(const isl_class &clazz, FunctionDecl *fd); void print_method(const isl_class &clazz, FunctionDecl *method, vector super); + void print_method_call(int indent, const isl_class &clazz, + FunctionDecl *method, const char *fmt, + int drop_ctx, int drop_user); + void print_argument_checks(const isl_class &clazz, FunctionDecl *fd, + int drop_ctx); void print_method_overload(const isl_class &clazz, FunctionDecl *method); void print_method(const isl_class &clazz, const string &fullname, - const set &methods, vector super); + const function_set &methods, vector super); + void print_set_enum(const isl_class &clazz, FunctionDecl *fd, + int value, const string &name, const vector &super); + void print_set_enum(const isl_class &clazz, FunctionDecl *fd, + const vector &super); }; diff --git a/gcc/isl/m4/ax_detect_clang.m4 b/gcc/isl/m4/ax_detect_clang.m4 index d3021e0..0a9f296 100644 --- a/gcc/isl/m4/ax_detect_clang.m4 +++ a/gcc/isl/m4/ax_detect_clang.m4 @@ -1,6 +1,7 @@ AC_DEFUN([AX_DETECT_CLANG], [ AC_SUBST(CLANG_CXXFLAGS) AC_SUBST(CLANG_LDFLAGS) +AC_SUBST(CLANG_RFLAG) AC_SUBST(CLANG_LIBS) AC_PROG_GREP AC_PROG_SED @@ -18,6 +19,9 @@ CLANG_CXXFLAGS=`$llvm_config --cxxflags | \ $SED -e 's/-Wcovered-switch-default//;s/-gsplit-dwarf//'` CLANG_LDFLAGS=`$llvm_config --ldflags` +# Construct a -R argument for libtool. +# This is needed in case some of the clang libraries are shared libraries. +CLANG_RFLAG=`echo "$CLANG_LDFLAGS" | $SED -e 's/-L/-R/g'` targets=`$llvm_config --targets-built` components="$targets asmparser bitreader support mc" $llvm_config --components | $GREP option > /dev/null 2> /dev/null @@ -43,12 +47,25 @@ AC_EGREP_HEADER([getExpansionLineNumber], [clang/Basic/SourceLocation.h], [], [AC_DEFINE([getExpansionLineNumber], [getInstantiationLineNumber], [Define to getInstantiationLineNumber for older versions of clang])]) +AC_EGREP_HEADER([getImmediateExpansionRange], [clang/Basic/SourceManager.h], + [], + [AC_DEFINE([getImmediateExpansionRange], + [getImmediateInstantiationRange], + [Define to getImmediateInstantiationRange for older versions of clang])] +) AC_EGREP_HEADER([DiagnosticsEngine], [clang/Basic/Diagnostic.h], [], [AC_DEFINE([DiagnosticsEngine], [Diagnostic], [Define to Diagnostic for older versions of clang])]) AC_EGREP_HEADER([ArrayRef], [clang/Driver/Driver.h], [AC_DEFINE([USE_ARRAYREF], [], - [Define if Driver::BuildCompilation takes ArrayRef])]) + [Define if Driver::BuildCompilation takes ArrayRef]) + AC_EGREP_HEADER([ArrayRef.*CommandLineArgs], + [clang/Frontend/CompilerInvocation.h], + [AC_DEFINE([CREATE_FROM_ARGS_TAKES_ARRAYREF], [], + [Define if CompilerInvocation::CreateFromArgs takes + ArrayRef]) + ]) + ]) AC_EGREP_HEADER([CXXIsProduction], [clang/Driver/Driver.h], [AC_DEFINE([HAVE_CXXISPRODUCTION], [], [Define if Driver constructor takes CXXIsProduction argument])]) @@ -131,8 +148,11 @@ [AC_DEFINE([initializeBuiltins], [InitializeBuiltins], [Define to InitializeBuiltins for older versions of clang])]) AC_EGREP_HEADER([IK_C], [clang/Frontend/FrontendOptions.h], [], - [AC_DEFINE([IK_C], [InputKind::C], - [Define to InputKind::C for newer versions of clang])]) + [AC_CHECK_HEADER([clang/Basic/LangStandard.h], + [IK_C=Language::C], [IK_C=InputKind::C]) + AC_DEFINE_UNQUOTED([IK_C], [$IK_C], + [Define to Language::C or InputKind::C for newer versions of clang]) + ]) AC_TRY_COMPILE([ #include #include @@ -157,6 +177,9 @@ Clang->setInvocation(std::make_shared(*invocation)); ], [AC_DEFINE([SETINVOCATION_TAKES_SHARED_PTR], [], [Defined if CompilerInstance::setInvocation takes a shared_ptr])]) +AC_CHECK_HEADER([llvm/Option/Arg.h], + [AC_DEFINE([HAVE_LLVM_OPTION_ARG_H], [], + [Define if llvm/Option/Arg.h exists])]) AC_LANG_POP CPPFLAGS="$SAVE_CPPFLAGS" diff --git a/gcc/isl/include/isl/aff.h b/gcc/isl/include/isl/aff.h index fd7c89d..1cca68d 100644 --- a/gcc/isl/include/isl/aff.h +++ a/gcc/isl/include/isl/aff.h @@ -1,20 +1,25 @@ #ifndef ISL_AFF_H #define ISL_AFF_H +#include #include #include +#include #include #include #include #include #include -#include +#include +#include #if defined(__cplusplus) extern "C" { #endif __isl_give isl_aff *isl_aff_zero_on_domain(__isl_take isl_local_space *ls); +__isl_give isl_aff *isl_aff_val_on_domain_space(__isl_take isl_space *space, + __isl_take isl_val *val); __isl_give isl_aff *isl_aff_val_on_domain(__isl_take isl_local_space *ls, __isl_take isl_val *val); __isl_give isl_aff *isl_aff_var_on_domain(__isl_take isl_local_space *ls, @@ -29,7 +34,9 @@ isl_ctx *isl_aff_get_ctx(__isl_keep isl_aff *aff); uint32_t isl_aff_get_hash(__isl_keep isl_aff *aff); -int isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type); +isl_bool isl_aff_involves_locals(__isl_keep isl_aff *aff); + +isl_size isl_aff_dim(__isl_keep isl_aff *aff, enum isl_dim_type type); isl_bool isl_aff_involves_dims(__isl_keep isl_aff *aff, enum isl_dim_type type, unsigned first, unsigned n); @@ -55,6 +62,7 @@ __isl_give isl_aff *isl_aff_set_coefficient_val(__isl_take isl_aff *aff, enum isl_dim_type type, int pos, __isl_take isl_val *v); __isl_give isl_aff *isl_aff_add_constant_si(__isl_take isl_aff *aff, int v); +__isl_overload __isl_give isl_aff *isl_aff_add_constant_val(__isl_take isl_aff *aff, __isl_take isl_val *v); __isl_give isl_aff *isl_aff_add_constant_num_si(__isl_take isl_aff *aff, int v); @@ -125,14 +133,22 @@ __isl_give isl_aff *isl_aff_drop_dims(__isl_take isl_aff *aff, enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_aff *isl_aff_project_domain_on_params(__isl_take isl_aff *aff); +__isl_export +__isl_give isl_aff *isl_aff_unbind_params_insert_domain( + __isl_take isl_aff *aff, __isl_take isl_multi_id *domain); __isl_give isl_aff *isl_aff_align_params(__isl_take isl_aff *aff, __isl_take isl_space *model); +__isl_export __isl_give isl_aff *isl_aff_gist(__isl_take isl_aff *aff, __isl_take isl_set *context); __isl_give isl_aff *isl_aff_gist_params(__isl_take isl_aff *aff, __isl_take isl_set *context); + +__isl_export +__isl_give isl_val *isl_aff_eval(__isl_take isl_aff *aff, + __isl_take isl_point *pnt); __isl_give isl_aff *isl_aff_pullback_aff(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2); @@ -171,6 +187,10 @@ __isl_export __isl_give isl_set *isl_aff_gt_set(__isl_take isl_aff *aff1, __isl_take isl_aff *aff2); + +__isl_overload +__isl_give isl_basic_set *isl_aff_bind_id(__isl_take isl_aff *aff, + __isl_take isl_id *id); __isl_constructor __isl_give isl_aff *isl_aff_read_from_str(isl_ctx *ctx, const char *str); @@ -186,7 +206,7 @@ __isl_constructor __isl_give isl_pw_aff *isl_pw_aff_from_aff(__isl_take isl_aff *aff); -__isl_give isl_pw_aff *isl_pw_aff_empty(__isl_take isl_space *dim); +__isl_give isl_pw_aff *isl_pw_aff_empty(__isl_take isl_space *space); __isl_give isl_pw_aff *isl_pw_aff_alloc(__isl_take isl_set *set, __isl_take isl_aff *aff); __isl_give isl_pw_aff *isl_pw_aff_zero_on_domain( @@ -196,6 +216,9 @@ __isl_give isl_pw_aff *isl_pw_aff_nan_on_domain(__isl_take isl_local_space *ls); __isl_give isl_pw_aff *isl_pw_aff_val_on_domain(__isl_take isl_set *domain, __isl_take isl_val *v); +__isl_overload +__isl_give isl_pw_aff *isl_pw_aff_param_on_domain_id( + __isl_take isl_set *domain, __isl_take isl_id *id); __isl_give isl_pw_aff *isl_set_indicator_function(__isl_take isl_set *set); @@ -231,7 +254,9 @@ __isl_give isl_pw_aff *isl_pw_aff_copy(__isl_keep isl_pw_aff *pwaff); __isl_null isl_pw_aff *isl_pw_aff_free(__isl_take isl_pw_aff *pwaff); -unsigned isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type); +isl_size isl_pw_aff_dim(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type); +isl_bool isl_pw_aff_involves_param_id(__isl_keep isl_pw_aff *pa, + __isl_keep isl_id *id); isl_bool isl_pw_aff_involves_dims(__isl_keep isl_pw_aff *pwaff, enum isl_dim_type type, unsigned first, unsigned n); @@ -242,6 +267,8 @@ __isl_give isl_pw_aff *isl_pw_aff_align_params(__isl_take isl_pw_aff *pwaff, __isl_take isl_space *model); +__isl_give isl_pw_aff *isl_pw_aff_drop_unused_params( + __isl_take isl_pw_aff *pa); isl_bool isl_pw_aff_has_tuple_id(__isl_keep isl_pw_aff *pa, enum isl_dim_type type); @@ -254,6 +281,7 @@ __isl_give isl_pw_aff *isl_pw_aff_reset_user(__isl_take isl_pw_aff *pa); __isl_give isl_set *isl_pw_aff_params(__isl_take isl_pw_aff *pwa); +__isl_export __isl_give isl_set *isl_pw_aff_domain(__isl_take isl_pw_aff *pwaff); __isl_give isl_pw_aff *isl_pw_aff_from_range(__isl_take isl_pw_aff *pwa); @@ -291,10 +319,17 @@ __isl_give isl_pw_aff *isl_pw_aff_tdiv_r(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2); +__isl_export __isl_give isl_pw_aff *isl_pw_aff_intersect_params(__isl_take isl_pw_aff *pa, __isl_take isl_set *set); +__isl_export __isl_give isl_pw_aff *isl_pw_aff_intersect_domain(__isl_take isl_pw_aff *pa, __isl_take isl_set *set); +__isl_give isl_pw_aff *isl_pw_aff_intersect_domain_wrapped_domain( + __isl_take isl_pw_aff *pa, __isl_take isl_set *set); +__isl_give isl_pw_aff *isl_pw_aff_intersect_domain_wrapped_range( + __isl_take isl_pw_aff *pa, __isl_take isl_set *set); +__isl_export __isl_give isl_pw_aff *isl_pw_aff_subtract_domain(__isl_take isl_pw_aff *pa, __isl_take isl_set *set); @@ -320,11 +355,16 @@ enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_pw_aff *isl_pw_aff_coalesce(__isl_take isl_pw_aff *pwqp); +__isl_export __isl_give isl_pw_aff *isl_pw_aff_gist(__isl_take isl_pw_aff *pwaff, __isl_take isl_set *context); __isl_give isl_pw_aff *isl_pw_aff_gist_params(__isl_take isl_pw_aff *pwaff, __isl_take isl_set *context); +__isl_export +__isl_give isl_val *isl_pw_aff_eval(__isl_take isl_pw_aff *pa, + __isl_take isl_point *pnt); + __isl_overload __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_aff( __isl_take isl_pw_aff *pa, __isl_take isl_multi_aff *ma); @@ -335,10 +375,14 @@ __isl_give isl_pw_aff *isl_pw_aff_pullback_multi_pw_aff( __isl_take isl_pw_aff *pa, __isl_take isl_multi_pw_aff *mpa); -int isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff); +isl_size isl_pw_aff_n_piece(__isl_keep isl_pw_aff *pwaff); isl_stat isl_pw_aff_foreach_piece(__isl_keep isl_pw_aff *pwaff, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_aff *aff, void *user), void *user); +__isl_export +isl_bool isl_pw_aff_isa_aff(__isl_keep isl_pw_aff *pa); +__isl_export +__isl_give isl_aff *isl_pw_aff_as_aff(__isl_take isl_pw_aff *pa); __isl_give isl_set *isl_set_from_pw_aff(__isl_take isl_pw_aff *pwaff); __isl_give isl_map *isl_map_from_pw_aff(__isl_take isl_pw_aff *pwaff); @@ -374,6 +418,16 @@ __isl_give isl_map *isl_pw_aff_gt_map(__isl_take isl_pw_aff *pa1, __isl_take isl_pw_aff *pa2); +__isl_export +__isl_give isl_pw_aff *isl_pw_aff_bind_domain(__isl_take isl_pw_aff *pa, + __isl_take isl_multi_id *tuple); +__isl_export +__isl_give isl_pw_aff *isl_pw_aff_bind_domain_wrapped_domain( + __isl_take isl_pw_aff *pa, __isl_take isl_multi_id *tuple); +__isl_overload +__isl_give isl_set *isl_pw_aff_bind_id(__isl_take isl_pw_aff *pa, + __isl_take isl_id *id); + __isl_constructor __isl_give isl_pw_aff *isl_pw_aff_read_from_str(isl_ctx *ctx, const char *str); __isl_give char *isl_pw_aff_to_str(__isl_keep isl_pw_aff *pa); @@ -398,15 +452,23 @@ __isl_take isl_pw_aff_list *list2); ISL_DECLARE_MULTI(aff) +ISL_DECLARE_MULTI_IDENTITY(aff) ISL_DECLARE_MULTI_CMP(aff) -ISL_DECLARE_MULTI_NEG(aff) +ISL_DECLARE_MULTI_ARITH(aff) +ISL_DECLARE_MULTI_ZERO(aff) +ISL_DECLARE_MULTI_NAN(aff) ISL_DECLARE_MULTI_DIMS(aff) +ISL_DECLARE_MULTI_LOCALS(aff) +ISL_DECLARE_MULTI_DIM_ID(aff) +ISL_DECLARE_MULTI_TUPLE_ID(aff) ISL_DECLARE_MULTI_WITH_DOMAIN(aff) +ISL_DECLARE_MULTI_BIND_DOMAIN(aff) __isl_constructor __isl_give isl_multi_aff *isl_multi_aff_from_aff(__isl_take isl_aff *aff); -__isl_give isl_multi_aff *isl_multi_aff_identity(__isl_take isl_space *space); +__isl_export __isl_give isl_multi_aff *isl_multi_aff_domain_map(__isl_take isl_space *space); +__isl_export __isl_give isl_multi_aff *isl_multi_aff_range_map(__isl_take isl_space *space); __isl_give isl_multi_aff *isl_multi_aff_project_out_map( __isl_take isl_space *space, enum isl_dim_type type, @@ -415,10 +477,12 @@ __isl_give isl_multi_aff *isl_multi_aff_multi_val_on_space( __isl_take isl_space *space, __isl_take isl_multi_val *mv); +__isl_export __isl_give isl_multi_aff *isl_multi_aff_floor(__isl_take isl_multi_aff *ma); __isl_give isl_multi_aff *isl_multi_aff_gist_params( __isl_take isl_multi_aff *maff, __isl_take isl_set *context); +__isl_export __isl_give isl_multi_aff *isl_multi_aff_gist(__isl_take isl_multi_aff *maff, __isl_take isl_set *context); @@ -441,6 +505,10 @@ __isl_take isl_multi_aff *ma2); __isl_give isl_set *isl_multi_aff_lex_ge_set(__isl_take isl_multi_aff *ma1, __isl_take isl_multi_aff *ma2); + +__isl_export +__isl_give isl_basic_set *isl_multi_aff_bind(__isl_take isl_multi_aff *ma, + __isl_take isl_multi_id *tuple); __isl_give char *isl_multi_aff_to_str(__isl_keep isl_multi_aff *ma); __isl_give isl_printer *isl_printer_print_multi_aff(__isl_take isl_printer *p, @@ -452,10 +520,18 @@ void isl_multi_aff_dump(__isl_keep isl_multi_aff *maff); ISL_DECLARE_MULTI(pw_aff) -ISL_DECLARE_MULTI_NEG(pw_aff) +ISL_DECLARE_MULTI_IDENTITY(pw_aff) +ISL_DECLARE_MULTI_ARITH(pw_aff) +ISL_DECLARE_MULTI_ZERO(pw_aff) +ISL_DECLARE_MULTI_NAN(pw_aff) ISL_DECLARE_MULTI_DIMS(pw_aff) +ISL_DECLARE_MULTI_DIM_ID(pw_aff) +ISL_DECLARE_MULTI_TUPLE_ID(pw_aff) ISL_DECLARE_MULTI_WITH_DOMAIN(pw_aff) +ISL_DECLARE_MULTI_BIND_DOMAIN(pw_aff) +ISL_DECLARE_MULTI_PARAM(pw_aff) +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_zero(__isl_take isl_space *space); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_identity( __isl_take isl_space *space); @@ -477,8 +553,12 @@ __isl_null isl_pw_multi_aff *isl_pw_multi_aff_free( __isl_take isl_pw_multi_aff *pma); -unsigned isl_pw_multi_aff_dim(__isl_keep isl_pw_multi_aff *pma, +isl_size isl_pw_multi_aff_dim(__isl_keep isl_pw_multi_aff *pma, enum isl_dim_type type); +isl_bool isl_pw_multi_aff_involves_param_id(__isl_keep isl_pw_multi_aff *pma, + __isl_keep isl_id *id); +isl_bool isl_pw_multi_aff_involves_dims(__isl_keep isl_pw_multi_aff *pma, + enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_pw_aff *isl_pw_multi_aff_get_pw_aff( __isl_keep isl_pw_multi_aff *pma, int pos); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_set_pw_aff( @@ -488,6 +568,7 @@ isl_ctx *isl_pw_multi_aff_get_ctx(__isl_keep isl_pw_multi_aff *pma); __isl_give isl_space *isl_pw_multi_aff_get_domain_space( __isl_keep isl_pw_multi_aff *pma); +__isl_export __isl_give isl_space *isl_pw_multi_aff_get_space( __isl_keep isl_pw_multi_aff *pma); isl_bool isl_pw_multi_aff_has_tuple_name(__isl_keep isl_pw_multi_aff *pma, @@ -513,6 +594,7 @@ __isl_take isl_pw_multi_aff *pma, enum isl_dim_type type, unsigned first, unsigned n); +__isl_export __isl_give isl_set *isl_pw_multi_aff_domain(__isl_take isl_pw_multi_aff *pma); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_empty(__isl_take isl_space *space); @@ -551,11 +633,14 @@ __isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_add( __isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2); +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_sub( __isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2); +__isl_overload __isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_val( __isl_take isl_pw_multi_aff *pma, __isl_take isl_val *v); +__isl_overload __isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_down_val( __isl_take isl_pw_multi_aff *pma, __isl_take isl_val *v); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_scale_multi_val( @@ -580,11 +665,24 @@ __isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_product( __isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2); +__isl_export +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_range_factor_domain( + __isl_take isl_pw_multi_aff *pma); +__isl_export +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_range_factor_range( + __isl_take isl_pw_multi_aff *pma); +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_params( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_domain( + __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_domain_wrapped_domain( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_intersect_domain_wrapped_range( + __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_subtract_domain( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); @@ -593,11 +691,14 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_align_params( __isl_take isl_pw_multi_aff *pma, __isl_take isl_space *model); +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_drop_unused_params( + __isl_take isl_pw_multi_aff *pma); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_coalesce( __isl_take isl_pw_multi_aff *pma); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist_params( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); +__isl_export __isl_give isl_pw_multi_aff *isl_pw_multi_aff_gist( __isl_take isl_pw_multi_aff *pma, __isl_take isl_set *set); @@ -608,10 +709,17 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_pullback_pw_multi_aff( __isl_take isl_pw_multi_aff *pma1, __isl_take isl_pw_multi_aff *pma2); -int isl_pw_multi_aff_n_piece(__isl_keep isl_pw_multi_aff *pma); +__isl_export +isl_size isl_pw_multi_aff_n_piece(__isl_keep isl_pw_multi_aff *pma); +__isl_export isl_stat isl_pw_multi_aff_foreach_piece(__isl_keep isl_pw_multi_aff *pma, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_multi_aff *maff, void *user), void *user); +__isl_export +isl_bool isl_pw_multi_aff_isa_multi_aff(__isl_keep isl_pw_multi_aff *pma); +__isl_export +__isl_give isl_multi_aff *isl_pw_multi_aff_as_multi_aff( + __isl_take isl_pw_multi_aff *pma); __isl_give isl_map *isl_map_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma); __isl_give isl_set *isl_set_from_pw_multi_aff(__isl_take isl_pw_multi_aff *pma); @@ -622,6 +730,13 @@ __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_set(__isl_take isl_set *set); __isl_give isl_pw_multi_aff *isl_pw_multi_aff_from_map(__isl_take isl_map *map); + +__isl_export +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_bind_domain( + __isl_take isl_pw_multi_aff *pma, __isl_take isl_multi_id *tuple); +__isl_export +__isl_give isl_pw_multi_aff *isl_pw_multi_aff_bind_domain_wrapped_domain( + __isl_take isl_pw_multi_aff *pma, __isl_take isl_multi_id *tuple); __isl_constructor __isl_give isl_pw_multi_aff *isl_pw_multi_aff_read_from_str(isl_ctx *ctx, @@ -629,6 +744,11 @@ void isl_pw_multi_aff_dump(__isl_keep isl_pw_multi_aff *pma); +__isl_overload +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_empty_ctx( + isl_ctx *ctx); +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_empty_space( + __isl_take isl_space *space); __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_empty( __isl_take isl_space *space); __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_from_aff( @@ -659,10 +779,13 @@ isl_ctx *isl_union_pw_multi_aff_get_ctx( __isl_keep isl_union_pw_multi_aff *upma); +__isl_export __isl_give isl_space *isl_union_pw_multi_aff_get_space( + __isl_keep isl_union_pw_multi_aff *upma); +__isl_give isl_pw_multi_aff_list *isl_union_pw_multi_aff_get_pw_multi_aff_list( __isl_keep isl_union_pw_multi_aff *upma); -unsigned isl_union_pw_multi_aff_dim(__isl_keep isl_union_pw_multi_aff *upma, +isl_size isl_union_pw_multi_aff_dim(__isl_keep isl_union_pw_multi_aff *upma, enum isl_dim_type type); __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_set_dim_name( __isl_take isl_union_pw_multi_aff *upma, @@ -682,6 +805,7 @@ __isl_take isl_union_pw_multi_aff *upma); __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_gist_params( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_set *context); +__isl_export __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_gist( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_union_set *context); @@ -695,15 +819,22 @@ __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_align_params( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_space *model); -int isl_union_pw_multi_aff_n_pw_multi_aff( +isl_size isl_union_pw_multi_aff_n_pw_multi_aff( __isl_keep isl_union_pw_multi_aff *upma); isl_stat isl_union_pw_multi_aff_foreach_pw_multi_aff( __isl_keep isl_union_pw_multi_aff *upma, isl_stat (*fn)(__isl_take isl_pw_multi_aff *pma, void *user), void *user); +__isl_export __isl_give isl_pw_multi_aff *isl_union_pw_multi_aff_extract_pw_multi_aff( __isl_keep isl_union_pw_multi_aff *upma, __isl_take isl_space *space); +__isl_export +isl_bool isl_union_pw_multi_aff_isa_pw_multi_aff( + __isl_keep isl_union_pw_multi_aff *upma); +__isl_export +__isl_give isl_pw_multi_aff *isl_union_pw_multi_aff_as_pw_multi_aff( + __isl_take isl_union_pw_multi_aff *upma); isl_bool isl_union_pw_multi_aff_involves_nan( __isl_keep isl_union_pw_multi_aff *upma); @@ -711,6 +842,7 @@ __isl_keep isl_union_pw_multi_aff *upma1, __isl_keep isl_union_pw_multi_aff *upma2); +__isl_export __isl_give isl_union_set *isl_union_pw_multi_aff_domain( __isl_take isl_union_pw_multi_aff *upma); @@ -725,6 +857,7 @@ __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_union_add( __isl_take isl_union_pw_multi_aff *upma1, __isl_take isl_union_pw_multi_aff *upma2); +__isl_export __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_sub( __isl_take isl_union_pw_multi_aff *upma1, __isl_take isl_union_pw_multi_aff *upma2); @@ -740,12 +873,31 @@ __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_flat_range_product( __isl_take isl_union_pw_multi_aff *upma1, __isl_take isl_union_pw_multi_aff *upma2); +__isl_export +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_range_factor_domain( + __isl_take isl_union_pw_multi_aff *upma); +__isl_export +__isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_range_factor_range( + __isl_take isl_union_pw_multi_aff *upma); +__isl_export __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_intersect_params( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_set *set); +__isl_export __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_intersect_domain( + __isl_take isl_union_pw_multi_aff *upma, + __isl_take isl_union_set *uset); +__isl_export +__isl_give isl_union_pw_multi_aff * +isl_union_pw_multi_aff_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_multi_aff *upma, + __isl_take isl_union_set *uset); +__isl_export +__isl_give isl_union_pw_multi_aff * +isl_union_pw_multi_aff_intersect_domain_wrapped_range( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_union_set *uset); +__isl_export __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_subtract_domain( __isl_take isl_union_pw_multi_aff *upma, __isl_take isl_union_set *uset); @@ -771,22 +923,24 @@ uint32_t isl_multi_pw_aff_get_hash(__isl_keep isl_multi_pw_aff *mpa); -__isl_give isl_multi_pw_aff *isl_multi_pw_aff_identity( - __isl_take isl_space *space); __isl_constructor __isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_multi_aff( __isl_take isl_multi_aff *ma); __isl_constructor __isl_give isl_multi_pw_aff *isl_multi_pw_aff_from_pw_aff( __isl_take isl_pw_aff *pa); +__isl_export __isl_give isl_set *isl_multi_pw_aff_domain(__isl_take isl_multi_pw_aff *mpa); +__isl_export __isl_give isl_multi_pw_aff *isl_multi_pw_aff_intersect_params( __isl_take isl_multi_pw_aff *mpa, __isl_take isl_set *set); +__isl_export __isl_give isl_multi_pw_aff *isl_multi_pw_aff_intersect_domain( __isl_take isl_multi_pw_aff *mpa, __isl_take isl_set *domain); __isl_give isl_multi_pw_aff *isl_multi_pw_aff_coalesce( __isl_take isl_multi_pw_aff *mpa); +__isl_export __isl_give isl_multi_pw_aff *isl_multi_pw_aff_gist( __isl_take isl_multi_pw_aff *mpa, __isl_take isl_set *set); __isl_give isl_multi_pw_aff *isl_multi_pw_aff_gist_params( @@ -825,6 +979,10 @@ __isl_take isl_multi_pw_aff *mpa1, __isl_take isl_multi_pw_aff *mpa2); __isl_give isl_map *isl_multi_pw_aff_lex_gt_map( __isl_take isl_multi_pw_aff *mpa1, __isl_take isl_multi_pw_aff *mpa2); + +__isl_export +__isl_give isl_set *isl_multi_pw_aff_bind(__isl_take isl_multi_pw_aff *mpa, + __isl_take isl_multi_id *tuple); __isl_constructor __isl_give isl_multi_pw_aff *isl_multi_pw_aff_read_from_str(isl_ctx *ctx, @@ -840,10 +998,13 @@ __isl_take isl_union_pw_aff *upa); isl_ctx *isl_union_pw_aff_get_ctx(__isl_keep isl_union_pw_aff *upa); +__isl_export __isl_give isl_space *isl_union_pw_aff_get_space( __isl_keep isl_union_pw_aff *upa); +__isl_give isl_pw_aff_list *isl_union_pw_aff_get_pw_aff_list( + __isl_keep isl_union_pw_aff *upa); -unsigned isl_union_pw_aff_dim(__isl_keep isl_union_pw_aff *upa, +isl_size isl_union_pw_aff_dim(__isl_keep isl_union_pw_aff *upa, enum isl_dim_type type); __isl_give isl_union_pw_aff *isl_union_pw_aff_set_dim_name( __isl_take isl_union_pw_aff *upa, enum isl_dim_type type, @@ -858,6 +1019,9 @@ __isl_give isl_union_pw_aff *isl_union_pw_aff_reset_user( __isl_take isl_union_pw_aff *upa); +__isl_give isl_union_pw_aff *isl_union_pw_aff_empty_ctx(isl_ctx *ctx); +__isl_give isl_union_pw_aff *isl_union_pw_aff_empty_space( + __isl_take isl_space *space); __isl_give isl_union_pw_aff *isl_union_pw_aff_empty( __isl_take isl_space *space); __isl_constructor @@ -876,7 +1040,7 @@ __isl_give isl_union_pw_multi_aff *isl_union_pw_multi_aff_from_union_pw_aff( __isl_take isl_union_pw_aff *upa); -int isl_union_pw_aff_n_pw_aff(__isl_keep isl_union_pw_aff *upa); +isl_size isl_union_pw_aff_n_pw_aff(__isl_keep isl_union_pw_aff *upa); isl_stat isl_union_pw_aff_foreach_pw_aff(__isl_keep isl_union_pw_aff *upa, isl_stat (*fn)(__isl_take isl_pw_aff *pa, void *user), void *user); @@ -887,6 +1051,7 @@ isl_bool isl_union_pw_aff_plain_is_equal(__isl_keep isl_union_pw_aff *upa1, __isl_keep isl_union_pw_aff *upa2); +__isl_export __isl_give isl_union_set *isl_union_pw_aff_domain( __isl_take isl_union_pw_aff *upa); @@ -899,11 +1064,13 @@ __isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_union_add( __isl_take isl_union_pw_aff *upa1, __isl_take isl_union_pw_aff *upa2); +__isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_sub( __isl_take isl_union_pw_aff *upa1, __isl_take isl_union_pw_aff *upa2); __isl_give isl_union_pw_aff *isl_union_pw_aff_coalesce( __isl_take isl_union_pw_aff *upa); +__isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_gist( __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *context); __isl_give isl_union_pw_aff *isl_union_pw_aff_gist_params( @@ -927,10 +1094,19 @@ __isl_give isl_union_pw_aff *isl_union_pw_aff_align_params( __isl_take isl_union_pw_aff *upa, __isl_take isl_space *model); +__isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_intersect_params( __isl_take isl_union_pw_aff *upa, __isl_take isl_set *set); +__isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_intersect_domain( + __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *uset); +__isl_export +__isl_give isl_union_pw_aff *isl_union_pw_aff_intersect_domain_wrapped_domain( __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *uset); +__isl_export +__isl_give isl_union_pw_aff *isl_union_pw_aff_intersect_domain_wrapped_range( + __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *uset); +__isl_export __isl_give isl_union_pw_aff *isl_union_pw_aff_subtract_domain( __isl_take isl_union_pw_aff *upa, __isl_take isl_union_set *uset); @@ -943,6 +1119,10 @@ __isl_give isl_union_map *isl_union_map_from_union_pw_aff( __isl_take isl_union_pw_aff *upa); + +__isl_overload +__isl_give isl_union_set *isl_union_pw_aff_bind_id( + __isl_take isl_union_pw_aff *upa, __isl_take isl_id *id); __isl_constructor __isl_give isl_union_pw_aff *isl_union_pw_aff_read_from_str(isl_ctx *ctx, @@ -953,7 +1133,12 @@ void isl_union_pw_aff_dump(__isl_keep isl_union_pw_aff *upa); ISL_DECLARE_MULTI(union_pw_aff) -ISL_DECLARE_MULTI_NEG(union_pw_aff) +ISL_DECLARE_MULTI_ARITH(union_pw_aff) +ISL_DECLARE_MULTI_ZERO(union_pw_aff) +ISL_DECLARE_MULTI_NAN(union_pw_aff) +ISL_DECLARE_MULTI_DROP_DIMS(union_pw_aff) +ISL_DECLARE_MULTI_DIM_ID(union_pw_aff) +ISL_DECLARE_MULTI_TUPLE_ID(union_pw_aff) __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_from_multi_aff( __isl_take isl_multi_aff *ma); @@ -974,19 +1159,23 @@ __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_floor( __isl_take isl_multi_union_pw_aff *mupa); +__isl_export __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_intersect_domain( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_union_set *uset); +__isl_export __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_intersect_params( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_set *params); __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_intersect_range( __isl_take isl_multi_union_pw_aff *mupa, __isl_take isl_set *set); +__isl_export __isl_give isl_union_set *isl_multi_union_pw_aff_domain( __isl_take isl_multi_union_pw_aff *mupa); __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_coalesce( __isl_take isl_multi_union_pw_aff *aff); +__isl_export __isl_give isl_multi_union_pw_aff *isl_multi_union_pw_aff_gist( __isl_take isl_multi_union_pw_aff *aff, __isl_take isl_union_set *context); @@ -1030,6 +1219,10 @@ __isl_give isl_union_set *isl_multi_union_pw_aff_zero_union_set( __isl_take isl_multi_union_pw_aff *mupa); +__isl_export +__isl_give isl_union_set *isl_multi_union_pw_aff_bind( + __isl_take isl_multi_union_pw_aff *mupa, + __isl_take isl_multi_id *tuple); __isl_give isl_multi_pw_aff *isl_multi_union_pw_aff_extract_multi_pw_aff( __isl_keep isl_multi_union_pw_aff *mupa, __isl_take isl_space *space); @@ -1043,7 +1236,10 @@ __isl_take isl_printer *p, __isl_keep isl_multi_union_pw_aff *mupa); void isl_multi_union_pw_aff_dump(__isl_keep isl_multi_union_pw_aff *mupa); -ISL_DECLARE_LIST_FN(union_pw_aff) +ISL_DECLARE_EXPORTED_LIST_FN(aff) +ISL_DECLARE_EXPORTED_LIST_FN(pw_aff) +ISL_DECLARE_EXPORTED_LIST_FN(pw_multi_aff) +ISL_DECLARE_EXPORTED_LIST_FN(union_pw_aff) ISL_DECLARE_LIST_FN(union_pw_multi_aff) #if defined(__cplusplus) diff --git a/gcc/isl/include/isl/aff_type.h b/gcc/isl/include/isl/aff_type.h index 6cffa18..271f978 100644 --- a/gcc/isl/include/isl/aff_type.h +++ a/gcc/isl/include/isl/aff_type.h @@ -10,19 +10,19 @@ struct __isl_subclass(isl_multi_aff) __isl_subclass(isl_pw_aff) isl_aff; typedef struct isl_aff isl_aff; -ISL_DECLARE_LIST(aff) +ISL_DECLARE_EXPORTED_LIST_TYPE(aff) struct __isl_subclass(isl_multi_pw_aff) __isl_subclass(isl_pw_multi_aff) __isl_subclass(isl_union_pw_aff) isl_pw_aff; typedef struct isl_pw_aff isl_pw_aff; -ISL_DECLARE_LIST(pw_aff) +ISL_DECLARE_EXPORTED_LIST_TYPE(pw_aff) struct __isl_subclass(isl_multi_union_pw_aff) __isl_subclass(isl_union_pw_multi_aff) isl_union_pw_aff; typedef struct isl_union_pw_aff isl_union_pw_aff; -ISL_DECLARE_LIST_TYPE(union_pw_aff) +ISL_DECLARE_EXPORTED_LIST_TYPE(union_pw_aff) struct __isl_subclass(isl_multi_pw_aff) __isl_subclass(isl_pw_multi_aff) isl_multi_aff; @@ -31,6 +31,8 @@ struct __isl_subclass(isl_multi_pw_aff) __isl_subclass(isl_union_pw_multi_aff) isl_pw_multi_aff; typedef struct isl_pw_multi_aff isl_pw_multi_aff; + +ISL_DECLARE_EXPORTED_LIST_TYPE(pw_multi_aff) struct __isl_export isl_union_pw_multi_aff; typedef struct isl_union_pw_multi_aff isl_union_pw_multi_aff; diff --git a/gcc/isl/include/isl/arg.h b/gcc/isl/include/isl/arg.h index 0d37d1c..edbd81e 100644 --- a/gcc/isl/include/isl/arg.h +++ a/gcc/isl/include/isl/arg.h @@ -53,6 +53,7 @@ char short_name; const char *long_name; const char *argument_name; +#define ISL_ARG_OFFSET_NONE ((size_t) -1) size_t offset; const char *help_msg; #define ISL_ARG_SINGLE_DASH (1 << 0) @@ -152,7 +153,7 @@ .type = isl_arg_choice, \ .short_name = s, \ .long_name = l, \ - .offset = -1, \ + .offset = ISL_ARG_OFFSET_NONE, \ .help_msg = h, \ .flags = fl, \ .u = { .choice = { .choice = c, .default_value = d, \ @@ -181,7 +182,7 @@ #define ISL_ARG_BOOL(st,f,s,l,d,h) \ ISL_ARG_BOOL_F(st,f,s,l,d,h,0) #define ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,fl) \ - _ISL_ARG_BOOL_F(-1,s,l,setter,0,h,fl) + _ISL_ARG_BOOL_F(ISL_ARG_OFFSET_NONE,s,l,setter,0,h,fl) #define ISL_ARG_PHANTOM_BOOL(s,l,setter,h) \ ISL_ARG_PHANTOM_BOOL_F(s,l,setter,h,0) #define ISL_ARG_INT_F(st,f,s,l,a,d,h,fl) { \ @@ -192,7 +193,7 @@ .offset = offsetof(st, f), \ .help_msg = h, \ .flags = fl, \ - .u = { .ul = { .default_value = d } } \ + .u = { .i = { .default_value = d } } \ }, #define ISL_ARG_INT(st,f,s,l,a,d,h) \ ISL_ARG_INT_F(st,f,s,l,a,d,h,0) @@ -263,7 +264,7 @@ #define ISL_ARG_CHILD(st,f,l,c,h) \ _ISL_ARG_CHILD(offsetof(st, f),l,c,h,0) #define ISL_ARG_GROUP_F(l,c,h,fl) \ - _ISL_ARG_CHILD(-1,l,c,h,fl) + _ISL_ARG_CHILD(ISL_ARG_OFFSET_NONE,l,c,h,fl) #define ISL_ARG_GROUP(l,c,h) \ ISL_ARG_GROUP_F(l,c,h,0) #define ISL_ARG_FLAGS(st,f,s,l,c,d,h) { \ diff --git a/gcc/isl/include/isl/ast.h b/gcc/isl/include/isl/ast.h index 2793e16..5a2894b 100644 --- a/gcc/isl/include/isl/ast.h +++ a/gcc/isl/include/isl/ast.h @@ -1,11 +1,11 @@ #ifndef ISL_AST_H #define ISL_AST_H #include #include -#include +#include #include -#include +#include #include #include @@ -62,12 +62,26 @@ __isl_null isl_ast_expr *isl_ast_expr_free(__isl_take isl_ast_expr *expr); isl_ctx *isl_ast_expr_get_ctx(__isl_keep isl_ast_expr *expr); +__isl_subclass(isl_ast_expr) enum isl_ast_expr_type isl_ast_expr_get_type(__isl_keep isl_ast_expr *expr); +__isl_export +__isl_give isl_val *isl_ast_expr_int_get_val(__isl_keep isl_ast_expr *expr); __isl_give isl_val *isl_ast_expr_get_val(__isl_keep isl_ast_expr *expr); +__isl_export +__isl_give isl_id *isl_ast_expr_id_get_id(__isl_keep isl_ast_expr *expr); __isl_give isl_id *isl_ast_expr_get_id(__isl_keep isl_ast_expr *expr); -enum isl_ast_op_type isl_ast_expr_get_op_type(__isl_keep isl_ast_expr *expr); -int isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr); +__isl_subclass(isl_ast_expr_op) +enum isl_ast_expr_op_type isl_ast_expr_op_get_type( + __isl_keep isl_ast_expr *expr); +enum isl_ast_expr_op_type isl_ast_expr_get_op_type( + __isl_keep isl_ast_expr *expr); +__isl_export +isl_size isl_ast_expr_op_get_n_arg(__isl_keep isl_ast_expr *expr); +isl_size isl_ast_expr_get_op_n_arg(__isl_keep isl_ast_expr *expr); +__isl_export +__isl_give isl_ast_expr *isl_ast_expr_op_get_arg(__isl_keep isl_ast_expr *expr, + int pos); __isl_give isl_ast_expr *isl_ast_expr_get_op_arg(__isl_keep isl_ast_expr *expr, int pos); __isl_give isl_ast_expr *isl_ast_expr_set_op_arg(__isl_take isl_ast_expr *expr, @@ -91,39 +105,59 @@ __isl_null isl_ast_node *isl_ast_node_free(__isl_take isl_ast_node *node); isl_ctx *isl_ast_node_get_ctx(__isl_keep isl_ast_node *node); +__isl_subclass(isl_ast_node) enum isl_ast_node_type isl_ast_node_get_type(__isl_keep isl_ast_node *node); __isl_give isl_ast_node *isl_ast_node_set_annotation( __isl_take isl_ast_node *node, __isl_take isl_id *annotation); __isl_give isl_id *isl_ast_node_get_annotation(__isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_for_get_iterator( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_for_get_init( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_for_get_cond( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_for_get_inc( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_node *isl_ast_node_for_get_body( __isl_keep isl_ast_node *node); +__isl_export isl_bool isl_ast_node_for_is_degenerate(__isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_if_get_cond( + __isl_keep isl_ast_node *node); +__isl_export +__isl_give isl_ast_node *isl_ast_node_if_get_then_node( __isl_keep isl_ast_node *node); __isl_give isl_ast_node *isl_ast_node_if_get_then( __isl_keep isl_ast_node *node); +__isl_export +isl_bool isl_ast_node_if_has_else_node(__isl_keep isl_ast_node *node); isl_bool isl_ast_node_if_has_else(__isl_keep isl_ast_node *node); +__isl_export +__isl_give isl_ast_node *isl_ast_node_if_get_else_node( + __isl_keep isl_ast_node *node); __isl_give isl_ast_node *isl_ast_node_if_get_else( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_node_list *isl_ast_node_block_get_children( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_id *isl_ast_node_mark_get_id(__isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_node *isl_ast_node_mark_get_node( __isl_keep isl_ast_node *node); +__isl_export __isl_give isl_ast_expr *isl_ast_node_user_get_expr( __isl_keep isl_ast_node *node); @@ -160,15 +194,24 @@ isl_stat isl_options_set_ast_print_macro_once(isl_ctx *ctx, int val); int isl_options_get_ast_print_macro_once(isl_ctx *ctx); +isl_stat isl_ast_expr_foreach_ast_expr_op_type(__isl_keep isl_ast_expr *expr, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); isl_stat isl_ast_expr_foreach_ast_op_type(__isl_keep isl_ast_expr *expr, - isl_stat (*fn)(enum isl_ast_op_type type, void *user), void *user); + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); +isl_stat isl_ast_node_foreach_ast_expr_op_type(__isl_keep isl_ast_node *node, + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); isl_stat isl_ast_node_foreach_ast_op_type(__isl_keep isl_ast_node *node, - isl_stat (*fn)(enum isl_ast_op_type type, void *user), void *user); + isl_stat (*fn)(enum isl_ast_expr_op_type type, void *user), void *user); +__isl_give isl_printer *isl_ast_expr_op_type_set_print_name( + __isl_take isl_printer *p, enum isl_ast_expr_op_type type, + __isl_keep const char *name); __isl_give isl_printer *isl_ast_op_type_set_print_name( - __isl_take isl_printer *p, enum isl_ast_op_type type, + __isl_take isl_printer *p, enum isl_ast_expr_op_type type, __isl_keep const char *name); +__isl_give isl_printer *isl_ast_expr_op_type_print_macro( + enum isl_ast_expr_op_type type, __isl_take isl_printer *p); __isl_give isl_printer *isl_ast_op_type_print_macro( - enum isl_ast_op_type type, __isl_take isl_printer *p); + enum isl_ast_expr_op_type type, __isl_take isl_printer *p); __isl_give isl_printer *isl_ast_expr_print_macros( __isl_keep isl_ast_expr *expr, __isl_take isl_printer *p); __isl_give isl_printer *isl_ast_node_print_macros( diff --git a/gcc/isl/include/isl/ast_build.h b/gcc/isl/include/isl/ast_build.h index bf08e03..0029cd5 100644 --- a/gcc/isl/include/isl/ast_build.h +++ a/gcc/isl/include/isl/ast_build.h @@ -1,5 +1,5 @@ -#ifndef ISL_AST_CONTEXT_H -#define ISL_AST_CONTEXT_H +#ifndef ISL_AST_BUILD_H +#define ISL_AST_BUILD_H #include #include @@ -52,6 +52,7 @@ __isl_give isl_space *isl_ast_build_get_schedule_space( __isl_keep isl_ast_build *build); +__isl_export __isl_give isl_union_map *isl_ast_build_get_schedule( __isl_keep isl_ast_build *build); @@ -69,6 +70,7 @@ __isl_give isl_ast_build *isl_ast_build_set_iterators( __isl_take isl_ast_build *build, __isl_take isl_id_list *iterators); +__isl_export __isl_give isl_ast_build *isl_ast_build_set_at_each_domain( __isl_take isl_ast_build *build, __isl_give isl_ast_node *(*fn)(__isl_take isl_ast_node *node, @@ -113,6 +115,7 @@ __isl_give isl_ast_expr *isl_ast_build_call_from_multi_pw_aff( __isl_keep isl_ast_build *build, __isl_take isl_multi_pw_aff *mpa); +__isl_overload __isl_give isl_ast_node *isl_ast_build_node_from_schedule( __isl_keep isl_ast_build *build, __isl_take isl_schedule *schedule); __isl_export diff --git a/gcc/isl/include/isl/ast_type.h b/gcc/isl/include/isl/ast_type.h index 1e09b3b..1ee4c45 100644 --- a/gcc/isl/include/isl/ast_type.h +++ a/gcc/isl/include/isl/ast_type.h @@ -13,36 +13,65 @@ struct __isl_export isl_ast_node; typedef struct isl_ast_node isl_ast_node; -enum isl_ast_op_type { - isl_ast_op_error = -1, - isl_ast_op_and, - isl_ast_op_and_then, - isl_ast_op_or, - isl_ast_op_or_else, - isl_ast_op_max, - isl_ast_op_min, - isl_ast_op_minus, - isl_ast_op_add, - isl_ast_op_sub, - isl_ast_op_mul, - isl_ast_op_div, - isl_ast_op_fdiv_q, /* Round towards -infty */ - isl_ast_op_pdiv_q, /* Dividend is non-negative */ - isl_ast_op_pdiv_r, /* Dividend is non-negative */ - isl_ast_op_zdiv_r, /* Result only compared against zero */ - isl_ast_op_cond, - isl_ast_op_select, - isl_ast_op_eq, - isl_ast_op_le, - isl_ast_op_lt, - isl_ast_op_ge, - isl_ast_op_gt, - isl_ast_op_call, - isl_ast_op_access, - isl_ast_op_member, - isl_ast_op_address_of +enum isl_ast_expr_op_type { + isl_ast_expr_op_error = -1, + isl_ast_expr_op_and, + isl_ast_expr_op_and_then, + isl_ast_expr_op_or, + isl_ast_expr_op_or_else, + isl_ast_expr_op_max, + isl_ast_expr_op_min, + isl_ast_expr_op_minus, + isl_ast_expr_op_add, + isl_ast_expr_op_sub, + isl_ast_expr_op_mul, + isl_ast_expr_op_div, + isl_ast_expr_op_fdiv_q, /* Round towards -infty */ + isl_ast_expr_op_pdiv_q, /* Dividend is non-negative */ + isl_ast_expr_op_pdiv_r, /* Dividend is non-negative */ + isl_ast_expr_op_zdiv_r, /* Result only compared against zero */ + isl_ast_expr_op_cond, + isl_ast_expr_op_select, + isl_ast_expr_op_eq, + isl_ast_expr_op_le, + isl_ast_expr_op_lt, + isl_ast_expr_op_ge, + isl_ast_expr_op_gt, + isl_ast_expr_op_call, + isl_ast_expr_op_access, + isl_ast_expr_op_member, + isl_ast_expr_op_address_of }; +#define isl_ast_op_type isl_ast_expr_op_type +#define isl_ast_op_error isl_ast_expr_op_error +#define isl_ast_op_and isl_ast_expr_op_and +#define isl_ast_op_and_then isl_ast_expr_op_and_then +#define isl_ast_op_or isl_ast_expr_op_or +#define isl_ast_op_or_else isl_ast_expr_op_or_else +#define isl_ast_op_max isl_ast_expr_op_max +#define isl_ast_op_min isl_ast_expr_op_min +#define isl_ast_op_minus isl_ast_expr_op_minus +#define isl_ast_op_add isl_ast_expr_op_add +#define isl_ast_op_sub isl_ast_expr_op_sub +#define isl_ast_op_mul isl_ast_expr_op_mul +#define isl_ast_op_div isl_ast_expr_op_div +#define isl_ast_op_fdiv_q isl_ast_expr_op_fdiv_q +#define isl_ast_op_pdiv_q isl_ast_expr_op_pdiv_q +#define isl_ast_op_pdiv_r isl_ast_expr_op_pdiv_r +#define isl_ast_op_zdiv_r isl_ast_expr_op_zdiv_r +#define isl_ast_op_cond isl_ast_expr_op_cond +#define isl_ast_op_select isl_ast_expr_op_select +#define isl_ast_op_eq isl_ast_expr_op_eq +#define isl_ast_op_le isl_ast_expr_op_le +#define isl_ast_op_lt isl_ast_expr_op_lt +#define isl_ast_op_ge isl_ast_expr_op_ge +#define isl_ast_op_gt isl_ast_expr_op_gt +#define isl_ast_op_call isl_ast_expr_op_call +#define isl_ast_op_access isl_ast_expr_op_access +#define isl_ast_op_member isl_ast_expr_op_member +#define isl_ast_op_address_of isl_ast_expr_op_address_of + enum isl_ast_expr_type { isl_ast_expr_error = -1, isl_ast_expr_op, @@ -71,7 +100,7 @@ typedef struct isl_ast_print_options isl_ast_print_options; ISL_DECLARE_LIST(ast_expr) -ISL_DECLARE_LIST(ast_node) +ISL_DECLARE_EXPORTED_LIST(ast_node) #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/constraint.h b/gcc/isl/include/isl/constraint.h index 73053b9..6728245 100644 --- a/gcc/isl/include/isl/constraint.h +++ a/gcc/isl/include/isl/constraint.h @@ -11,11 +11,11 @@ #define ISL_CONSTRAINT_H #include -#include +#include #include #include #include -#include +#include #include #if defined(__cplusplus) @@ -39,8 +39,8 @@ struct isl_constraint *isl_constraint_copy(struct isl_constraint *c); __isl_null isl_constraint *isl_constraint_free(__isl_take isl_constraint *c); -int isl_basic_map_n_constraint(__isl_keep isl_basic_map *bmap); -int isl_basic_set_n_constraint(__isl_keep isl_basic_set *bset); +isl_size isl_basic_map_n_constraint(__isl_keep isl_basic_map *bmap); +isl_size isl_basic_set_n_constraint(__isl_keep isl_basic_set *bset); isl_stat isl_basic_map_foreach_constraint(__isl_keep isl_basic_map *bmap, isl_stat (*fn)(__isl_take isl_constraint *c, void *user), void *user); isl_stat isl_basic_set_foreach_constraint(__isl_keep isl_basic_set *bset, @@ -82,7 +82,7 @@ __isl_keep isl_constraint *constraint); __isl_give isl_local_space *isl_constraint_get_local_space( __isl_keep isl_constraint *constraint); -int isl_constraint_dim(struct isl_constraint *constraint, +isl_size isl_constraint_dim(__isl_keep isl_constraint *constraint, enum isl_dim_type type); isl_bool isl_constraint_involves_dims(__isl_keep isl_constraint *constraint, @@ -111,7 +111,8 @@ struct isl_constraint *isl_constraint_negate(struct isl_constraint *constraint); isl_bool isl_constraint_is_equality(__isl_keep isl_constraint *constraint); -int isl_constraint_is_div_constraint(__isl_keep isl_constraint *constraint); +isl_bool isl_constraint_is_div_constraint( + __isl_keep isl_constraint *constraint); isl_bool isl_constraint_is_lower_bound(__isl_keep isl_constraint *constraint, enum isl_dim_type type, unsigned pos); diff --git a/gcc/isl/include/isl/ctx.h b/gcc/isl/include/isl/ctx.h index 13c98c8..ecd9272 100644 --- a/gcc/isl/include/isl/ctx.h +++ a/gcc/isl/include/isl/ctx.h @@ -85,12 +85,16 @@ isl_stat_error = -1, isl_stat_ok = 0 } isl_stat; +isl_stat isl_stat_non_null(void *obj); typedef enum { isl_bool_error = -1, isl_bool_false = 0, isl_bool_true = 1 } isl_bool; isl_bool isl_bool_not(isl_bool b); +isl_bool isl_bool_ok(int b); +typedef int isl_size; +#define isl_size_error ((int) -1) struct isl_ctx; typedef struct isl_ctx isl_ctx; diff --git a/gcc/isl/include/isl/flow.h b/gcc/isl/include/isl/flow.h index f606549..be2f6c5 100644 --- a/gcc/isl/include/isl/flow.h +++ a/gcc/isl/include/isl/flow.h @@ -63,7 +63,7 @@ void *user), void *user); __isl_give isl_map *isl_flow_get_no_source(__isl_keep isl_flow *deps, int must); -void isl_flow_free(__isl_take isl_flow *deps); +__isl_null isl_flow *isl_flow_free(__isl_take isl_flow *deps); isl_ctx *isl_flow_get_ctx(__isl_keep isl_flow *deps); diff --git a/gcc/isl/include/isl/hash.h b/gcc/isl/include/isl/hash.h index d5de9ba..7ef3d2e 100644 --- a/gcc/isl/include/isl/hash.h +++ a/gcc/isl/include/isl/hash.h @@ -59,11 +59,12 @@ int isl_hash_table_init(struct isl_ctx *ctx, struct isl_hash_table *table, int min_size); void isl_hash_table_clear(struct isl_hash_table *table); +extern struct isl_hash_table_entry *isl_hash_table_entry_none; struct isl_hash_table_entry *isl_hash_table_find(struct isl_ctx *ctx, - struct isl_hash_table *table, - uint32_t key_hash, - int (*eq)(const void *entry, const void *val), - const void *val, int reserve); + struct isl_hash_table *table, + uint32_t key_hash, + isl_bool (*eq)(const void *entry, const void *val), + const void *val, int reserve); isl_stat isl_hash_table_foreach(isl_ctx *ctx, struct isl_hash_table *table, isl_stat (*fn)(void **entry, void *user), void *user); void isl_hash_table_remove(struct isl_ctx *ctx, diff --git a/gcc/isl/include/isl/hmap_templ.c b/gcc/isl/include/isl/hmap_templ.c index 3519a8d..ceb52bd 100644 --- a/gcc/isl/include/isl/hmap_templ.c +++ a/gcc/isl/include/isl/hmap_templ.c @@ -128,7 +128,7 @@ return hmap; } -static int has_key(const void *entry, const void *c_key) +static isl_bool has_key(const void *entry, const void *c_key) { const ISL_S(pair) *pair = entry; ISL_KEY *key = (ISL_KEY *) c_key; @@ -159,6 +159,8 @@ &has_key, key, 0); if (!entry) + goto error; + if (entry == isl_hash_table_entry_none) return res; pair = entry->data; @@ -221,7 +223,9 @@ hash = ISL_FN(ISL_KEY,get_hash)(key); entry = isl_hash_table_find(hmap->ctx, &hmap->table, hash, &has_key, key, 0); - if (!entry) { + if (!entry) + goto error; + if (entry == isl_hash_table_entry_none) { ISL_FN(ISL_KEY,free)(key); return hmap; } @@ -234,8 +238,10 @@ ISL_FN(ISL_KEY,free)(key); if (!entry) + return ISL_FN(ISL_HMAP,free)(hmap); + if (entry == isl_hash_table_entry_none) isl_die(hmap->ctx, isl_error_internal, - "missing entry" , goto error); + "missing entry" , return ISL_FN(ISL_HMAP,free)(hmap)); pair = entry->data; isl_hash_table_remove(hmap->ctx, &hmap->table, entry); @@ -269,8 +275,10 @@ hash = ISL_FN(ISL_KEY,get_hash)(key); entry = isl_hash_table_find(hmap->ctx, &hmap->table, hash, &has_key, key, 0); - if (entry) { - int equal; + if (!entry) + goto error; + if (entry != isl_hash_table_entry_none) { + isl_bool equal; pair = entry->data; equal = ISL_VAL_IS_EQUAL(pair->val, val); if (equal < 0) diff --git a/gcc/isl/include/isl/id.h b/gcc/isl/include/isl/id.h index c025d51..956b962 100644 --- a/gcc/isl/include/isl/id.h +++ a/gcc/isl/include/isl/id.h @@ -1,8 +1,10 @@ #ifndef ISL_ID_H #define ISL_ID_H #include +#include #include +#include #include #include @@ -10,10 +12,9 @@ extern "C" { #endif -struct isl_id; -typedef struct isl_id isl_id; +ISL_DECLARE_EXPORTED_LIST_FN(id) -ISL_DECLARE_LIST(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); @@ -24,15 +25,26 @@ __isl_null isl_id *isl_id_free(__isl_take isl_id *id); void *isl_id_get_user(__isl_keep isl_id *id); +__isl_export __isl_keep const char *isl_id_get_name(__isl_keep isl_id *id); __isl_give isl_id *isl_id_set_free_user(__isl_take isl_id *id, void (*free_user)(void *user)); +__isl_constructor +__isl_give isl_id *isl_id_read_from_str(isl_ctx *ctx, const char *str); __isl_give char *isl_id_to_str(__isl_keep isl_id *id); __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_constructor +__isl_give isl_multi_id *isl_multi_id_read_from_str(isl_ctx *ctx, + const char *str); +__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) } diff --git a/gcc/isl/include/isl/id_to_ast_expr.h b/gcc/isl/include/isl/id_to_ast_expr.h index a160a9f..5822241 100644 --- a/gcc/isl/include/isl/id_to_ast_expr.h +++ a/gcc/isl/include/isl/id_to_ast_expr.h @@ -1,7 +1,7 @@ #ifndef ISL_ID_TO_AST_EXPR_H #define ISL_ID_TO_AST_EXPR_H -#include +#include #include #include diff --git a/gcc/isl/include/isl/id_to_id.h b/gcc/isl/include/isl/id_to_id.h index 26bbc59..3090115 100644 --- a/gcc/isl/include/isl/id_to_id.h +++ a/gcc/isl/include/isl/id_to_id.h @@ -1,7 +1,7 @@ #ifndef ISL_ID_TO_ID_H #define ISL_ID_TO_ID_H -#include +#include #include #define ISL_KEY isl_id diff --git a/gcc/isl/include/isl/id_to_pw_aff.h b/gcc/isl/include/isl/id_to_pw_aff.h index 081cc84..bcbea66 100644 --- a/gcc/isl/include/isl/id_to_pw_aff.h +++ a/gcc/isl/include/isl/id_to_pw_aff.h @@ -1,7 +1,7 @@ #ifndef ISL_ID_TO_PW_AFF_H #define ISL_ID_TO_PW_AFF_H -#include +#include #include #include diff --git a/gcc/isl/include/isl/ilp.h b/gcc/isl/include/isl/ilp.h index d93c592..0116642 100644 --- a/gcc/isl/include/isl/ilp.h +++ a/gcc/isl/include/isl/ilp.h @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #if defined(__cplusplus) @@ -29,7 +29,15 @@ __isl_give isl_val *isl_set_max_val(__isl_keep isl_set *set, __isl_keep isl_aff *obj); __isl_give isl_multi_val *isl_union_set_min_multi_union_pw_aff( - __isl_keep isl_union_set *set, __isl_keep isl_multi_union_pw_aff *obj); + __isl_keep isl_union_set *uset, __isl_keep isl_multi_union_pw_aff *obj); + +__isl_give isl_val *isl_union_pw_aff_min_val(__isl_take isl_union_pw_aff *upa); +__isl_give isl_val *isl_union_pw_aff_max_val(__isl_take isl_union_pw_aff *upa); + +__isl_give isl_multi_val *isl_multi_union_pw_aff_min_multi_val( + __isl_take isl_multi_union_pw_aff *mupa); +__isl_give isl_multi_val *isl_multi_union_pw_aff_max_multi_val( + __isl_take isl_multi_union_pw_aff *mupa); __isl_export __isl_give isl_val *isl_basic_set_dim_max_val(__isl_take isl_basic_set *bset, diff --git a/gcc/isl/include/isl/list.h b/gcc/isl/include/isl/list.h index 803fd3a..b5ffe49 100644 --- a/gcc/isl/include/isl/list.h +++ a/gcc/isl/include/isl/list.h @@ -17,38 +17,60 @@ extern "C" { #endif -#define ISL_DECLARE_LIST_TYPE(EL) \ +#define ISL_DECLARE_LIST_TYPE2(EL,EXPORT) \ struct isl_##EL; \ -struct isl_##EL##_list; \ +struct EXPORT isl_##EL##_list; \ typedef struct isl_##EL##_list isl_##EL##_list; -#define ISL_DECLARE_LIST_FN(EL) \ +#define ISL_DECLARE_LIST_TYPE(EL) \ + ISL_DECLARE_LIST_TYPE2(EL,) +#define ISL_DECLARE_EXPORTED_LIST_TYPE(EL) \ + ISL_DECLARE_LIST_TYPE2(EL,__isl_export) +#define ISL_DECLARE_LIST_FN3(EL,CONSTRUCTOR,EXPORT) \ isl_ctx *isl_##EL##_list_get_ctx(__isl_keep isl_##EL##_list *list); \ +CONSTRUCTOR \ __isl_give isl_##EL##_list *isl_##EL##_list_from_##EL( \ - __isl_take struct isl_##EL *el); \ + __isl_take isl_##EL *el); \ +CONSTRUCTOR \ __isl_give isl_##EL##_list *isl_##EL##_list_alloc(isl_ctx *ctx, int n); \ __isl_give isl_##EL##_list *isl_##EL##_list_copy( \ __isl_keep isl_##EL##_list *list); \ __isl_null isl_##EL##_list *isl_##EL##_list_free( \ __isl_take isl_##EL##_list *list); \ +EXPORT \ __isl_give isl_##EL##_list *isl_##EL##_list_add( \ __isl_take isl_##EL##_list *list, \ - __isl_take struct isl_##EL *el); \ + __isl_take isl_##EL *el); \ __isl_give isl_##EL##_list *isl_##EL##_list_insert( \ __isl_take isl_##EL##_list *list, unsigned pos, \ __isl_take struct isl_##EL *el); \ __isl_give isl_##EL##_list *isl_##EL##_list_drop( \ __isl_take isl_##EL##_list *list, unsigned first, unsigned n); \ +EXPORT \ +__isl_give isl_##EL##_list *isl_##EL##_list_clear( \ + __isl_take isl_##EL##_list *list); \ +__isl_give isl_##EL##_list *isl_##EL##_list_swap( \ + __isl_take isl_##EL##_list *list, unsigned pos1, \ + unsigned pos2); \ +__isl_give isl_##EL##_list *isl_##EL##_list_reverse( \ + __isl_take isl_##EL##_list *list); \ +EXPORT \ __isl_give isl_##EL##_list *isl_##EL##_list_concat( \ __isl_take isl_##EL##_list *list1, \ __isl_take isl_##EL##_list *list2); \ -int isl_##EL##_list_n_##EL(__isl_keep isl_##EL##_list *list); \ +EXPORT \ +isl_size isl_##EL##_list_size(__isl_keep isl_##EL##_list *list); \ +isl_size isl_##EL##_list_n_##EL(__isl_keep isl_##EL##_list *list); \ +EXPORT \ +__isl_give isl_##EL *isl_##EL##_list_get_at( \ + __isl_keep isl_##EL##_list *list, int index); \ __isl_give struct isl_##EL *isl_##EL##_list_get_##EL( \ __isl_keep isl_##EL##_list *list, int index); \ __isl_give struct isl_##EL##_list *isl_##EL##_list_set_##EL( \ __isl_take struct isl_##EL##_list *list, int index, \ __isl_take struct isl_##EL *el); \ +EXPORT \ isl_stat isl_##EL##_list_foreach(__isl_keep isl_##EL##_list *list, \ - isl_stat (*fn)(__isl_take struct isl_##EL *el, void *user), \ + isl_stat (*fn)(__isl_take isl_##EL *el, void *user), \ void *user); \ __isl_give isl_##EL##_list *isl_##EL##_list_map( \ __isl_take isl_##EL##_list *list, \ @@ -66,13 +88,22 @@ void *follows_user, \ isl_stat (*fn)(__isl_take isl_##EL##_list *scc, void *user), \ void *fn_user); \ +__isl_give char *isl_##EL##_list_to_str( \ + __isl_keep isl_##EL##_list *list); \ __isl_give isl_printer *isl_printer_print_##EL##_list( \ __isl_take isl_printer *p, __isl_keep isl_##EL##_list *list); \ void isl_##EL##_list_dump(__isl_keep isl_##EL##_list *list); +#define ISL_DECLARE_LIST_FN(EL) \ + ISL_DECLARE_LIST_FN3(EL,,) +#define ISL_DECLARE_EXPORTED_LIST_FN(EL) \ + ISL_DECLARE_LIST_FN3(EL,__isl_constructor,__isl_export) #define ISL_DECLARE_LIST(EL) \ ISL_DECLARE_LIST_TYPE(EL) \ ISL_DECLARE_LIST_FN(EL) +#define ISL_DECLARE_EXPORTED_LIST(EL) \ + ISL_DECLARE_EXPORTED_LIST_TYPE(EL) \ + ISL_DECLARE_EXPORTED_LIST_FN(EL) #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/local_space.h b/gcc/isl/include/isl/local_space.h index d0fc960..cf2fe17 100644 --- a/gcc/isl/include/isl/local_space.h +++ a/gcc/isl/include/isl/local_space.h @@ -1,8 +1,8 @@ #ifndef ISL_LOCAL_SPACE_H #define ISL_LOCAL_SPACE_H #include -#include +#include #include #include @@ -29,7 +29,7 @@ __isl_take isl_local_space *ls, enum isl_dim_type type, __isl_take isl_id *id); -int isl_local_space_dim(__isl_keep isl_local_space *ls, +isl_size isl_local_space_dim(__isl_keep isl_local_space *ls, enum isl_dim_type type); isl_bool isl_local_space_has_dim_name(__isl_keep isl_local_space *ls, enum isl_dim_type type, unsigned pos); diff --git a/gcc/isl/include/isl/lp.h b/gcc/isl/include/isl/lp.h index 461ae00..4ca39a9 100644 --- a/gcc/isl/include/isl/lp.h +++ a/gcc/isl/include/isl/lp.h @@ -11,7 +11,7 @@ #define ISL_LP_H #include -#include +#include #include enum isl_lp_result { diff --git a/gcc/isl/include/isl/map.h b/gcc/isl/include/isl/map.h index 0ff17fe..41fee75 100644 --- a/gcc/isl/include/isl/map.h +++ a/gcc/isl/include/isl/map.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include #include @@ -21,36 +21,25 @@ #include #include #include -#include +#include #include +#include +#include #if defined(__cplusplus) extern "C" { #endif -ISL_DEPRECATED -unsigned isl_basic_map_n_in(__isl_keep const isl_basic_map *bmap); -ISL_DEPRECATED -unsigned isl_basic_map_n_out(__isl_keep const isl_basic_map *bmap); -ISL_DEPRECATED -unsigned isl_basic_map_n_param(__isl_keep const isl_basic_map *bmap); -ISL_DEPRECATED -unsigned isl_basic_map_n_div(__isl_keep const isl_basic_map *bmap); -unsigned isl_basic_map_total_dim(__isl_keep const isl_basic_map *bmap); -unsigned isl_basic_map_dim(__isl_keep isl_basic_map *bmap, +isl_size isl_basic_map_total_dim(__isl_keep const isl_basic_map *bmap); +isl_size isl_basic_map_dim(__isl_keep isl_basic_map *bmap, enum isl_dim_type type); -ISL_DEPRECATED -unsigned isl_map_n_in(__isl_keep const isl_map *map); -ISL_DEPRECATED -unsigned isl_map_n_out(__isl_keep const isl_map *map); -ISL_DEPRECATED -unsigned isl_map_n_param(__isl_keep const isl_map *map); -unsigned isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type); +isl_size isl_map_dim(__isl_keep isl_map *map, enum isl_dim_type type); isl_ctx *isl_basic_map_get_ctx(__isl_keep isl_basic_map *bmap); isl_ctx *isl_map_get_ctx(__isl_keep isl_map *map); __isl_give isl_space *isl_basic_map_get_space(__isl_keep isl_basic_map *bmap); +__isl_export __isl_give isl_space *isl_map_get_space(__isl_keep isl_map *map); __isl_give isl_aff *isl_basic_map_get_div(__isl_keep isl_basic_map *bmap, @@ -110,18 +99,19 @@ isl_bool isl_basic_map_is_rational(__isl_keep isl_basic_map *bmap); -__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *dim); +__isl_give isl_basic_map *isl_basic_map_identity(__isl_take isl_space *space); __isl_null isl_basic_map *isl_basic_map_free(__isl_take isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_copy(__isl_keep isl_basic_map *bmap); __isl_give isl_basic_map *isl_basic_map_equal( - __isl_take isl_space *dim, unsigned n_equal); -__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *dim, + __isl_take isl_space *space, unsigned n_equal); +__isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *space, unsigned pos); -__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim, +__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *space, unsigned pos); __isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *space); __isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *space); -__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_space *dim); +__isl_give isl_basic_map *isl_basic_map_nat_universe( + __isl_take isl_space *space); __isl_give isl_basic_map *isl_basic_map_remove_redundancies( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_remove_redundancies(__isl_take isl_map *map); @@ -257,8 +247,10 @@ __isl_give isl_set **empty); __isl_give isl_pw_multi_aff *isl_basic_map_lexmin_pw_multi_aff( __isl_take isl_basic_map *bmap); +__isl_export __isl_give isl_pw_multi_aff *isl_map_lexmin_pw_multi_aff( __isl_take isl_map *map); +__isl_export __isl_give isl_pw_multi_aff *isl_map_lexmax_pw_multi_aff( __isl_take isl_map *map); @@ -281,8 +273,10 @@ isl_bool isl_basic_map_is_strict_subset(__isl_keep isl_basic_map *bmap1, __isl_keep isl_basic_map *bmap2); +__isl_export __isl_give isl_map *isl_map_universe(__isl_take isl_space *space); __isl_give isl_map *isl_map_nat_universe(__isl_take isl_space *dim); +__isl_export __isl_give isl_map *isl_map_empty(__isl_take isl_space *space); __isl_give isl_map *isl_map_identity(__isl_take isl_space *dim); __isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_space *dim, unsigned n); @@ -297,6 +291,7 @@ __isl_give isl_map *isl_map_copy(__isl_keep isl_map *map); __isl_export __isl_give isl_map *isl_map_reverse(__isl_take isl_map *map); +__isl_give isl_map *isl_map_range_reverse(__isl_take isl_map *map); __isl_export __isl_give isl_map *isl_map_union( __isl_take isl_map *map1, @@ -312,6 +307,8 @@ __isl_take isl_map *map, __isl_take isl_set *set); __isl_give isl_map *isl_map_intersect_domain_factor_range( + __isl_take isl_map *map, __isl_take isl_map *factor); +__isl_give isl_map *isl_map_intersect_range_factor_domain( __isl_take isl_map *map, __isl_take isl_map *factor); __isl_give isl_map *isl_map_intersect_range_factor_range( __isl_take isl_map *map, __isl_take isl_map *factor); @@ -323,14 +320,19 @@ __isl_give isl_map *isl_map_apply_range( __isl_take isl_map *map1, __isl_take isl_map *map2); +__isl_overload __isl_give isl_map *isl_map_preimage_domain_multi_aff(__isl_take isl_map *map, __isl_take isl_multi_aff *ma); +__isl_overload __isl_give isl_map *isl_map_preimage_range_multi_aff(__isl_take isl_map *map, __isl_take isl_multi_aff *ma); +__isl_overload __isl_give isl_map *isl_map_preimage_domain_pw_multi_aff( __isl_take isl_map *map, __isl_take isl_pw_multi_aff *pma); +__isl_overload __isl_give isl_map *isl_map_preimage_range_pw_multi_aff( __isl_take isl_map *map, __isl_take isl_pw_multi_aff *pma); +__isl_overload __isl_give isl_map *isl_map_preimage_domain_multi_pw_aff( __isl_take isl_map *map, __isl_take isl_multi_pw_aff *mpa); __isl_give isl_basic_map *isl_basic_map_product( @@ -341,8 +343,10 @@ __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); __isl_give isl_basic_map *isl_basic_map_range_product( __isl_take isl_basic_map *bmap1, __isl_take isl_basic_map *bmap2); +__isl_export __isl_give isl_map *isl_map_domain_product(__isl_take isl_map *map1, __isl_take isl_map *map2); +__isl_export __isl_give isl_map *isl_map_range_product(__isl_take isl_map *map1, __isl_take isl_map *map2); __isl_give isl_basic_map *isl_basic_map_flat_product( @@ -358,11 +362,17 @@ isl_bool isl_map_domain_is_wrapping(__isl_keep isl_map *map); isl_bool isl_map_range_is_wrapping(__isl_keep isl_map *map); isl_bool isl_map_is_product(__isl_keep isl_map *map); +__isl_export __isl_give isl_map *isl_map_factor_domain(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_factor_range(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_domain_factor_domain(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_domain_factor_range(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_range_factor_domain(__isl_take isl_map *map); +__isl_export __isl_give isl_map *isl_map_range_factor_range(__isl_take isl_map *map); __isl_export __isl_give isl_map *isl_map_intersect(__isl_take isl_map *map1, @@ -425,6 +435,8 @@ enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_map *isl_map_project_out(__isl_take isl_map *map, enum isl_dim_type type, unsigned first, unsigned n); +__isl_export +__isl_give isl_map *isl_map_project_out_all_params(__isl_take isl_map *map); __isl_give isl_basic_map *isl_basic_map_remove_divs( __isl_take isl_basic_map *bmap); __isl_give isl_map *isl_map_remove_unknown_divs(__isl_take isl_map *map); @@ -468,8 +480,10 @@ __isl_export isl_bool isl_set_is_wrapping(__isl_keep isl_set *set); __isl_give isl_basic_set *isl_basic_map_wrap(__isl_take isl_basic_map *bmap); +__isl_export __isl_give isl_set *isl_map_wrap(__isl_take isl_map *map); __isl_give isl_basic_map *isl_basic_set_unwrap(__isl_take isl_basic_set *bset); +__isl_export __isl_give isl_map *isl_set_unwrap(__isl_take isl_set *set); __isl_export __isl_give isl_basic_map *isl_basic_map_flatten(__isl_take isl_basic_map *bmap); @@ -491,7 +505,9 @@ __isl_give isl_set *isl_set_flatten(__isl_take isl_set *set); __isl_give isl_map *isl_set_flatten_map(__isl_take isl_set *set); __isl_give isl_set *isl_map_params(__isl_take isl_map *map); +__isl_export __isl_give isl_set *isl_map_domain(__isl_take isl_map *bmap); +__isl_export __isl_give isl_set *isl_map_range(__isl_take isl_map *map); __isl_give isl_map *isl_map_domain_map(__isl_take isl_map *map); __isl_give isl_map *isl_map_range_map(__isl_take isl_map *map); @@ -510,6 +526,13 @@ __isl_take isl_set *range); __isl_export __isl_give isl_basic_map *isl_map_sample(__isl_take isl_map *map); + +__isl_export +__isl_give isl_set *isl_map_bind_domain(__isl_take isl_map *map, + __isl_take isl_multi_id *tuple); +__isl_export +__isl_give isl_set *isl_map_bind_range(__isl_take isl_map *map, + __isl_take isl_multi_id *tuple); isl_bool isl_map_plain_is_empty(__isl_keep isl_map *map); isl_bool isl_map_plain_is_universe(__isl_keep isl_map *map); @@ -547,6 +570,7 @@ isl_bool isl_basic_map_can_curry(__isl_keep isl_basic_map *bmap); isl_bool isl_map_can_curry(__isl_keep isl_map *map); __isl_give isl_basic_map *isl_basic_map_curry(__isl_take isl_basic_map *bmap); +__isl_export __isl_give isl_map *isl_map_curry(__isl_take isl_map *map); isl_bool isl_map_can_range_curry(__isl_keep isl_map *map); @@ -555,6 +579,7 @@ isl_bool isl_basic_map_can_uncurry(__isl_keep isl_basic_map *bmap); isl_bool isl_map_can_uncurry(__isl_keep isl_map *map); __isl_give isl_basic_map *isl_basic_map_uncurry(__isl_take isl_basic_map *bmap); +__isl_export __isl_give isl_map *isl_map_uncurry(__isl_take isl_map *map); __isl_give isl_map *isl_map_make_disjoint(__isl_take isl_map *map); @@ -604,7 +629,13 @@ __isl_give isl_map *isl_map_gist_basic_map(__isl_take isl_map *map, __isl_take isl_basic_map *context); +__isl_give isl_stride_info *isl_map_get_range_stride_info( + __isl_keep isl_map *map, int pos); __isl_export +__isl_give isl_fixed_box *isl_map_get_range_simple_fixed_box_hull( + __isl_keep isl_map *map); + +__isl_export __isl_give isl_map *isl_map_coalesce(__isl_take isl_map *map); isl_bool isl_map_plain_is_equal(__isl_keep isl_map *map1, @@ -612,18 +643,20 @@ uint32_t isl_map_get_hash(__isl_keep isl_map *map); -int isl_map_n_basic_map(__isl_keep isl_map *map); +isl_size isl_map_n_basic_map(__isl_keep isl_map *map); __isl_export isl_stat isl_map_foreach_basic_map(__isl_keep isl_map *map, isl_stat (*fn)(__isl_take isl_basic_map *bmap, void *user), void *user); +__isl_give isl_basic_map_list *isl_map_get_basic_map_list( + __isl_keep isl_map *map); __isl_give isl_map *isl_map_fixed_power_val(__isl_take isl_map *map, __isl_take isl_val *exp); -__isl_give isl_map *isl_map_power(__isl_take isl_map *map, int *exact); +__isl_give isl_map *isl_map_power(__isl_take isl_map *map, isl_bool *exact); __isl_give isl_map *isl_map_reaching_path_lengths(__isl_take isl_map *map, - int *exact); + isl_bool *exact); __isl_give isl_map *isl_map_transitive_closure(__isl_take isl_map *map, - int *exact); + isl_bool *exact); __isl_give isl_map *isl_map_lex_le_map(__isl_take isl_map *map1, __isl_take isl_map *map2); @@ -638,6 +671,9 @@ __isl_take isl_basic_map *bmap, __isl_take isl_space *model); __isl_give isl_map *isl_map_align_params(__isl_take isl_map *map, __isl_take isl_space *model); +__isl_give isl_basic_map *isl_basic_map_drop_unused_params( + __isl_take isl_basic_map *bmap); +__isl_give isl_map *isl_map_drop_unused_params(__isl_take isl_map *map); __isl_give isl_mat *isl_basic_map_equalities_matrix( __isl_keep isl_basic_map *bmap, enum isl_dim_type c1, @@ -657,7 +693,7 @@ __isl_give isl_basic_map *isl_basic_map_from_multi_aff( __isl_take isl_multi_aff *maff); __isl_give isl_basic_map *isl_basic_map_from_aff_list( - __isl_take isl_space *domain_dim, __isl_take isl_aff_list *list); + __isl_take isl_space *domain_space, __isl_take isl_aff_list *list); __isl_give isl_map *isl_map_from_aff(__isl_take isl_aff *aff); __isl_give isl_map *isl_map_from_multi_aff(__isl_take isl_multi_aff *maff); diff --git a/gcc/isl/include/isl/mat.h b/gcc/isl/include/isl/mat.h index 9fef0e9..38983da 100644 --- a/gcc/isl/include/isl/mat.h +++ a/gcc/isl/include/isl/mat.h @@ -14,7 +14,7 @@ #include #include -#include +#include #if defined(__cplusplus) extern "C" { @@ -33,8 +33,8 @@ __isl_give isl_mat *isl_mat_copy(__isl_keep isl_mat *mat); __isl_null isl_mat *isl_mat_free(__isl_take isl_mat *mat); -int isl_mat_rows(__isl_keep isl_mat *mat); -int isl_mat_cols(__isl_keep isl_mat *mat); +isl_size isl_mat_rows(__isl_keep isl_mat *mat); +isl_size isl_mat_cols(__isl_keep isl_mat *mat); __isl_give isl_val *isl_mat_get_element_val(__isl_keep isl_mat *mat, int row, int col); __isl_give isl_mat *isl_mat_set_element_si(__isl_take isl_mat *mat, @@ -106,7 +106,7 @@ isl_bool isl_mat_has_linearly_independent_rows(__isl_keep isl_mat *mat1, __isl_keep isl_mat *mat2); -int isl_mat_rank(__isl_keep isl_mat *mat); +isl_size isl_mat_rank(__isl_keep isl_mat *mat); int isl_mat_initial_non_zero_cols(__isl_keep isl_mat *mat); void isl_mat_print_internal(__isl_keep isl_mat *mat, FILE *out, int indent); diff --git a/gcc/isl/include/isl/multi.h b/gcc/isl/include/isl/multi.h index bccc031..1ab330a 100644 --- a/gcc/isl/include/isl/multi.h +++ a/gcc/isl/include/isl/multi.h @@ -1,7 +1,8 @@ #ifndef ISL_MULTI_H #define ISL_MULTI_H -#include +#include +#include #include #include @@ -10,63 +11,37 @@ #endif #define ISL_DECLARE_MULTI(BASE) \ -unsigned isl_multi_##BASE##_dim(__isl_keep isl_multi_##BASE *multi, \ - enum isl_dim_type type); \ isl_ctx *isl_multi_##BASE##_get_ctx( \ __isl_keep isl_multi_##BASE *multi); \ +__isl_export \ __isl_give isl_space *isl_multi_##BASE##_get_space( \ __isl_keep isl_multi_##BASE *multi); \ __isl_give isl_space *isl_multi_##BASE##_get_domain_space( \ __isl_keep isl_multi_##BASE *multi); \ -int isl_multi_##BASE##_find_dim_by_name( \ - __isl_keep isl_multi_##BASE *multi, \ - enum isl_dim_type type, const char *name); \ +__isl_constructor \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_from_##BASE##_list( \ __isl_take isl_space *space, __isl_take isl_##BASE##_list *list); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_zero( \ - __isl_take isl_space *space); \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_copy( \ __isl_keep isl_multi_##BASE *multi); \ __isl_null isl_multi_##BASE *isl_multi_##BASE##_free( \ __isl_take isl_multi_##BASE *multi); \ +__isl_export \ isl_bool isl_multi_##BASE##_plain_is_equal( \ __isl_keep isl_multi_##BASE *multi1, \ __isl_keep isl_multi_##BASE *multi2); \ -isl_bool isl_multi_##BASE##_involves_nan( \ - __isl_keep isl_multi_##BASE *multi); \ -int isl_multi_##BASE##_find_dim_by_id( \ - __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type, \ - __isl_keep isl_id *id); \ -__isl_give isl_id *isl_multi_##BASE##_get_dim_id( \ - __isl_keep isl_multi_##BASE *multi, \ - enum isl_dim_type type, unsigned pos); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_dim_name( \ - __isl_take isl_multi_##BASE *multi, \ - enum isl_dim_type type, unsigned pos, const char *s); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_dim_id( \ - __isl_take isl_multi_##BASE *multi, \ - enum isl_dim_type type, unsigned pos, __isl_take isl_id *id); \ -const char *isl_multi_##BASE##_get_tuple_name( \ - __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ -isl_bool isl_multi_##BASE##_has_tuple_id( \ - __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ -__isl_give isl_id *isl_multi_##BASE##_get_tuple_id( \ - __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_tuple_name( \ - __isl_take isl_multi_##BASE *multi, \ - enum isl_dim_type type, const char *s); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_tuple_id( \ - __isl_take isl_multi_##BASE *multi, \ - enum isl_dim_type type, __isl_take isl_id *id); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_reset_tuple_id( \ - __isl_take isl_multi_##BASE *multi, enum isl_dim_type type); \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_reset_user( \ __isl_take isl_multi_##BASE *multi); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_drop_dims( \ - __isl_take isl_multi_##BASE *multi, enum isl_dim_type type, \ - unsigned first, unsigned n); \ +__isl_export \ +isl_size isl_multi_##BASE##_size(__isl_keep isl_multi_##BASE *multi); \ +__isl_export \ +__isl_give isl_##BASE *isl_multi_##BASE##_get_at( \ + __isl_keep isl_multi_##BASE *multi, int pos); \ __isl_give isl_##BASE *isl_multi_##BASE##_get_##BASE( \ __isl_keep isl_multi_##BASE *multi, int pos); \ +__isl_export \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_at( \ + __isl_take isl_multi_##BASE *multi, int pos, \ + __isl_take isl_##BASE *el); \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_set_##BASE( \ __isl_take isl_multi_##BASE *multi, int pos, \ __isl_take isl_##BASE *el); \ @@ -90,14 +65,40 @@ __isl_give isl_multi_##BASE *isl_multi_##BASE##_range_factor_domain( \ __isl_take isl_multi_##BASE *multi); \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_range_factor_range( \ + __isl_take isl_multi_##BASE *multi); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_align_params( \ + __isl_take isl_multi_##BASE *multi, \ + __isl_take isl_space *model); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_from_range( \ + __isl_take isl_multi_##BASE *multi); + +#define ISL_DECLARE_MULTI_IDENTITY(BASE) \ +__isl_overload \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_identity_multi_##BASE( \ __isl_take isl_multi_##BASE *multi); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_identity( \ + __isl_take isl_space *space); \ +__isl_overload \ +__isl_give isl_multi_##BASE * \ +isl_multi_##BASE##_identity_on_domain_space( \ + __isl_take isl_space *space); + +#define ISL_DECLARE_MULTI_CMP(BASE) \ +int isl_multi_##BASE##_plain_cmp(__isl_keep isl_multi_##BASE *multi1, \ + __isl_keep isl_multi_##BASE *multi2); + +#define ISL_DECLARE_MULTI_ARITH(BASE) \ +__isl_overload \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_scale_val( \ __isl_take isl_multi_##BASE *multi, __isl_take isl_val *v); \ +__isl_overload \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_scale_down_val( \ __isl_take isl_multi_##BASE *multi, __isl_take isl_val *v); \ +__isl_overload \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_scale_multi_val( \ __isl_take isl_multi_##BASE *multi, \ __isl_take isl_multi_val *mv); \ +__isl_overload \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_scale_down_multi_val( \ __isl_take isl_multi_##BASE *multi, \ __isl_take isl_multi_val *mv); \ @@ -108,24 +109,31 @@ __isl_give isl_multi_##BASE *isl_multi_##BASE##_add( \ __isl_take isl_multi_##BASE *multi1, \ __isl_take isl_multi_##BASE *multi2); \ +__isl_export \ __isl_give isl_multi_##BASE *isl_multi_##BASE##_sub( \ __isl_take isl_multi_##BASE *multi1, \ __isl_take isl_multi_##BASE *multi2); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_align_params( \ - __isl_take isl_multi_##BASE *multi, \ - __isl_take isl_space *model); \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_from_range( \ +__isl_export \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_neg( \ __isl_take isl_multi_##BASE *multi); -#define ISL_DECLARE_MULTI_CMP(BASE) \ -int isl_multi_##BASE##_plain_cmp(__isl_keep isl_multi_##BASE *multi1, \ - __isl_keep isl_multi_##BASE *multi2); +#define ISL_DECLARE_MULTI_ZERO(BASE) \ +__isl_export \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_zero( \ + __isl_take isl_space *space); -#define ISL_DECLARE_MULTI_NEG(BASE) \ -__isl_give isl_multi_##BASE *isl_multi_##BASE##_neg( \ - __isl_take isl_multi_##BASE *multi); +#define ISL_DECLARE_MULTI_NAN(BASE) \ +isl_bool isl_multi_##BASE##_involves_nan( \ + __isl_keep isl_multi_##BASE *multi); +#define ISL_DECLARE_MULTI_DROP_DIMS(BASE) \ +isl_size isl_multi_##BASE##_dim(__isl_keep isl_multi_##BASE *multi, \ + enum isl_dim_type type); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_drop_dims( \ + __isl_take isl_multi_##BASE *multi, enum isl_dim_type type, \ + unsigned first, unsigned n); #define ISL_DECLARE_MULTI_DIMS(BASE) \ +ISL_DECLARE_MULTI_DROP_DIMS(BASE) \ isl_bool isl_multi_##BASE##_involves_dims( \ __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type, \ unsigned first, unsigned n); \ @@ -138,6 +146,44 @@ __isl_give isl_multi_##BASE * \ isl_multi_##BASE##_project_domain_on_params( \ __isl_take isl_multi_##BASE *multi); + +#define ISL_DECLARE_MULTI_LOCALS(BASE) \ +__isl_export \ +isl_bool isl_multi_##BASE##_involves_locals( \ + __isl_keep isl_multi_##BASE *multi); + +#define ISL_DECLARE_MULTI_DIM_ID(BASE) \ +int isl_multi_##BASE##_find_dim_by_name( \ + __isl_keep isl_multi_##BASE *multi, \ + enum isl_dim_type type, const char *name); \ +int isl_multi_##BASE##_find_dim_by_id( \ + __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type, \ + __isl_keep isl_id *id); \ +__isl_give isl_id *isl_multi_##BASE##_get_dim_id( \ + __isl_keep isl_multi_##BASE *multi, \ + enum isl_dim_type type, unsigned pos); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_dim_name( \ + __isl_take isl_multi_##BASE *multi, \ + enum isl_dim_type type, unsigned pos, const char *s); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_dim_id( \ + __isl_take isl_multi_##BASE *multi, \ + enum isl_dim_type type, unsigned pos, __isl_take isl_id *id); + +#define ISL_DECLARE_MULTI_TUPLE_ID(BASE) \ +const char *isl_multi_##BASE##_get_tuple_name( \ + __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ +isl_bool isl_multi_##BASE##_has_tuple_id( \ + __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ +__isl_give isl_id *isl_multi_##BASE##_get_tuple_id( \ + __isl_keep isl_multi_##BASE *multi, enum isl_dim_type type); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_tuple_name( \ + __isl_take isl_multi_##BASE *multi, \ + enum isl_dim_type type, const char *s); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_set_tuple_id( \ + __isl_take isl_multi_##BASE *multi, \ + enum isl_dim_type type, __isl_take isl_id *id); \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_reset_tuple_id( \ + __isl_take isl_multi_##BASE *multi, enum isl_dim_type type); #define ISL_DECLARE_MULTI_WITH_DOMAIN(BASE) \ __isl_export \ @@ -147,6 +193,26 @@ __isl_give isl_multi_##BASE *isl_multi_##BASE##_splice( \ __isl_take isl_multi_##BASE *multi1, unsigned in_pos, \ unsigned out_pos, __isl_take isl_multi_##BASE *multi2); + +#define ISL_DECLARE_MULTI_BIND_DOMAIN(BASE) \ +__isl_export \ +__isl_give isl_multi_##BASE *isl_multi_##BASE##_bind_domain( \ + __isl_take isl_multi_##BASE *multi, \ + __isl_take isl_multi_id *tuple); \ +__isl_export \ +__isl_give isl_multi_##BASE * \ +isl_multi_##BASE##_bind_domain_wrapped_domain( \ + __isl_take isl_multi_##BASE *multi, \ + __isl_take isl_multi_id *tuple); + +#define ISL_DECLARE_MULTI_PARAM(BASE) \ +__isl_overload \ +isl_bool isl_multi_##BASE##_involves_param_id( \ + __isl_keep isl_multi_##BASE *multi, __isl_keep isl_id *id); \ +__isl_overload \ +isl_bool isl_multi_##BASE##_involves_param_id_list( \ + __isl_keep isl_multi_##BASE *multi, \ + __isl_keep isl_id_list *list); #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/options.h b/gcc/isl/include/isl/options.h index c09dee6..1738155 100644 --- a/gcc/isl/include/isl/options.h +++ a/gcc/isl/include/isl/options.h @@ -46,6 +46,9 @@ isl_stat isl_options_set_coalesce_bounded_wrapping(isl_ctx *ctx, int val); int isl_options_get_coalesce_bounded_wrapping(isl_ctx *ctx); +isl_stat isl_options_set_coalesce_preserve_locals(isl_ctx *ctx, int val); +int isl_options_get_coalesce_preserve_locals(isl_ctx *ctx); + #if defined(__cplusplus) } #endif diff --git a/gcc/isl/include/isl/point.h b/gcc/isl/include/isl/point.h index 97c3c46..b2f0957 100644 --- a/gcc/isl/include/isl/point.h +++ a/gcc/isl/include/isl/point.h @@ -1,9 +1,9 @@ #ifndef ISL_POINT_H #define ISL_POINT_H #include -#include -#include +#include +#include #if defined(__cplusplus) extern "C" { @@ -15,7 +15,7 @@ isl_ctx *isl_point_get_ctx(__isl_keep isl_point *pnt); __isl_give isl_space *isl_point_get_space(__isl_keep isl_point *pnt); -__isl_give isl_point *isl_point_zero(__isl_take isl_space *dim); +__isl_give isl_point *isl_point_zero(__isl_take isl_space *space); __isl_give isl_point *isl_point_copy(__isl_keep isl_point *pnt); __isl_null isl_point *isl_point_free(__isl_take isl_point *pnt); @@ -29,7 +29,7 @@ __isl_give isl_point *isl_point_sub_ui(__isl_take isl_point *pnt, enum isl_dim_type type, int pos, unsigned val); -__isl_give isl_point *isl_point_void(__isl_take isl_space *dim); +__isl_give isl_point *isl_point_void(__isl_take isl_space *space); isl_bool isl_point_is_void(__isl_keep isl_point *pnt); __isl_give isl_printer *isl_printer_print_point( diff --git a/gcc/isl/include/isl/polynomial.h b/gcc/isl/include/isl/polynomial.h index 72b015d..3a1b623 100644 --- a/gcc/isl/include/isl/polynomial.h +++ a/gcc/isl/include/isl/polynomial.h @@ -1,16 +1,16 @@ #ifndef ISL_POLYNOMIAL_H #define ISL_POLYNOMIAL_H #include #include -#include +#include #include #include #include #include #include #include -#include +#include #if defined(__cplusplus) extern "C" { @@ -20,7 +20,7 @@ __isl_give isl_space *isl_qpolynomial_get_domain_space( __isl_keep isl_qpolynomial *qp); __isl_give isl_space *isl_qpolynomial_get_space(__isl_keep isl_qpolynomial *qp); -unsigned isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp, +isl_size isl_qpolynomial_dim(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type); isl_bool isl_qpolynomial_involves_dims(__isl_keep isl_qpolynomial *qp, enum isl_dim_type type, unsigned first, unsigned n); @@ -32,14 +32,20 @@ __isl_take isl_qpolynomial *qp, enum isl_dim_type type, unsigned pos, const char *s); -__isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain(__isl_take isl_space *dim); -__isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain(__isl_take isl_space *dim); -__isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain(__isl_take isl_space *dim); -__isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain(__isl_take isl_space *dim); -__isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain(__isl_take isl_space *dim); +__isl_give isl_qpolynomial *isl_qpolynomial_zero_on_domain( + __isl_take isl_space *domain); +__isl_give isl_qpolynomial *isl_qpolynomial_one_on_domain( + __isl_take isl_space *domain); +__isl_give isl_qpolynomial *isl_qpolynomial_infty_on_domain( + __isl_take isl_space *domain); +__isl_give isl_qpolynomial *isl_qpolynomial_neginfty_on_domain( + __isl_take isl_space *domain); +__isl_give isl_qpolynomial *isl_qpolynomial_nan_on_domain( + __isl_take isl_space *domain); __isl_give isl_qpolynomial *isl_qpolynomial_val_on_domain( __isl_take isl_space *space, __isl_take isl_val *val); -__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain(__isl_take isl_space *dim, +__isl_give isl_qpolynomial *isl_qpolynomial_var_on_domain( + __isl_take isl_space *domain, enum isl_dim_type type, unsigned pos); __isl_give isl_qpolynomial *isl_qpolynomial_copy(__isl_keep isl_qpolynomial *qp); __isl_null isl_qpolynomial *isl_qpolynomial_free( @@ -101,11 +107,11 @@ isl_ctx *isl_term_get_ctx(__isl_keep isl_term *term); __isl_give isl_term *isl_term_copy(__isl_keep isl_term *term); -void isl_term_free(__isl_take isl_term *term); +__isl_null isl_term *isl_term_free(__isl_take isl_term *term); -unsigned isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type); +isl_size isl_term_dim(__isl_keep isl_term *term, enum isl_dim_type type); __isl_give isl_val *isl_term_get_coefficient_val(__isl_keep isl_term *term); -int isl_term_get_exp(__isl_keep isl_term *term, +isl_size isl_term_get_exp(__isl_keep isl_term *term, enum isl_dim_type type, unsigned pos); __isl_give isl_aff *isl_term_get_div(__isl_keep isl_term *term, unsigned pos); @@ -139,7 +145,8 @@ isl_bool isl_pw_qpolynomial_plain_is_equal(__isl_keep isl_pw_qpolynomial *pwqp1, __isl_keep isl_pw_qpolynomial *pwqp2); -__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero(__isl_take isl_space *dim); +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_zero( + __isl_take isl_space *space); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_alloc(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_qpolynomial( @@ -157,8 +164,10 @@ __isl_keep isl_pw_qpolynomial *pwqp); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_reset_domain_space( __isl_take isl_pw_qpolynomial *pwqp, __isl_take isl_space *dim); -unsigned isl_pw_qpolynomial_dim(__isl_keep isl_pw_qpolynomial *pwqp, +isl_size isl_pw_qpolynomial_dim(__isl_keep isl_pw_qpolynomial *pwqp, enum isl_dim_type type); +isl_bool isl_pw_qpolynomial_involves_param_id( + __isl_keep isl_pw_qpolynomial *pwqp, __isl_keep isl_id *id); isl_bool isl_pw_qpolynomial_involves_dims(__isl_keep isl_pw_qpolynomial *pwqp, enum isl_dim_type type, unsigned first, unsigned n); isl_bool isl_pw_qpolynomial_has_equal_space( @@ -179,6 +188,12 @@ __isl_give isl_set *isl_pw_qpolynomial_domain(__isl_take isl_pw_qpolynomial *pwqp); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_domain( __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set); +__isl_give isl_pw_qpolynomial * +isl_pw_qpolynomial_intersect_domain_wrapped_domain( + __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set); +__isl_give isl_pw_qpolynomial * +isl_pw_qpolynomial_intersect_domain_wrapped_range( + __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_intersect_params( __isl_take isl_pw_qpolynomial *pwpq, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_subtract_domain( @@ -194,6 +209,9 @@ __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_split_dims( __isl_take isl_pw_qpolynomial *pwqp, enum isl_dim_type type, unsigned first, unsigned n); + +__isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_drop_unused_params( + __isl_take isl_pw_qpolynomial *pwqp); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_add( __isl_take isl_pw_qpolynomial *pwqp1, @@ -238,7 +256,7 @@ __isl_give isl_val *isl_pw_qpolynomial_max(__isl_take isl_pw_qpolynomial *pwqp); __isl_give isl_val *isl_pw_qpolynomial_min(__isl_take isl_pw_qpolynomial *pwqp); -int isl_pw_qpolynomial_n_piece(__isl_keep isl_pw_qpolynomial *pwqp); +isl_size isl_pw_qpolynomial_n_piece(__isl_keep isl_pw_qpolynomial *pwqp); isl_stat isl_pw_qpolynomial_foreach_piece(__isl_keep isl_pw_qpolynomial *pwqp, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp, void *user), void *user); @@ -246,6 +264,10 @@ __isl_keep isl_pw_qpolynomial *pwqp, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial *qp, void *user), void *user); +isl_bool isl_pw_qpolynomial_isa_qpolynomial( + __isl_keep isl_pw_qpolynomial *pwqp); +__isl_give isl_qpolynomial *isl_pw_qpolynomial_as_qpolynomial( + __isl_take isl_pw_qpolynomial *pwqp); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_from_pw_aff( __isl_take isl_pw_aff *pwaff); @@ -285,9 +307,10 @@ enum isl_fold type, __isl_take isl_qpolynomial *qp); __isl_give isl_qpolynomial_fold *isl_qpolynomial_fold_copy( __isl_keep isl_qpolynomial_fold *fold); -void isl_qpolynomial_fold_free(__isl_take isl_qpolynomial_fold *fold); +__isl_null isl_qpolynomial_fold *isl_qpolynomial_fold_free( + __isl_take isl_qpolynomial_fold *fold); -int isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold *fold); +isl_bool isl_qpolynomial_fold_is_empty(__isl_keep isl_qpolynomial_fold *fold); isl_bool isl_qpolynomial_fold_is_nan(__isl_keep isl_qpolynomial_fold *fold); int isl_qpolynomial_fold_plain_is_equal(__isl_keep isl_qpolynomial_fold *fold1, __isl_keep isl_qpolynomial_fold *fold2); @@ -339,6 +362,8 @@ void isl_qpolynomial_fold_dump(__isl_keep isl_qpolynomial_fold *fold); isl_ctx *isl_pw_qpolynomial_fold_get_ctx(__isl_keep isl_pw_qpolynomial_fold *pwf); +enum isl_fold isl_pw_qpolynomial_fold_get_type( + __isl_keep isl_pw_qpolynomial_fold *pwf); isl_bool isl_pw_qpolynomial_fold_involves_nan( __isl_keep isl_pw_qpolynomial_fold *pwf); @@ -352,6 +377,9 @@ __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_alloc( enum isl_fold type, __isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold); +__isl_give isl_pw_qpolynomial_fold * +isl_pw_qpolynomial_fold_from_qpolynomial_fold( + __isl_take isl_qpolynomial_fold *fold); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_copy( __isl_keep isl_pw_qpolynomial_fold *pwf); __isl_null isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_free( @@ -366,8 +394,10 @@ __isl_keep isl_pw_qpolynomial_fold *pwf); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_reset_space( __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_space *dim); -unsigned isl_pw_qpolynomial_fold_dim(__isl_keep isl_pw_qpolynomial_fold *pwf, +isl_size isl_pw_qpolynomial_fold_dim(__isl_keep isl_pw_qpolynomial_fold *pwf, enum isl_dim_type type); +isl_bool isl_pw_qpolynomial_fold_involves_param_id( + __isl_keep isl_pw_qpolynomial_fold *pwf, __isl_keep isl_id *id); isl_bool isl_pw_qpolynomial_fold_has_equal_space( __isl_keep isl_pw_qpolynomial_fold *pwf1, __isl_keep isl_pw_qpolynomial_fold *pwf2); @@ -375,7 +405,7 @@ size_t isl_pw_qpolynomial_fold_size(__isl_keep isl_pw_qpolynomial_fold *pwf); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_zero( - __isl_take isl_space *dim, enum isl_fold type); + __isl_take isl_space *space, enum isl_fold type); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_set_dim_name( __isl_take isl_pw_qpolynomial_fold *pwf, @@ -392,6 +422,12 @@ __isl_take isl_pw_qpolynomial_fold *pwf); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_intersect_domain( __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set); +__isl_give isl_pw_qpolynomial_fold * +isl_pw_qpolynomial_fold_intersect_domain_wrapped_domain( + __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set); +__isl_give isl_pw_qpolynomial_fold * +isl_pw_qpolynomial_fold_intersect_domain_wrapped_range( + __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_intersect_params( __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_set *set); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_subtract_domain( @@ -422,11 +458,15 @@ __isl_take isl_pw_qpolynomial_fold *pwf, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n); + +__isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_drop_unused_params( + __isl_take isl_pw_qpolynomial_fold *pwf); __isl_give isl_val *isl_pw_qpolynomial_fold_eval( __isl_take isl_pw_qpolynomial_fold *pwf, __isl_take isl_point *pnt); -int isl_pw_qpolynomial_fold_n_piece(__isl_keep isl_pw_qpolynomial_fold *pwf); +isl_size isl_pw_qpolynomial_fold_n_piece( + __isl_keep isl_pw_qpolynomial_fold *pwf); isl_stat isl_pw_qpolynomial_fold_foreach_piece( __isl_keep isl_pw_qpolynomial_fold *pwf, isl_stat (*fn)(__isl_take isl_set *set, @@ -435,6 +475,10 @@ __isl_keep isl_pw_qpolynomial_fold *pwf, isl_stat (*fn)(__isl_take isl_set *set, __isl_take isl_qpolynomial_fold *fold, void *user), void *user); +isl_bool isl_pw_qpolynomial_fold_isa_qpolynomial_fold( + __isl_keep isl_pw_qpolynomial_fold *pwf); +__isl_give isl_qpolynomial_fold *isl_pw_qpolynomial_fold_as_qpolynomial_fold( + __isl_take isl_pw_qpolynomial_fold *pwf); __isl_give isl_printer *isl_printer_print_pw_qpolynomial_fold( __isl_take isl_printer *p, __isl_keep isl_pw_qpolynomial_fold *pwf); @@ -455,15 +499,16 @@ __isl_take isl_pw_qpolynomial_fold *pwf); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_bound( - __isl_take isl_pw_qpolynomial *pwqp, enum isl_fold type, int *tight); + __isl_take isl_pw_qpolynomial *pwqp, enum isl_fold type, + isl_bool *tight); __isl_give isl_pw_qpolynomial_fold *isl_pw_qpolynomial_fold_bound( - __isl_take isl_pw_qpolynomial_fold *pwf, int *tight); + __isl_take isl_pw_qpolynomial_fold *pwf, isl_bool *tight); __isl_give isl_pw_qpolynomial_fold *isl_set_apply_pw_qpolynomial_fold( __isl_take isl_set *set, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight); + isl_bool *tight); __isl_give isl_pw_qpolynomial_fold *isl_map_apply_pw_qpolynomial_fold( __isl_take isl_map *map, __isl_take isl_pw_qpolynomial_fold *pwf, - int *tight); + isl_bool *tight); __isl_give isl_pw_qpolynomial *isl_pw_qpolynomial_to_polynomial( __isl_take isl_pw_qpolynomial *pwqp, int sign); @@ -471,7 +516,7 @@ isl_ctx *isl_union_pw_qpolynomial_get_ctx( __isl_keep isl_union_pw_qpolynomial *upwqp); -unsigned isl_union_pw_qpolynomial_dim( +isl_size isl_union_pw_qpolynomial_dim( __isl_keep isl_union_pw_qpolynomial *upwqp, enum isl_dim_type type); isl_bool isl_union_pw_qpolynomial_involves_nan( @@ -481,8 +526,12 @@ __isl_keep isl_union_pw_qpolynomial *upwqp2); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_from_pw_qpolynomial(__isl_take isl_pw_qpolynomial *pwqp); +__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero_ctx( + isl_ctx *ctx); +__isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero_space( + __isl_take isl_space *space); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_zero( - __isl_take isl_space *dim); + __isl_take isl_space *space); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_add_pw_qpolynomial( __isl_take isl_union_pw_qpolynomial *upwqp, __isl_take isl_pw_qpolynomial *pwqp); @@ -520,6 +569,14 @@ __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_intersect_domain( __isl_take isl_union_pw_qpolynomial *upwpq, __isl_take isl_union_set *uset); +__isl_give isl_union_pw_qpolynomial * +isl_union_pw_qpolynomial_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_qpolynomial *upwpq, + __isl_take isl_union_set *uset); +__isl_give isl_union_pw_qpolynomial * +isl_union_pw_qpolynomial_intersect_domain_wrapped_range( + __isl_take isl_union_pw_qpolynomial *upwpq, + __isl_take isl_union_set *uset); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_intersect_params( __isl_take isl_union_pw_qpolynomial *upwpq, __isl_take isl_set *set); @@ -528,6 +585,9 @@ __isl_take isl_union_set *uset); __isl_give isl_space *isl_union_pw_qpolynomial_get_space( + __isl_keep isl_union_pw_qpolynomial *upwqp); +__isl_give isl_pw_qpolynomial_list * +isl_union_pw_qpolynomial_get_pw_qpolynomial_list( __isl_keep isl_union_pw_qpolynomial *upwqp); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_set_dim_name( @@ -561,7 +621,7 @@ __isl_take isl_union_pw_qpolynomial *upwqp, __isl_take isl_space *model); -int isl_union_pw_qpolynomial_n_pw_qpolynomial( +isl_size isl_union_pw_qpolynomial_n_pw_qpolynomial( __isl_keep isl_union_pw_qpolynomial *upwqp); isl_stat isl_union_pw_qpolynomial_foreach_pw_qpolynomial( __isl_keep isl_union_pw_qpolynomial *upwqp, @@ -576,7 +636,7 @@ isl_ctx *isl_union_pw_qpolynomial_fold_get_ctx( __isl_keep isl_union_pw_qpolynomial_fold *upwf); -unsigned isl_union_pw_qpolynomial_fold_dim( +isl_size isl_union_pw_qpolynomial_fold_dim( __isl_keep isl_union_pw_qpolynomial_fold *upwf, enum isl_dim_type type); isl_bool isl_union_pw_qpolynomial_fold_involves_nan( @@ -586,8 +646,13 @@ __isl_keep isl_union_pw_qpolynomial_fold *upwf2); __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_from_pw_qpolynomial_fold(__isl_take isl_pw_qpolynomial_fold *pwf); +__isl_give isl_union_pw_qpolynomial_fold * +isl_union_pw_qpolynomial_fold_zero_ctx(isl_ctx *ctx, enum isl_fold type); +__isl_give isl_union_pw_qpolynomial_fold * +isl_union_pw_qpolynomial_fold_zero_space(__isl_take isl_space *space, + enum isl_fold type); __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_zero( - __isl_take isl_space *dim, enum isl_fold type); + __isl_take isl_space *space, enum isl_fold type); __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_fold_fold_pw_qpolynomial_fold( __isl_take isl_union_pw_qpolynomial_fold *upwqp, __isl_take isl_pw_qpolynomial_fold *pwqp); @@ -615,6 +680,14 @@ __isl_take isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_union_set *uset); __isl_give isl_union_pw_qpolynomial_fold * +isl_union_pw_qpolynomial_fold_intersect_domain_wrapped_domain( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + __isl_take isl_union_set *uset); +__isl_give isl_union_pw_qpolynomial_fold * +isl_union_pw_qpolynomial_fold_intersect_domain_wrapped_range( + __isl_take isl_union_pw_qpolynomial_fold *upwf, + __isl_take isl_union_set *uset); +__isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_intersect_params( __isl_take isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_set *set); @@ -627,6 +700,9 @@ __isl_keep isl_union_pw_qpolynomial_fold *upwf); __isl_give isl_space *isl_union_pw_qpolynomial_fold_get_space( __isl_keep isl_union_pw_qpolynomial_fold *upwf); +__isl_give isl_pw_qpolynomial_fold_list * +isl_union_pw_qpolynomial_fold_get_pw_qpolynomial_fold_list( + __isl_keep isl_union_pw_qpolynomial_fold *upwf); __isl_give isl_union_pw_qpolynomial_fold * isl_union_pw_qpolynomial_fold_set_dim_name( @@ -663,7 +739,7 @@ __isl_take isl_union_pw_qpolynomial_fold *upwf, __isl_take isl_space *model); -int isl_union_pw_qpolynomial_fold_n_pw_qpolynomial_fold( +isl_size isl_union_pw_qpolynomial_fold_n_pw_qpolynomial_fold( __isl_keep isl_union_pw_qpolynomial_fold *upwf); isl_stat isl_union_pw_qpolynomial_fold_foreach_pw_qpolynomial_fold( __isl_keep isl_union_pw_qpolynomial_fold *upwf, @@ -678,16 +754,19 @@ __isl_give isl_union_pw_qpolynomial_fold *isl_union_pw_qpolynomial_bound( __isl_take isl_union_pw_qpolynomial *upwqp, - enum isl_fold type, int *tight); + enum isl_fold type, isl_bool *tight); __isl_give isl_union_pw_qpolynomial_fold *isl_union_set_apply_union_pw_qpolynomial_fold( __isl_take isl_union_set *uset, - __isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight); + __isl_take isl_union_pw_qpolynomial_fold *upwf, isl_bool *tight); __isl_give isl_union_pw_qpolynomial_fold *isl_union_map_apply_union_pw_qpolynomial_fold( __isl_take isl_union_map *umap, - __isl_take isl_union_pw_qpolynomial_fold *upwf, int *tight); + __isl_take isl_union_pw_qpolynomial_fold *upwf, isl_bool *tight); __isl_give isl_union_pw_qpolynomial *isl_union_pw_qpolynomial_to_polynomial( __isl_take isl_union_pw_qpolynomial *upwqp, int sign); + +ISL_DECLARE_LIST_FN(pw_qpolynomial) +ISL_DECLARE_LIST_FN(pw_qpolynomial_fold) #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/polynomial_type.h b/gcc/isl/include/isl/polynomial_type.h index df432bd..f260219 100644 --- a/gcc/isl/include/isl/polynomial_type.h +++ a/gcc/isl/include/isl/polynomial_type.h @@ -10,7 +10,10 @@ struct __isl_export isl_pw_qpolynomial; typedef struct isl_pw_qpolynomial isl_pw_qpolynomial; +ISL_DECLARE_LIST_TYPE(pw_qpolynomial) + enum isl_fold { + isl_fold_error = -1, isl_fold_min, isl_fold_max, isl_fold_list @@ -21,6 +24,8 @@ struct isl_pw_qpolynomial_fold; typedef struct isl_pw_qpolynomial_fold isl_pw_qpolynomial_fold; + +ISL_DECLARE_LIST_TYPE(pw_qpolynomial_fold) struct __isl_export isl_union_pw_qpolynomial; typedef struct isl_union_pw_qpolynomial isl_union_pw_qpolynomial; diff --git a/gcc/isl/include/isl/printer.h b/gcc/isl/include/isl/printer.h index dd50e91..c315954 100644 --- a/gcc/isl/include/isl/printer.h +++ a/gcc/isl/include/isl/printer.h @@ -1,10 +1,10 @@ #ifndef ISL_PRINTER_H #define ISL_PRINTER_H #include #include #include -#include +#include #if defined(__cplusplus) extern "C" { diff --git a/gcc/isl/include/isl/schedule.h b/gcc/isl/include/isl/schedule.h index b74d5ac..3792f94 100644 --- a/gcc/isl/include/isl/schedule.h +++ a/gcc/isl/include/isl/schedule.h @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include #include #include @@ -129,6 +129,7 @@ __isl_take isl_union_map *proximity); __isl_give isl_schedule *isl_schedule_empty(__isl_take isl_space *space); +__isl_export __isl_give isl_schedule *isl_schedule_from_domain( __isl_take isl_union_set *domain); __isl_give isl_schedule *isl_schedule_copy(__isl_keep isl_schedule *sched); diff --git a/gcc/isl/include/isl/schedule_node.h b/gcc/isl/include/isl/schedule_node.h index bfef140..b336003 100644 --- a/gcc/isl/include/isl/schedule_node.h +++ a/gcc/isl/include/isl/schedule_node.h @@ -5,15 +5,18 @@ #include #include #include -#include -#include +#include +#include +#include #if defined(__cplusplus) extern "C" { #endif +__isl_export __isl_give isl_schedule_node *isl_schedule_node_from_domain( __isl_take isl_union_set *domain); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_from_extension( __isl_take isl_union_map *extension); __isl_give isl_schedule_node *isl_schedule_node_copy( @@ -21,10 +24,12 @@ __isl_null isl_schedule_node *isl_schedule_node_free( __isl_take isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_is_equal(__isl_keep isl_schedule_node *node1, __isl_keep isl_schedule_node *node2); isl_ctx *isl_schedule_node_get_ctx(__isl_keep isl_schedule_node *node); +__isl_subclass(isl_schedule_node) enum isl_schedule_node_type isl_schedule_node_get_type( __isl_keep isl_schedule_node *node); enum isl_schedule_node_type isl_schedule_node_get_parent_type( @@ -33,56 +38,76 @@ __isl_give isl_schedule *isl_schedule_node_get_schedule( __isl_keep isl_schedule_node *node); +__isl_export isl_stat isl_schedule_node_foreach_descendant_top_down( __isl_keep isl_schedule_node *node, isl_bool (*fn)(__isl_keep isl_schedule_node *node, void *user), void *user); +__isl_export isl_bool isl_schedule_node_every_descendant(__isl_keep isl_schedule_node *node, isl_bool (*test)(__isl_keep isl_schedule_node *node, void *user), void *user); +__isl_export isl_stat isl_schedule_node_foreach_ancestor_top_down( __isl_keep isl_schedule_node *node, isl_stat (*fn)(__isl_keep isl_schedule_node *node, void *user), void *user); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_map_descendant_bottom_up( __isl_take isl_schedule_node *node, __isl_give isl_schedule_node *(*fn)(__isl_take isl_schedule_node *node, void *user), void *user); -int isl_schedule_node_get_tree_depth(__isl_keep isl_schedule_node *node); +__isl_export +isl_size isl_schedule_node_get_tree_depth(__isl_keep isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_has_parent(__isl_keep isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_has_children(__isl_keep isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_has_previous_sibling( __isl_keep isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_has_next_sibling(__isl_keep isl_schedule_node *node); -int isl_schedule_node_n_children(__isl_keep isl_schedule_node *node); -int isl_schedule_node_get_child_position(__isl_keep isl_schedule_node *node); -int isl_schedule_node_get_ancestor_child_position( +__isl_export +isl_size isl_schedule_node_n_children(__isl_keep isl_schedule_node *node); +__isl_export +isl_size isl_schedule_node_get_child_position( + __isl_keep isl_schedule_node *node); +__isl_export +isl_size isl_schedule_node_get_ancestor_child_position( __isl_keep isl_schedule_node *node, __isl_keep isl_schedule_node *ancestor); __isl_give isl_schedule_node *isl_schedule_node_get_child( __isl_keep isl_schedule_node *node, int pos); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_get_shared_ancestor( __isl_keep isl_schedule_node *node1, __isl_keep isl_schedule_node *node2); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_root( __isl_take isl_schedule_node *node); __isl_export __isl_give isl_schedule_node *isl_schedule_node_parent( __isl_take isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_ancestor( __isl_take isl_schedule_node *node, int generation); __isl_export __isl_give isl_schedule_node *isl_schedule_node_child( __isl_take isl_schedule_node *node, int pos); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_first_child( __isl_take isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_previous_sibling( __isl_take isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_next_sibling( __isl_take isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_is_subtree_anchored( __isl_keep isl_schedule_node *node); @@ -94,12 +119,14 @@ __isl_give isl_space *isl_schedule_node_band_get_space( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_multi_union_pw_aff *isl_schedule_node_band_get_partial_schedule( __isl_keep isl_schedule_node *node); __isl_give isl_union_map *isl_schedule_node_band_get_partial_schedule_union_map( __isl_keep isl_schedule_node *node); enum isl_ast_loop_type isl_schedule_node_band_member_get_ast_loop_type( __isl_keep isl_schedule_node *node, int pos); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_member_set_ast_loop_type( __isl_take isl_schedule_node *node, int pos, enum isl_ast_loop_type type); @@ -109,21 +136,27 @@ isl_schedule_node_band_member_set_isolate_ast_loop_type( __isl_take isl_schedule_node *node, int pos, enum isl_ast_loop_type type); +__isl_export __isl_give isl_union_set *isl_schedule_node_band_get_ast_build_options( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_set_ast_build_options( __isl_take isl_schedule_node *node, __isl_take isl_union_set *options); +__isl_export __isl_give isl_set *isl_schedule_node_band_get_ast_isolate_option( __isl_keep isl_schedule_node *node); -unsigned isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node); __isl_export +isl_size isl_schedule_node_band_n_member(__isl_keep isl_schedule_node *node); +__isl_export isl_bool isl_schedule_node_band_member_get_coincident( __isl_keep isl_schedule_node *node, int pos); __isl_export __isl_give isl_schedule_node *isl_schedule_node_band_member_set_coincident( __isl_take isl_schedule_node *node, int pos, int coincident); +__isl_export isl_bool isl_schedule_node_band_get_permutable( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_set_permutable( __isl_take isl_schedule_node *node, int permutable); @@ -132,40 +165,54 @@ isl_stat isl_options_set_tile_shift_point_loops(isl_ctx *ctx, int val); int isl_options_get_tile_shift_point_loops(isl_ctx *ctx); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_scale( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_scale_down( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_mod( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *mv); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_shift( __isl_take isl_schedule_node *node, __isl_take isl_multi_union_pw_aff *shift); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_tile( __isl_take isl_schedule_node *node, __isl_take isl_multi_val *sizes); __isl_give isl_schedule_node *isl_schedule_node_band_sink( __isl_take isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_band_split( __isl_take isl_schedule_node *node, int pos); +__isl_export __isl_give isl_set *isl_schedule_node_context_get_context( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_union_set *isl_schedule_node_domain_get_domain( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_union_map *isl_schedule_node_expansion_get_expansion( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_union_pw_multi_aff *isl_schedule_node_expansion_get_contraction( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_union_map *isl_schedule_node_extension_get_extension( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_union_set *isl_schedule_node_filter_get_filter( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_set *isl_schedule_node_guard_get_guard( __isl_keep isl_schedule_node *node); __isl_give isl_id *isl_schedule_node_mark_get_id( __isl_keep isl_schedule_node *node); -int isl_schedule_node_get_schedule_depth(__isl_keep isl_schedule_node *node); +isl_size isl_schedule_node_get_schedule_depth( + __isl_keep isl_schedule_node *node); __isl_give isl_union_set *isl_schedule_node_get_domain( __isl_keep isl_schedule_node *node); __isl_give isl_union_set *isl_schedule_node_get_universe_domain( @@ -190,20 +237,27 @@ __isl_give isl_union_pw_multi_aff *isl_schedule_node_get_subtree_contraction( __isl_keep isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_context( __isl_take isl_schedule_node *node, __isl_take isl_set *context); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_partial_schedule( __isl_take isl_schedule_node *node, __isl_take isl_multi_union_pw_aff *schedule); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_filter( __isl_take isl_schedule_node *node, __isl_take isl_union_set *filter); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_guard( __isl_take isl_schedule_node *node, __isl_take isl_set *context); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_mark( __isl_take isl_schedule_node *node, __isl_take isl_id *mark); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_sequence( __isl_take isl_schedule_node *node, __isl_take isl_union_set_list *filters); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_insert_set( __isl_take isl_schedule_node *node, __isl_take isl_union_set_list *filters); @@ -213,14 +267,18 @@ __isl_give isl_schedule_node *isl_schedule_node_delete( __isl_take isl_schedule_node *node); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_order_before( __isl_take isl_schedule_node *node, __isl_take isl_union_set *filter); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_order_after( __isl_take isl_schedule_node *node, __isl_take isl_union_set *filter); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_graft_before( __isl_take isl_schedule_node *node, __isl_take isl_schedule_node *graft); +__isl_export __isl_give isl_schedule_node *isl_schedule_node_graft_after( __isl_take isl_schedule_node *node, __isl_take isl_schedule_node *graft); diff --git a/gcc/isl/include/isl/set.h b/gcc/isl/include/isl/set.h index 16da1a7..41697b7 100644 --- a/gcc/isl/include/isl/set.h +++ a/gcc/isl/include/isl/set.h @@ -10,32 +10,35 @@ #ifndef ISL_SET_H #define ISL_SET_H +#include #include #include #include #include #include #include -#include +#include #include +#include #if defined(__cplusplus) extern "C" { #endif -unsigned isl_basic_set_n_dim(__isl_keep isl_basic_set *bset); -unsigned isl_basic_set_n_param(__isl_keep isl_basic_set *bset); -unsigned isl_basic_set_total_dim(__isl_keep const isl_basic_set *bset); -unsigned isl_basic_set_dim(__isl_keep isl_basic_set *bset, +isl_size isl_basic_set_n_dim(__isl_keep isl_basic_set *bset); +isl_size isl_basic_set_n_param(__isl_keep isl_basic_set *bset); +isl_size isl_basic_set_total_dim(__isl_keep const isl_basic_set *bset); +isl_size isl_basic_set_dim(__isl_keep isl_basic_set *bset, enum isl_dim_type type); -unsigned isl_set_n_dim(__isl_keep isl_set *set); -unsigned isl_set_n_param(__isl_keep isl_set *set); -unsigned isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type); +isl_size isl_set_n_dim(__isl_keep isl_set *set); +isl_size isl_set_n_param(__isl_keep isl_set *set); +isl_size isl_set_dim(__isl_keep isl_set *set, enum isl_dim_type type); isl_ctx *isl_basic_set_get_ctx(__isl_keep isl_basic_set *bset); isl_ctx *isl_set_get_ctx(__isl_keep isl_set *set); __isl_give isl_space *isl_basic_set_get_space(__isl_keep isl_basic_set *bset); +__isl_export __isl_give isl_space *isl_set_get_space(__isl_keep isl_set *set); __isl_give isl_set *isl_set_reset_space(__isl_take isl_set *set, __isl_take isl_space *dim); @@ -93,7 +96,8 @@ __isl_give isl_basic_set *isl_basic_set_copy(__isl_keep isl_basic_set *bset); __isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *space); __isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *space); -__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_space *dim); +__isl_give isl_basic_set *isl_basic_set_nat_universe( + __isl_take isl_space *space); __isl_give isl_basic_set *isl_basic_set_positive_orthant( __isl_take isl_space *space); void isl_basic_set_print_internal(__isl_keep isl_basic_set *bset, @@ -200,8 +204,10 @@ __isl_give isl_pw_multi_aff *isl_basic_set_partial_lexmax_pw_multi_aff( __isl_take isl_basic_set *bset, __isl_take isl_basic_set *dom, __isl_give isl_set **empty); +__isl_export __isl_give isl_pw_multi_aff *isl_set_lexmin_pw_multi_aff( __isl_take isl_set *set); +__isl_export __isl_give isl_pw_multi_aff *isl_set_lexmax_pw_multi_aff( __isl_take isl_set *set); @@ -210,16 +216,28 @@ __isl_take isl_basic_set *bset1, __isl_take isl_basic_set *bset2); -int isl_basic_set_compare_at(struct isl_basic_set *bset1, - struct isl_basic_set *bset2, int pos); +int isl_basic_set_compare_at(__isl_keep isl_basic_set *bset1, + __isl_keep isl_basic_set *bset2, int pos); int isl_set_follows_at(__isl_keep isl_set *set1, __isl_keep isl_set *set2, int pos); +__isl_export __isl_give isl_basic_set *isl_basic_set_params(__isl_take isl_basic_set *bset); __isl_give isl_basic_set *isl_basic_set_from_params( __isl_take isl_basic_set *bset); +__isl_export __isl_give isl_set *isl_set_params(__isl_take isl_set *set); __isl_give isl_set *isl_set_from_params(__isl_take isl_set *set); + +__isl_export +__isl_give isl_set *isl_set_bind(__isl_take isl_set *set, + __isl_take isl_multi_id *tuple); +__isl_export +__isl_give isl_set *isl_set_unbind_params(__isl_take isl_set *set, + __isl_take isl_multi_id *tuple); +__isl_export +__isl_give isl_map *isl_set_unbind_params_insert_domain( + __isl_take isl_set *set, __isl_take isl_multi_id *domain); isl_stat isl_basic_set_dims_get_sign(__isl_keep isl_basic_set *bset, enum isl_dim_type type, unsigned pos, unsigned n, int *signs); @@ -236,7 +254,9 @@ isl_bool isl_basic_set_plain_is_equal(__isl_keep isl_basic_set *bset1, __isl_keep isl_basic_set *bset2); +__isl_export __isl_give isl_set *isl_set_empty(__isl_take isl_space *space); +__isl_export __isl_give isl_set *isl_set_universe(__isl_take isl_space *space); __isl_give isl_set *isl_set_nat_universe(__isl_take isl_space *dim); __isl_give isl_set *isl_set_copy(__isl_keep isl_set *set); @@ -272,6 +292,7 @@ __isl_give isl_set *isl_set_union( __isl_take isl_set *set1, __isl_take isl_set *set2); +__isl_export __isl_give isl_set *isl_set_product(__isl_take isl_set *set1, __isl_take isl_set *set2); __isl_give isl_basic_set *isl_basic_set_flat_product( @@ -285,6 +306,10 @@ __isl_export __isl_give isl_set *isl_set_intersect_params(__isl_take isl_set *set, __isl_take isl_set *params); +__isl_give isl_set *isl_set_intersect_factor_domain(__isl_take isl_set *set, + __isl_take isl_set *domain); +__isl_give isl_set *isl_set_intersect_factor_range(__isl_take isl_set *set, + __isl_take isl_set *range); __isl_export __isl_give isl_set *isl_set_subtract( __isl_take isl_set *set1, @@ -295,10 +320,13 @@ __isl_give isl_set *isl_set_apply( __isl_take isl_set *set, __isl_take isl_map *map); +__isl_overload __isl_give isl_set *isl_set_preimage_multi_aff(__isl_take isl_set *set, __isl_take isl_multi_aff *ma); +__isl_overload __isl_give isl_set *isl_set_preimage_pw_multi_aff(__isl_take isl_set *set, __isl_take isl_pw_multi_aff *pma); +__isl_overload __isl_give isl_set *isl_set_preimage_multi_pw_aff(__isl_take isl_set *set, __isl_take isl_multi_pw_aff *mpa); __isl_give isl_set *isl_set_fix_val(__isl_take isl_set *set, @@ -323,8 +351,16 @@ __isl_give isl_basic_set *isl_basic_set_project_out( __isl_take isl_basic_set *bset, enum isl_dim_type type, unsigned first, unsigned n); +__isl_overload +__isl_give isl_set *isl_set_project_out_param_id(__isl_take isl_set *set, + __isl_take isl_id *id); +__isl_overload +__isl_give isl_set *isl_set_project_out_param_id_list(__isl_take isl_set *set, + __isl_take isl_id_list *list); __isl_give isl_set *isl_set_project_out(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n); +__isl_export +__isl_give isl_set *isl_set_project_out_all_params(__isl_take isl_set *set); __isl_give isl_map *isl_set_project_onto_map(__isl_take isl_set *set, enum isl_dim_type type, unsigned first, unsigned n); __isl_give isl_basic_set *isl_basic_set_remove_divs( @@ -385,6 +421,7 @@ __isl_export isl_bool isl_set_is_disjoint(__isl_keep isl_set *set1, __isl_keep isl_set *set2); +__isl_export isl_bool isl_set_is_singleton(__isl_keep isl_set *set); isl_bool isl_set_is_box(__isl_keep isl_set *set); isl_bool isl_set_has_equal_space(__isl_keep isl_set *set1, @@ -427,12 +464,6 @@ isl_stat isl_set_dim_residue_class_val(__isl_keep isl_set *set, int pos, __isl_give isl_val **modulo, __isl_give isl_val **residue); -struct isl_stride_info; -typedef struct isl_stride_info isl_stride_info; -__isl_give isl_val *isl_stride_info_get_stride(__isl_keep isl_stride_info *si); -__isl_give isl_aff *isl_stride_info_get_offset(__isl_keep isl_stride_info *si); -__isl_null isl_stride_info *isl_stride_info_free( - __isl_take isl_stride_info *si); __isl_give isl_stride_info *isl_set_get_stride_info(__isl_keep isl_set *set, int pos); __isl_export @@ -449,13 +480,14 @@ uint32_t isl_set_get_hash(struct isl_set *set); -int isl_set_n_basic_set(__isl_keep isl_set *set); +isl_size isl_set_n_basic_set(__isl_keep isl_set *set); __isl_export isl_stat isl_set_foreach_basic_set(__isl_keep isl_set *set, isl_stat (*fn)(__isl_take isl_basic_set *bset, void *user), void *user); __isl_give isl_basic_set_list *isl_set_get_basic_set_list( __isl_keep isl_set *set); +__isl_export isl_stat isl_set_foreach_point(__isl_keep isl_set *set, isl_stat (*fn)(__isl_take isl_point *pnt, void *user), void *user); __isl_give isl_val *isl_set_count_val(__isl_keep isl_set *set); @@ -487,6 +519,9 @@ __isl_take isl_basic_set *bset, __isl_take isl_space *model); __isl_give isl_set *isl_set_align_params(__isl_take isl_set *set, __isl_take isl_space *model); +__isl_give isl_basic_set *isl_basic_set_drop_unused_params( + __isl_take isl_basic_set *bset); +__isl_give isl_set *isl_set_drop_unused_params(__isl_take isl_set *set); __isl_give isl_mat *isl_basic_set_equalities_matrix( __isl_keep isl_basic_set *bset, enum isl_dim_type c1, @@ -498,6 +533,11 @@ __isl_take isl_space *dim, __isl_take isl_mat *eq, __isl_take isl_mat *ineq, enum isl_dim_type c1, enum isl_dim_type c2, enum isl_dim_type c3, enum isl_dim_type c4); + +__isl_give isl_basic_set *isl_basic_set_from_multi_aff( + __isl_take isl_multi_aff *ma); + +__isl_give isl_set *isl_set_from_multi_aff(__isl_take isl_multi_aff *ma); __isl_give isl_mat *isl_basic_set_reduced_basis(__isl_keep isl_basic_set *bset); diff --git a/gcc/isl/include/isl/space.h b/gcc/isl/include/isl/space.h index e7f959b..e8c7cb6 100644 --- a/gcc/isl/include/isl/space.h +++ a/gcc/isl/include/isl/space.h @@ -11,27 +11,17 @@ #define ISL_SPACE_H #include -#include +#include +#include #include #if defined(__cplusplus) extern "C" { #endif -struct isl_space; -typedef struct isl_space isl_space; - -enum isl_dim_type { - isl_dim_cst, - isl_dim_param, - isl_dim_in, - isl_dim_out, - isl_dim_set = isl_dim_out, - isl_dim_div, - isl_dim_all -}; - -isl_ctx *isl_space_get_ctx(__isl_keep isl_space *dim); +isl_ctx *isl_space_get_ctx(__isl_keep isl_space *space); +__isl_export +__isl_give isl_space *isl_space_unit(isl_ctx *ctx); __isl_give isl_space *isl_space_alloc(isl_ctx *ctx, unsigned nparam, unsigned n_in, unsigned n_out); __isl_give isl_space *isl_space_set_alloc(isl_ctx *ctx, @@ -47,40 +37,40 @@ __isl_give isl_space *isl_space_add_param_id(__isl_take isl_space *space, __isl_take isl_id *id); -__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_tuple_name(__isl_take isl_space *space, enum isl_dim_type type, const char *s); isl_bool isl_space_has_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type); -__isl_keep const char *isl_space_get_tuple_name(__isl_keep isl_space *dim, +__isl_keep const char *isl_space_get_tuple_name(__isl_keep isl_space *space, enum isl_dim_type type); -__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_tuple_id(__isl_take isl_space *space, enum isl_dim_type type, __isl_take isl_id *id); -__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_reset_tuple_id(__isl_take isl_space *space, enum isl_dim_type type); -isl_bool isl_space_has_tuple_id(__isl_keep isl_space *dim, +isl_bool isl_space_has_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type); -__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *dim, +__isl_give isl_id *isl_space_get_tuple_id(__isl_keep isl_space *space, enum isl_dim_type type); __isl_give isl_space *isl_space_reset_user(__isl_take isl_space *space); __isl_give isl_space *isl_space_set_dim_id(__isl_take isl_space *dim, enum isl_dim_type type, unsigned pos, __isl_take isl_id *id); -isl_bool isl_space_has_dim_id(__isl_keep isl_space *dim, +isl_bool isl_space_has_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos); -__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *dim, +__isl_give isl_id *isl_space_get_dim_id(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos); -int isl_space_find_dim_by_id(__isl_keep isl_space *dim, enum isl_dim_type type, - __isl_keep isl_id *id); +int isl_space_find_dim_by_id(__isl_keep isl_space *space, + enum isl_dim_type type, __isl_keep isl_id *id); int isl_space_find_dim_by_name(__isl_keep isl_space *space, enum isl_dim_type type, const char *name); isl_bool isl_space_has_dim_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos); -__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_set_dim_name(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, __isl_keep const char *name); -__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *dim, +__isl_keep const char *isl_space_get_dim_name(__isl_keep isl_space *space, enum isl_dim_type type, unsigned pos); ISL_DEPRECATED @@ -91,7 +81,7 @@ __isl_give isl_space *isl_space_move_dims(__isl_take isl_space *space, enum isl_dim_type dst_type, unsigned dst_pos, enum isl_dim_type src_type, unsigned src_pos, unsigned n); -__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_insert_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned pos, unsigned n); __isl_give isl_space *isl_space_join(__isl_take isl_space *left, __isl_take isl_space *right); @@ -111,11 +101,13 @@ __isl_take isl_space *space); __isl_give isl_space *isl_space_range_factor_range( __isl_take isl_space *space); +__isl_export __isl_give isl_space *isl_space_map_from_set(__isl_take isl_space *space); __isl_give isl_space *isl_space_map_from_domain_and_range( __isl_take isl_space *domain, __isl_take isl_space *range); -__isl_give isl_space *isl_space_reverse(__isl_take isl_space *dim); -__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *dim, +__isl_give isl_space *isl_space_reverse(__isl_take isl_space *space); +__isl_give isl_space *isl_space_range_reverse(__isl_take isl_space *space); +__isl_give isl_space *isl_space_drop_dims(__isl_take isl_space *space, enum isl_dim_type type, unsigned first, unsigned num); ISL_DEPRECATED __isl_give isl_space *isl_space_drop_inputs(__isl_take isl_space *dim, @@ -123,27 +115,40 @@ ISL_DEPRECATED __isl_give isl_space *isl_space_drop_outputs(__isl_take isl_space *dim, unsigned first, unsigned n); +__isl_give isl_space *isl_space_drop_all_params(__isl_take isl_space *space); +__isl_export __isl_give isl_space *isl_space_domain(__isl_take isl_space *space); -__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_from_domain(__isl_take isl_space *space); +__isl_export __isl_give isl_space *isl_space_range(__isl_take isl_space *space); -__isl_give isl_space *isl_space_from_range(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_from_range(__isl_take isl_space *space); __isl_give isl_space *isl_space_domain_map(__isl_take isl_space *space); __isl_give isl_space *isl_space_range_map(__isl_take isl_space *space); +__isl_export __isl_give isl_space *isl_space_params(__isl_take isl_space *space); +__isl_overload +__isl_give isl_space *isl_space_add_unnamed_tuple_ui( + __isl_take isl_space *space, unsigned dim); +__isl_overload +__isl_give isl_space *isl_space_add_named_tuple_id_ui( + __isl_take isl_space *space, __isl_take isl_id *tuple_id, unsigned dim); __isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space); __isl_give isl_space *isl_space_align_params(__isl_take isl_space *dim1, __isl_take isl_space *dim2); -isl_bool isl_space_is_wrapping(__isl_keep isl_space *dim); +__isl_export +isl_bool isl_space_is_wrapping(__isl_keep isl_space *space); isl_bool isl_space_domain_is_wrapping(__isl_keep isl_space *space); isl_bool isl_space_range_is_wrapping(__isl_keep isl_space *space); isl_bool isl_space_is_product(__isl_keep isl_space *space); -__isl_give isl_space *isl_space_wrap(__isl_take isl_space *dim); -__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *dim); +__isl_export +__isl_give isl_space *isl_space_wrap(__isl_take isl_space *space); +__isl_export +__isl_give isl_space *isl_space_unwrap(__isl_take isl_space *space); isl_bool isl_space_can_zip(__isl_keep isl_space *space); -__isl_give isl_space *isl_space_zip(__isl_take isl_space *dim); +__isl_give isl_space *isl_space_zip(__isl_take isl_space *space); isl_bool isl_space_can_curry(__isl_keep isl_space *space); __isl_give isl_space *isl_space_curry(__isl_take isl_space *space); @@ -158,6 +163,7 @@ __isl_keep isl_space *space2); isl_bool isl_space_is_range(__isl_keep isl_space *space1, __isl_keep isl_space *space2); +__isl_export isl_bool isl_space_is_equal(__isl_keep isl_space *space1, __isl_keep isl_space *space2); isl_bool isl_space_has_equal_params(__isl_keep isl_space *space1, @@ -170,15 +176,17 @@ ISL_DEPRECATED isl_bool isl_space_match(__isl_keep isl_space *space1, enum isl_dim_type type1, __isl_keep isl_space *space2, enum isl_dim_type type2); -unsigned isl_space_dim(__isl_keep isl_space *dim, enum isl_dim_type type); +isl_size isl_space_dim(__isl_keep isl_space *space, enum isl_dim_type type); +__isl_export __isl_give isl_space *isl_space_flatten_domain(__isl_take isl_space *space); +__isl_export __isl_give isl_space *isl_space_flatten_range(__isl_take isl_space *space); __isl_give char *isl_space_to_str(__isl_keep isl_space *space); __isl_give isl_printer *isl_printer_print_space(__isl_take isl_printer *p, - __isl_keep isl_space *dim); -void isl_space_dump(__isl_keep isl_space *dim); + __isl_keep isl_space *space); +void isl_space_dump(__isl_keep isl_space *space); #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/stream.h b/gcc/isl/include/isl/stream.h index b0eb096..38888d3 100644 --- a/gcc/isl/include/isl/stream.h +++ a/gcc/isl/include/isl/stream.h @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #if defined(__cplusplus) diff --git a/gcc/isl/include/isl/union_map.h b/gcc/isl/include/isl/union_map.h index 19d11b7..0ceb4d9 100644 --- a/gcc/isl/include/isl/union_map.h +++ a/gcc/isl/include/isl/union_map.h @@ -1,18 +1,19 @@ #ifndef ISL_UNION_MAP_H #define ISL_UNION_MAP_H -#include +#include +#include #include #include #include #include -#include +#include #if defined(__cplusplus) extern "C" { #endif -unsigned isl_union_map_dim(__isl_keep isl_union_map *umap, +isl_size isl_union_map_dim(__isl_keep isl_union_map *umap, enum isl_dim_type type); isl_bool isl_union_map_involves_dims(__isl_keep isl_union_map *umap, enum isl_dim_type type, unsigned first, unsigned n); @@ -24,11 +25,16 @@ __isl_take isl_basic_map *bmap); __isl_constructor __isl_give isl_union_map *isl_union_map_from_map(__isl_take isl_map *map); +__isl_overload +__isl_give isl_union_map *isl_union_map_empty_ctx(isl_ctx *ctx); +__isl_give isl_union_map *isl_union_map_empty_space( + __isl_take isl_space *space); __isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *space); __isl_give isl_union_map *isl_union_map_copy(__isl_keep isl_union_map *umap); __isl_null isl_union_map *isl_union_map_free(__isl_take isl_union_map *umap); isl_ctx *isl_union_map_get_ctx(__isl_keep isl_union_map *umap); +__isl_export __isl_give isl_space *isl_union_map_get_space(__isl_keep isl_union_map *umap); __isl_give isl_union_map *isl_union_map_reset_user( @@ -37,6 +43,7 @@ int isl_union_map_find_dim_by_name(__isl_keep isl_union_map *umap, enum isl_dim_type type, const char *name); +__isl_export __isl_give isl_union_map *isl_union_map_universe( __isl_take isl_union_map *umap); __isl_give isl_set *isl_union_map_params(__isl_take isl_union_map *umap); @@ -147,6 +154,10 @@ __isl_export __isl_give isl_union_map *isl_union_map_intersect_range( __isl_take isl_union_map *umap, __isl_take isl_union_set *uset); +__isl_give isl_union_map *isl_union_map_intersect_domain_factor_range( + __isl_take isl_union_map *umap, __isl_take isl_union_map *factor); +__isl_give isl_union_map *isl_union_map_intersect_range_factor_domain( + __isl_take isl_union_map *umap, __isl_take isl_union_map *factor); __isl_give isl_union_map *isl_union_map_intersect_range_factor_range( __isl_take isl_union_map *umap, __isl_take isl_union_map *factor); @@ -163,24 +174,33 @@ __isl_export __isl_give isl_union_map *isl_union_map_apply_range( __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_domain_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_multi_aff *ma); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_range_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_multi_aff *ma); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_domain_pw_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_pw_multi_aff *pma); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_range_pw_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_pw_multi_aff *pma); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_domain_multi_pw_aff( __isl_take isl_union_map *umap, __isl_take isl_multi_pw_aff *mpa); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_domain_union_pw_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_union_pw_multi_aff *upma); +__isl_overload __isl_give isl_union_map *isl_union_map_preimage_range_union_pw_multi_aff( __isl_take isl_union_map *umap, __isl_take isl_union_pw_multi_aff *upma); __isl_export __isl_give isl_union_map *isl_union_map_reverse(__isl_take isl_union_map *umap); +__isl_give isl_union_map *isl_union_map_range_reverse( + __isl_take isl_union_map *umap); __isl_export __isl_give isl_union_map *isl_union_map_from_domain_and_range( __isl_take isl_union_set *domain, __isl_take isl_union_set *range); @@ -204,6 +224,10 @@ __isl_give isl_union_map *isl_union_map_remove_divs( __isl_take isl_union_map *bmap); +__isl_export +__isl_give isl_union_set *isl_union_map_bind_range( + __isl_take isl_union_map *umap, __isl_take isl_multi_id *tuple); + isl_bool isl_union_map_plain_is_empty(__isl_keep isl_union_map *umap); __isl_export isl_bool isl_union_map_is_empty(__isl_keep isl_union_map *umap); @@ -222,6 +246,7 @@ __isl_export isl_bool isl_union_map_is_equal(__isl_keep isl_union_map *umap1, __isl_keep isl_union_map *umap2); +__isl_export isl_bool isl_union_map_is_disjoint(__isl_keep isl_union_map *umap1, __isl_keep isl_union_map *umap2); __isl_export @@ -230,10 +255,13 @@ uint32_t isl_union_map_get_hash(__isl_keep isl_union_map *umap); -int isl_union_map_n_map(__isl_keep isl_union_map *umap); +isl_size isl_union_map_n_map(__isl_keep isl_union_map *umap); __isl_export isl_stat isl_union_map_foreach_map(__isl_keep isl_union_map *umap, isl_stat (*fn)(__isl_take isl_map *map, void *user), void *user); +__isl_give isl_map_list *isl_union_map_get_map_list( + __isl_keep isl_union_map *umap); +__isl_export isl_bool isl_union_map_every_map(__isl_keep isl_union_map *umap, isl_bool (*test)(__isl_keep isl_map *map, void *user), void *user); __isl_give isl_union_map *isl_union_map_remove_map_if( @@ -241,8 +269,11 @@ isl_bool (*fn)(__isl_keep isl_map *map, void *user), void *user); isl_bool isl_union_map_contains(__isl_keep isl_union_map *umap, __isl_keep isl_space *space); +__isl_export __isl_give isl_map *isl_union_map_extract_map(__isl_keep isl_union_map *umap, __isl_take isl_space *dim); +__isl_export +isl_bool isl_union_map_isa_map(__isl_keep isl_union_map *umap); __isl_give isl_map *isl_map_from_union_map(__isl_take isl_union_map *umap); __isl_give isl_basic_map *isl_union_map_sample(__isl_take isl_union_map *umap); @@ -251,9 +282,9 @@ __isl_give isl_union_map *isl_union_map_fixed_power_val( __isl_take isl_union_map *umap, __isl_take isl_val *exp); __isl_give isl_union_map *isl_union_map_power(__isl_take isl_union_map *umap, - int *exact); + isl_bool *exact); __isl_give isl_union_map *isl_union_map_transitive_closure( - __isl_take isl_union_map *umap, int *exact); + __isl_take isl_union_map *umap, isl_bool *exact); __isl_give isl_union_map *isl_union_map_lex_lt_union_map( __isl_take isl_union_map *umap1, __isl_take isl_union_map *umap2); @@ -292,9 +323,11 @@ __isl_export __isl_give isl_union_map *isl_union_map_zip(__isl_take isl_union_map *umap); +__isl_export __isl_give isl_union_map *isl_union_map_curry(__isl_take isl_union_map *umap); __isl_give isl_union_map *isl_union_map_range_curry( __isl_take isl_union_map *umap); +__isl_export __isl_give isl_union_map *isl_union_map_uncurry(__isl_take isl_union_map *umap); __isl_give isl_union_map *isl_union_map_align_params( diff --git a/gcc/isl/include/isl/union_map_type.h b/gcc/isl/include/isl/union_map_type.h index 72fdffd..7b6e69f 100644 --- a/gcc/isl/include/isl/union_map_type.h +++ a/gcc/isl/include/isl/union_map_type.h @@ -14,7 +14,7 @@ #ifndef isl_union_set struct __isl_export isl_union_set; typedef struct isl_union_set isl_union_set; -ISL_DECLARE_LIST_TYPE(union_set) +ISL_DECLARE_EXPORTED_LIST_TYPE(union_set) #endif #if defined(__cplusplus) diff --git a/gcc/isl/include/isl/union_set.h b/gcc/isl/include/isl/union_set.h index 289693b..0a6f423 100644 --- a/gcc/isl/include/isl/union_set.h +++ a/gcc/isl/include/isl/union_set.h @@ -8,7 +8,7 @@ extern "C" { #endif -unsigned isl_union_set_dim(__isl_keep isl_union_set *uset, +isl_size isl_union_set_dim(__isl_keep isl_union_set *uset, enum isl_dim_type type); __isl_constructor @@ -16,16 +16,22 @@ __isl_take isl_basic_set *bset); __isl_constructor __isl_give isl_union_set *isl_union_set_from_set(__isl_take isl_set *set); +__isl_overload +__isl_give isl_union_set *isl_union_set_empty_ctx(isl_ctx *ctx); +__isl_give isl_union_set *isl_union_set_empty_space( + __isl_take isl_space *space); __isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *space); __isl_give isl_union_set *isl_union_set_copy(__isl_keep isl_union_set *uset); __isl_null isl_union_set *isl_union_set_free(__isl_take isl_union_set *uset); isl_ctx *isl_union_set_get_ctx(__isl_keep isl_union_set *uset); +__isl_export __isl_give isl_space *isl_union_set_get_space(__isl_keep isl_union_set *uset); __isl_give isl_union_set *isl_union_set_reset_user( __isl_take isl_union_set *uset); +__isl_export __isl_give isl_union_set *isl_union_set_universe( __isl_take isl_union_set *uset); __isl_give isl_set *isl_union_set_params(__isl_take isl_union_set *uset); @@ -94,6 +100,8 @@ __isl_give isl_union_set *isl_union_set_project_out( __isl_take isl_union_set *uset, enum isl_dim_type type, unsigned first, unsigned n); +__isl_give isl_union_set *isl_union_set_project_out_all_params( + __isl_take isl_union_set *uset); __isl_give isl_union_set *isl_union_set_remove_divs( __isl_take isl_union_set *bset); @@ -107,6 +115,7 @@ __isl_export isl_bool isl_union_set_is_equal(__isl_keep isl_union_set *uset1, __isl_keep isl_union_set *uset2); +__isl_export isl_bool isl_union_set_is_disjoint(__isl_keep isl_union_set *uset1, __isl_keep isl_union_set *uset2); __isl_export @@ -115,16 +124,24 @@ uint32_t isl_union_set_get_hash(__isl_keep isl_union_set *uset); -int isl_union_set_n_set(__isl_keep isl_union_set *uset); +isl_size isl_union_set_n_set(__isl_keep isl_union_set *uset); __isl_export isl_stat isl_union_set_foreach_set(__isl_keep isl_union_set *uset, isl_stat (*fn)(__isl_take isl_set *set, void *user), void *user); +__isl_export +isl_bool isl_union_set_every_set(__isl_keep isl_union_set *uset, + isl_bool (*test)(__isl_keep isl_set *set, void *user), void *user); __isl_give isl_basic_set_list *isl_union_set_get_basic_set_list( __isl_keep isl_union_set *uset); +__isl_give isl_set_list *isl_union_set_get_set_list( + __isl_keep isl_union_set *uset); isl_bool isl_union_set_contains(__isl_keep isl_union_set *uset, __isl_keep isl_space *space); +__isl_export __isl_give isl_set *isl_union_set_extract_set(__isl_keep isl_union_set *uset, __isl_take isl_space *dim); +__isl_export +isl_bool isl_union_set_isa_set(__isl_keep isl_union_set *uset); __isl_give isl_set *isl_set_from_union_set(__isl_take isl_union_set *uset); __isl_export isl_stat isl_union_set_foreach_point(__isl_keep isl_union_set *uset, @@ -164,7 +181,7 @@ __isl_keep isl_union_set *uset); void isl_union_set_dump(__isl_keep isl_union_set *uset); -ISL_DECLARE_LIST_FN(union_set) +ISL_DECLARE_EXPORTED_LIST_FN(union_set) __isl_give isl_union_set *isl_union_set_list_union( __isl_take isl_union_set_list *list); diff --git a/gcc/isl/include/isl/val.h b/gcc/isl/include/isl/val.h index fb50eaa..284fcd2 100644 --- a/gcc/isl/include/isl/val.h +++ a/gcc/isl/include/isl/val.h @@ -1,26 +1,24 @@ #ifndef ISL_VAL_H #define ISL_VAL_H +#include #include #include #include #include +#include #if defined(__cplusplus) extern "C" { #endif -struct __isl_export isl_val; -typedef struct isl_val isl_val; - -ISL_DECLARE_LIST(val) - -struct __isl_export isl_multi_val; -typedef struct isl_multi_val isl_multi_val; - ISL_DECLARE_MULTI(val) -ISL_DECLARE_MULTI_NEG(val) +ISL_DECLARE_MULTI_ARITH(val) +ISL_DECLARE_MULTI_ZERO(val) +ISL_DECLARE_MULTI_NAN(val) ISL_DECLARE_MULTI_DIMS(val) +ISL_DECLARE_MULTI_DIM_ID(val) +ISL_DECLARE_MULTI_TUPLE_ID(val) ISL_DECLARE_MULTI_WITH_DOMAIN(val) __isl_export @@ -46,12 +44,14 @@ isl_ctx *isl_val_get_ctx(__isl_keep isl_val *val); uint32_t isl_val_get_hash(__isl_keep isl_val *val); +__isl_export long isl_val_get_num_si(__isl_keep isl_val *v); +__isl_export long isl_val_get_den_si(__isl_keep isl_val *v); __isl_give isl_val *isl_val_get_den_val(__isl_keep isl_val *v); double isl_val_get_d(__isl_keep isl_val *v); -size_t isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size); -int isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, +isl_size isl_val_n_abs_num_chunks(__isl_keep isl_val *v, size_t size); +isl_stat isl_val_get_abs_num_chunks(__isl_keep isl_val *v, size_t size, void *chunks); __isl_give isl_val *isl_val_set_si(__isl_take isl_val *v, long i); @@ -69,6 +69,8 @@ __isl_export __isl_give isl_val *isl_val_trunc(__isl_take isl_val *v); __isl_give isl_val *isl_val_2exp(__isl_take isl_val *v); +__isl_export +__isl_give isl_val *isl_val_pow2(__isl_take isl_val *v); __isl_export __isl_give isl_val *isl_val_min(__isl_take isl_val *v1, __isl_take isl_val *v2); __isl_export @@ -128,6 +130,7 @@ isl_bool isl_val_le(__isl_keep isl_val *v1, __isl_keep isl_val *v2); __isl_export isl_bool isl_val_gt(__isl_keep isl_val *v1, __isl_keep isl_val *v2); +isl_bool isl_val_gt_si(__isl_keep isl_val *v, long i); __isl_export isl_bool isl_val_ge(__isl_keep isl_val *v1, __isl_keep isl_val *v2); __isl_export @@ -148,17 +151,21 @@ void isl_val_dump(__isl_keep isl_val *v); __isl_give char *isl_val_to_str(__isl_keep isl_val *v); +__isl_overload __isl_give isl_multi_val *isl_multi_val_add_val(__isl_take isl_multi_val *mv, __isl_take isl_val *v); __isl_give isl_multi_val *isl_multi_val_mod_val(__isl_take isl_multi_val *mv, __isl_take isl_val *v); +__isl_constructor __isl_give isl_multi_val *isl_multi_val_read_from_str(isl_ctx *ctx, const char *str); __isl_give isl_printer *isl_printer_print_multi_val(__isl_take isl_printer *p, __isl_keep isl_multi_val *mv); void isl_multi_val_dump(__isl_keep isl_multi_val *mv); __isl_give char *isl_multi_val_to_str(__isl_keep isl_multi_val *mv); + +ISL_DECLARE_EXPORTED_LIST_FN(val) #if defined(__cplusplus) } diff --git a/gcc/isl/include/isl/val_gmp.h b/gcc/isl/include/isl/val_gmp.h index 9558c1a..dbc1501 100644 --- a/gcc/isl/include/isl/val_gmp.h +++ a/gcc/isl/include/isl/val_gmp.h @@ -1,8 +1,8 @@ #ifndef ISL_VAL_GMP_H #define ISL_VAL_GMP_H #include -#include +#include #if defined(__cplusplus) extern "C" { diff --git a/gcc/isl/include/isl/vec.h b/gcc/isl/include/isl/vec.h index 19b5579..6baa87b 100644 --- a/gcc/isl/include/isl/vec.h +++ a/gcc/isl/include/isl/vec.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #if defined(__cplusplus) @@ -30,7 +30,7 @@ isl_ctx *isl_vec_get_ctx(__isl_keep isl_vec *vec); -int isl_vec_size(__isl_keep isl_vec *vec); +isl_size isl_vec_size(__isl_keep isl_vec *vec); __isl_give isl_val *isl_vec_get_element_val(__isl_keep isl_vec *vec, int pos); __isl_give isl_vec *isl_vec_set_element_si(__isl_take isl_vec *vec, int pos, int v); @@ -65,6 +65,7 @@ __isl_give isl_vec *isl_vec_drop_els(__isl_take isl_vec *vec, unsigned pos, unsigned n); +__isl_give isl_vec *isl_vec_add_els(__isl_take isl_vec *vec, unsigned n); __isl_give isl_vec *isl_vec_insert_els(__isl_take isl_vec *vec, unsigned pos, unsigned n); __isl_give isl_vec *isl_vec_insert_zero_els(__isl_take isl_vec *vec, diff --git a/gcc/isl/include/isl/vertices.h b/gcc/isl/include/isl/vertices.h index 6a7ee6a..9a7ac50 100644 --- a/gcc/isl/include/isl/vertices.h +++ a/gcc/isl/include/isl/vertices.h @@ -18,15 +18,15 @@ typedef struct isl_vertices isl_vertices; isl_ctx *isl_vertex_get_ctx(__isl_keep isl_vertex *vertex); -int isl_vertex_get_id(__isl_keep isl_vertex *vertex); +isl_size isl_vertex_get_id(__isl_keep isl_vertex *vertex); __isl_give isl_basic_set *isl_vertex_get_domain(__isl_keep isl_vertex *vertex); __isl_give isl_multi_aff *isl_vertex_get_expr(__isl_keep isl_vertex *vertex); -void isl_vertex_free(__isl_take isl_vertex *vertex); +__isl_null isl_vertex *isl_vertex_free(__isl_take isl_vertex *vertex); __isl_give isl_vertices *isl_basic_set_compute_vertices( __isl_keep isl_basic_set *bset); isl_ctx *isl_vertices_get_ctx(__isl_keep isl_vertices *vertices); -int isl_vertices_get_n_vertices(__isl_keep isl_vertices *vertices); +isl_size isl_vertices_get_n_vertices(__isl_keep isl_vertices *vertices); isl_stat isl_vertices_foreach_vertex(__isl_keep isl_vertices *vertices, isl_stat (*fn)(__isl_take isl_vertex *vertex, void *user), void *user); __isl_null isl_vertices *isl_vertices_free(__isl_take isl_vertices *vertices); @@ -35,7 +35,7 @@ __isl_give isl_basic_set *isl_cell_get_domain(__isl_keep isl_cell *cell); isl_stat isl_cell_foreach_vertex(__isl_keep isl_cell *cell, isl_stat (*fn)(__isl_take isl_vertex *vertex, void *user), void *user); -void isl_cell_free(__isl_take isl_cell *cell); +__isl_null isl_cell *isl_cell_free(__isl_take isl_cell *cell); isl_stat isl_vertices_foreach_cell(__isl_keep isl_vertices *vertices, isl_stat (*fn)(__isl_take isl_cell *cell, void *user), void *user); diff --git a/gcc/isl/test_inputs/codegen/correlation.c b/gcc/isl/test_inputs/codegen/correlation.c index e771b43..8285005 100644 --- a/gcc/isl/test_inputs/codegen/correlation.c +++ a/gcc/isl/test_inputs/codegen/correlation.c @@ -1,5 +1,5 @@ for (int c0 = 0; c0 < m; c0 += 32) - for (int c1 = (n >= 32 && m >= c0 + 2) || (m == 1 && c0 == 0) ? 0 : 32 * n - 32 * floord(31 * n + 31, 32); c1 <= ((n <= -1 && c0 == 0) || (m == 1 && n >= 0 && c0 == 0) ? max(0, n - 1) : n); c1 += 32) + for (int c1 = (n >= 32 && m >= c0 + 2) || (m == 1 && c0 == 0) ? 0 : 32 * n - 32 * floord(31 * n + 31, 32); c1 <= ((n <= 0 && c0 == 0) || (m == 1 && n >= 1 && c0 == 0) ? max(0, n - 1) : n); c1 += 32) for (int c2 = c0; c2 <= (m >= 2 && c0 + 31 >= m && n >= c1 && c1 + 31 >= n ? 2 * m - 3 : (m >= 2 * c0 + 63 && c1 <= -32 && n >= c1 && c1 + 31 >= n) || (m >= c0 + 32 && 2 * c0 + 62 >= m && n >= c1 && c1 + 31 >= n) || (n >= 0 && c0 >= 32 && m >= 2 * c0 + 63 && c1 == n) || (m >= 63 && n >= 32 && c0 == 0 && c1 == n) ? 2 * c0 + 61 : m - 1); c2 += 32) { if (n >= c1 + 32 && c1 >= 0 && 2 * c0 >= c2 + 32) { for (int c4 = 0; c4 <= 31; c4 += 1) diff --git a/gcc/isl/test_inputs/codegen/shift2.c b/gcc/isl/test_inputs/codegen/shift2.c index a0571c9..04831a0 100644 --- a/gcc/isl/test_inputs/codegen/shift2.c +++ a/gcc/isl/test_inputs/codegen/shift2.c @@ -45,12 +45,9 @@ if (c1 == 0 && length % 32 == 0) S_4(c0); } - if (length <= 1) - for (int c5 = 0; c5 <= length; c5 += 1) { - if (c5 == length) { - S_4(c0); - } else { - S_0(c0, 0, 0); - } - } + if (length <= 1) { + if (length == 1) + S_0(c0, 0, 0); + S_4(c0); + } } diff --git a/gcc/isl/test_inputs/codegen/stride7.c b/gcc/isl/test_inputs/codegen/stride7.c index b64c66d..b9d3127 100644 --- a/gcc/isl/test_inputs/codegen/stride7.c +++ a/gcc/isl/test_inputs/codegen/stride7.c @@ -1,6 +1,8 @@ -for (int c0 = 2; c0 <= 200; c0 += 64) { - for (int c2 = c0 - 1; c2 <= 120; c2 += 1) - s2(c0, c2); - for (int c2 = 122; c2 <= c0 + 62; c2 += 1) - s4(c0, c2); +{ + for (int c0 = 2; c0 <= 100; c0 += 64) + for (int c2 = c0 - 1; c2 <= 120; c2 += 1) + s2(c0, c2); + for (int c0 = 66; c0 <= 200; c0 += 64) + for (int c2 = 122; c2 <= c0 + 62; c2 += 1) + s4(c0, c2); } diff --git a/gcc/isl/test_inputs/codegen/unroll4.c b/gcc/isl/test_inputs/codegen/unroll4.c index 6d4c341..1e7eccc 100644 --- a/gcc/isl/test_inputs/codegen/unroll4.c +++ a/gcc/isl/test_inputs/codegen/unroll4.c @@ -1,15 +1,15 @@ { write_shared_A(3, ((t1 + 3) % 4) + 1, ((t2 + 31) % 32) + 1); if (t2 >= 1 && t2 <= 2 && t1 % 3 == 0) write_shared_A(3, (-t1 / 3) + 4, t2 + 32); - if (((-((t1 + 3) % 4) + t2 + 30) % 32) + t1 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) - 4 * ((-t1 + 4) / 4) + 1) + if (((t1 + 3) % 4) + 1 >= t2 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2) write_shared_A(3, ((t1 + 3) % 4) + 5, -((((t1 + 3) % 4) - t2 + 33) % 32) + t1 + 4 * ((-t1 + 4) / 4) + 32); if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4) write_shared_A(3, t1 + 4, t2 + 32); write_shared_A(4, ((t1 + 3) % 4) + 1, ((t2 + 31) % 32) + 1); if (t2 >= 1 && t2 <= 2 && t1 % 3 == 0) write_shared_A(4, (-t1 / 3) + 4, t2 + 32); - if (((-((t1 + 3) % 4) + t2 + 30) % 32) + t1 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) - 4 * ((-t1 + 4) / 4) + 1) + if (((t1 + 3) % 4) + 1 >= t2 || t2 >= ((t1 + 3) % 4) + ((t2 + 1) % 2) + 2) write_shared_A(4, ((t1 + 3) % 4) + 5, -((((t1 + 3) % 4) - t2 + 33) % 32) + t1 + 4 * ((-t1 + 4) / 4) + 32); if (t1 >= 1 && t2 >= t1 + 1 && t2 <= 4) write_shared_A(4, t1 + 4, t2 + 32); diff --git a/gcc/isl/test_inputs/codegen/cloog/classen.c b/gcc/isl/test_inputs/codegen/cloog/classen.c index 3155aa7..0201766 100644 --- a/gcc/isl/test_inputs/codegen/cloog/classen.c +++ a/gcc/isl/test_inputs/codegen/cloog/classen.c @@ -1,86 +1,63 @@ if (m >= 1) { - if (m == 1) { - S1(0, 1, 1, 1); - S8(0, 1); - } else { - S1(0, 1, 1, 1); + S1(0, 1, 1, 1); + if (m >= 2) { S2(0, 1, 1, 1, 1, 1, 2, 1); S3(0, 1, 1, 2, 1, 1, 1, 2); S4(0, 1, 2, 2, 1, 1, 2, 2); - S8(0, 1); } - for (int c0 = 1; c0 < 2 * m - 3; c0 += 1) { - if (c0 + 1 == m) { - S5(m - 2, 1, m - 1, 1, m - 1, 1, m, 1); - S1(m - 1, 1, m, 1); - S3(m - 1, 1, m, 2, m, 1, m, 2); - } else if (m >= c0 + 2) { - S5(c0 - 1, 1, c0, 1, c0, 1, c0 + 1, 1); - S1(c0, 1, c0 + 1, 1); - S2(c0, 1, c0 + 1, 1, c0 + 1, 1, c0 + 2, 1); - S4(c0, 1, c0 + 2, 2, c0 + 1, 1, c0 + 2, 2); - S3(c0, 1, c0 + 1, 2, c0 + 1, 1, c0 + 1, 2); - } else { - S5(c0 - 1, -m + c0 + 2, c0, -m + c0 + 2, m - 1, -m + c0 + 2, m, -m + c0 + 2); - S6(c0 - 1, -m + c0 + 1, c0, -m + c0 + 2, m, -m + c0 + 1, m, -m + c0 + 2); - S1(c0, -m + c0 + 2, m, -m + c0 + 2); - S3(c0, -m + c0 + 2, c0 + 1, -m + c0 + 3, m, -m + c0 + 2, m, -m + c0 + 3); - } - for (int c1 = max(2, -m + c0 + 3); c1 <= min(m - 1, c0); c1 += 1) { - S5(c0 - 1, c1, c0, c1, c0 - c1 + 1, c1, c0 - c1 + 2, c1); - S7(c0 - 1, c1 - 1, c0 + 1, c1, c0 - c1 + 2, c1 - 1, c0 - c1 + 3, c1); - S6(c0 - 1, c1 - 1, c0, c1, c0 - c1 + 2, c1 - 1, c0 - c1 + 2, c1); - S1(c0, c1, c0 - c1 + 2, c1); - S2(c0, c1, c0 + 1, c1, c0 - c1 + 2, c1, c0 - c1 + 3, c1); - S4(c0, c1, c0 + 2, c1 + 1, c0 - c1 + 2, c1, c0 - c1 + 3, c1 + 1); - S3(c0, c1, c0 + 1, c1 + 1, c0 - c1 + 2, c1, c0 - c1 + 2, c1 + 1); - } - if (c0 + 1 == m) { - S7(m - 2, m - 1, m, m, 1, m - 1, 2, m); - S6(m - 2, m - 1, m - 1, m, 1, m - 1, 1, m); - S1(m - 1, m, 1, m); - S2(m - 1, m, m, m, 1, m, 2, m); - } else if (c0 >= m) { - S5(c0 - 1, m, c0, m, -m + c0 + 1, m, -m + c0 + 2, m); - S7(c0 - 1, m - 1, c0 + 1, m, -m + c0 + 2, m - 1, -m + c0 + 3, m); - S6(c0 - 1, m - 1, c0, m, -m + c0 + 2, m - 1, -m + c0 + 2, m); - S1(c0, m, -m + c0 + 2, m); - S2(c0, m, c0 + 1, m, -m + c0 + 2, m, -m + c0 + 3, m); + S8(0, 1); + for (int c0 = 1; c0 < 2 * m - 1; c0 += 1) { + if (2 * m >= c0 + 3) { + if (c0 + 1 == m) { + S5(m - 2, 1, m - 1, 1, m - 1, 1, m, 1); + S1(m - 1, 1, m, 1); + S3(m - 1, 1, m, 2, m, 1, m, 2); + } else if (m >= c0 + 2) { + S5(c0 - 1, 1, c0, 1, c0, 1, c0 + 1, 1); + S1(c0, 1, c0 + 1, 1); + S2(c0, 1, c0 + 1, 1, c0 + 1, 1, c0 + 2, 1); + S4(c0, 1, c0 + 2, 2, c0 + 1, 1, c0 + 2, 2); + S3(c0, 1, c0 + 1, 2, c0 + 1, 1, c0 + 1, 2); + } else { + S5(c0 - 1, -m + c0 + 2, c0, -m + c0 + 2, m - 1, -m + c0 + 2, m, -m + c0 + 2); + S6(c0 - 1, -m + c0 + 1, c0, -m + c0 + 2, m, -m + c0 + 1, m, -m + c0 + 2); + S1(c0, -m + c0 + 2, m, -m + c0 + 2); + S3(c0, -m + c0 + 2, c0 + 1, -m + c0 + 3, m, -m + c0 + 2, m, -m + c0 + 3); + } + for (int c1 = max(2, -m + c0 + 3); c1 <= min(m - 1, c0); c1 += 1) { + S5(c0 - 1, c1, c0, c1, c0 - c1 + 1, c1, c0 - c1 + 2, c1); + S7(c0 - 1, c1 - 1, c0 + 1, c1, c0 - c1 + 2, c1 - 1, c0 - c1 + 3, c1); + S6(c0 - 1, c1 - 1, c0, c1, c0 - c1 + 2, c1 - 1, c0 - c1 + 2, c1); + S1(c0, c1, c0 - c1 + 2, c1); + S2(c0, c1, c0 + 1, c1, c0 - c1 + 2, c1, c0 - c1 + 3, c1); + S4(c0, c1, c0 + 2, c1 + 1, c0 - c1 + 2, c1, c0 - c1 + 3, c1 + 1); + S3(c0, c1, c0 + 1, c1 + 1, c0 - c1 + 2, c1, c0 - c1 + 2, c1 + 1); + } + if (c0 + 1 == m) { + S7(m - 2, m - 1, m, m, 1, m - 1, 2, m); + S6(m - 2, m - 1, m - 1, m, 1, m - 1, 1, m); + S1(m - 1, m, 1, m); + S2(m - 1, m, m, m, 1, m, 2, m); + } else if (m >= c0 + 2) { + S6(c0 - 1, c0, c0, c0 + 1, 1, c0, 1, c0 + 1); + S7(c0 - 1, c0, c0 + 1, c0 + 1, 1, c0, 2, c0 + 1); + S1(c0, c0 + 1, 1, c0 + 1); + S2(c0, c0 + 1, c0 + 1, c0 + 1, 1, c0 + 1, 2, c0 + 1); + S4(c0, c0 + 1, c0 + 2, c0 + 2, 1, c0 + 1, 2, c0 + 2); + S3(c0, c0 + 1, c0 + 1, c0 + 2, 1, c0 + 1, 1, c0 + 2); + } else { + S5(c0 - 1, m, c0, m, -m + c0 + 1, m, -m + c0 + 2, m); + S7(c0 - 1, m - 1, c0 + 1, m, -m + c0 + 2, m - 1, -m + c0 + 3, m); + S6(c0 - 1, m - 1, c0, m, -m + c0 + 2, m - 1, -m + c0 + 2, m); + S1(c0, m, -m + c0 + 2, m); + S2(c0, m, c0 + 1, m, -m + c0 + 2, m, -m + c0 + 3, m); + } } else { - S6(c0 - 1, c0, c0, c0 + 1, 1, c0, 1, c0 + 1); - S7(c0 - 1, c0, c0 + 1, c0 + 1, 1, c0, 2, c0 + 1); - S1(c0, c0 + 1, 1, c0 + 1); - S2(c0, c0 + 1, c0 + 1, c0 + 1, 1, c0 + 1, 2, c0 + 1); - S4(c0, c0 + 1, c0 + 2, c0 + 2, 1, c0 + 1, 2, c0 + 2); - S3(c0, c0 + 1, c0 + 1, c0 + 2, 1, c0 + 1, 1, c0 + 2); + S5(2 * m - 3, m, 2 * m - 2, m, m - 1, m, m, m); + S6(2 * m - 3, m - 1, 2 * m - 2, m, m, m - 1, m, m); + S1(2 * m - 2, m, m, m); } for (int c2 = max(1, -m + c0 + 2); c2 <= min(m, c0 + 1); c2 += 1) S8(c0, c2); - } - if (m >= 2) { - if (m >= 3) { - S5(2 * m - 4, m - 1, 2 * m - 3, m - 1, m - 1, m - 1, m, m - 1); - S6(2 * m - 4, m - 2, 2 * m - 3, m - 1, m, m - 2, m, m - 1); - S1(2 * m - 3, m - 1, m, m - 1); - S3(2 * m - 3, m - 1, 2 * m - 2, m, m, m - 1, m, m); - S5(2 * m - 4, m, 2 * m - 3, m, m - 2, m, m - 1, m); - S7(2 * m - 4, m - 1, 2 * m - 2, m, m - 1, m - 1, m, m); - S6(2 * m - 4, m - 1, 2 * m - 3, m, m - 1, m - 1, m - 1, m); - S1(2 * m - 3, m, m - 1, m); - } else { - S5(0, 1, 1, 1, 1, 1, 2, 1); - S1(1, 1, 2, 1); - S3(1, 1, 2, 2, 2, 1, 2, 2); - S7(0, 1, 2, 2, 1, 1, 2, 2); - S6(0, 1, 1, 2, 1, 1, 1, 2); - S1(1, 2, 1, 2); - } - S2(2 * m - 3, m, 2 * m - 2, m, m - 1, m, m, m); - for (int c2 = m - 1; c2 <= m; c2 += 1) - S8(2 * m - 3, c2); - S5(2 * m - 3, m, 2 * m - 2, m, m - 1, m, m, m); - S6(2 * m - 3, m - 1, 2 * m - 2, m, m, m - 1, m, m); - S1(2 * m - 2, m, m, m); - S8(2 * m - 2, m); } } -- gitore 0.2.1