util.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright 2012-2013 Ecole Normale Superieure
  3. *
  4. * Use of this software is governed by the MIT license
  5. *
  6. * Written by Sven Verdoolaege,
  7. * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
  8. */
  9. #include <isl/space.h>
  10. #include <isl/val.h>
  11. #include <isl/aff.h>
  12. #include <isl/set.h>
  13. #include "util.h"
  14. /* Construct an isl_multi_val living in "space" with all values equal to "val".
  15. */
  16. __isl_give isl_multi_val *ppcg_multi_val_from_int(__isl_take isl_space *space,
  17. int val)
  18. {
  19. int i, n;
  20. isl_ctx *ctx;
  21. isl_val *v;
  22. isl_multi_val *mv;
  23. if (!space)
  24. return NULL;
  25. ctx = isl_space_get_ctx(space);
  26. n = isl_space_dim(space, isl_dim_set);
  27. mv = isl_multi_val_zero(space);
  28. v = isl_val_int_from_si(ctx, val);
  29. for (i = 0; i < n; ++i)
  30. mv = isl_multi_val_set_val(mv, i, isl_val_copy(v));
  31. isl_val_free(v);
  32. return mv;
  33. }
  34. /* Construct an isl_multi_val living in "space" with values specified
  35. * by "list". "list" is assumed to have at least as many entries
  36. * as the set dimension of "space".
  37. */
  38. __isl_give isl_multi_val *ppcg_multi_val_from_int_list(
  39. __isl_take isl_space *space, int *list)
  40. {
  41. int i, n;
  42. isl_ctx *ctx;
  43. isl_multi_val *mv;
  44. if (!space)
  45. return NULL;
  46. ctx = isl_space_get_ctx(space);
  47. n = isl_space_dim(space, isl_dim_set);
  48. mv = isl_multi_val_zero(space);
  49. for (i = 0; i < n; ++i) {
  50. isl_val *v;
  51. v = isl_val_int_from_si(ctx, list[i]);
  52. mv = isl_multi_val_set_val(mv, i, v);
  53. }
  54. return mv;
  55. }
  56. /* Compute the size of a bounding box around the origin and "set",
  57. * where "set" is assumed to contain only non-negative elements.
  58. * In particular, compute the maximal value of "set" in each direction
  59. * and add one.
  60. */
  61. __isl_give isl_multi_pw_aff *ppcg_size_from_extent(__isl_take isl_set *set)
  62. {
  63. int i, n;
  64. isl_multi_pw_aff *mpa;
  65. n = isl_set_dim(set, isl_dim_set);
  66. mpa = isl_multi_pw_aff_zero(isl_set_get_space(set));
  67. for (i = 0; i < n; ++i) {
  68. isl_space *space;
  69. isl_aff *one;
  70. isl_pw_aff *bound;
  71. if (!isl_set_dim_has_upper_bound(set, isl_dim_set, i)) {
  72. const char *name;
  73. name = isl_set_get_tuple_name(set);
  74. if (!name)
  75. name = "";
  76. fprintf(stderr, "unable to determine extent of '%s' "
  77. "in dimension %d\n", name, i);
  78. set = isl_set_free(set);
  79. }
  80. bound = isl_set_dim_max(isl_set_copy(set), i);
  81. space = isl_pw_aff_get_domain_space(bound);
  82. one = isl_aff_zero_on_domain(isl_local_space_from_space(space));
  83. one = isl_aff_add_constant_si(one, 1);
  84. bound = isl_pw_aff_add(bound, isl_pw_aff_from_aff(one));
  85. mpa = isl_multi_pw_aff_set_pw_aff(mpa, i, bound);
  86. }
  87. isl_set_free(set);
  88. return mpa;
  89. }