uniting two isl::map withdifferent Spaces

Skip to first unread message


Mar 16, 2023, 5:59:50 AMMar 16
to Polly Development
I want to use 'map1.unite(map2)', but when the spaces are different it is not allowed.
I want to make a space that contains both of the maps and in this CombinedSpace, I can unite them but unfortunately I could not do that so far. here is the function that I wrote for this purpose but unfortunately it returns an error when it is being run on a program: "/llvm-project/polly/lib/External/isl/isl_space.c:1940: domain is not a set space"

isl::map combineMaps(isl::map map1, isl::map map2) {
  isl::space map1Space = map1.get_space();
  isl::space map2Space = map2.get_space();

  if (!map1Space.is_equal(map2Space)) {
    // First, create a combined space that has all dimensions from both spaces.
    isl::space combinedSpace = map1Space.params().set_from_params();

    for (int i = 0; i < map1Space.dim(isl::dim::set).release(); i++) {
      if (combinedSpace.find_dim_by_id(
              isl::dim::set, map1Space.get_dim_id(isl::dim::set, i)) < 0) {

        combinedSpace = combinedSpace.add_named_tuple(
            combinedSpace.get_dim_id(isl::dim::set, i),
        combinedSpace = combinedSpace.set_dim_id(
            isl::dim::set, i, map1Space.get_dim_id(isl::dim::set, i));

    for (int i = 0; i < map2Space.dim(isl::dim::set).release(); i++) {
      if (combinedSpace.find_dim_by_id(
              isl::dim::set, map2Space.get_dim_id(isl::dim::set, i)) < 0) {

        combinedSpace = combinedSpace.add_named_tuple(
            map2Space.get_dim_id(isl::dim::set, i), 1);
        combinedSpace = combinedSpace.set_dim_id(
            isl::dim::set, combinedSpace.dim(isl::dim::set).release() - 1,
            map2Space.get_dim_id(isl::dim::set, i));

    // Create transformations to convert map1 and map2 into the combined space.
    isl::map map1ToCombined =
    isl::map map2ToCombined =

    // Intersect the maps with the domain of the combined space.
    map1 = map1ToCombined.intersect_domain(combinedSpace).as_map();
    map2 = map2ToCombined.intersect_domain(combinedSpace).as_map();

    // Apply the transformations to map1 and map2.
    isl::set domain1 = map1.domain();
    if (!isl_space_is_set(domain1.get_space().get())) {
      llvm::errs() << "Domain of map1 is not a set space\n";
      return isl::map();
    map1 = map1ToCombined.apply_domain(domain1.identity());

    isl::set domain2 = map2.domain();
    if (!isl_space_is_set(domain2.get_space().get())) {
      llvm::errs() << "Domain of map2 is not a set space\n";
      return isl::map();
    map2 = map2ToCombined.apply_domain(domain2.identity());

  // Combine the maps into one map.
  isl::map combinedMap = map1.unite(map2);
  return combinedMap.coalesce();

Sven Verdoolaege

Mar 16, 2023, 5:11:09 PMMar 16
to Arsalan, Polly Development
On Thu, Mar 16, 2023 at 02:59:50AM -0700, Arsalan wrote:
> I want to use 'map1.unite(map2)', but when the spaces are different it is
> not allowed.

If you want to have elements living in different spaces in a single object,
then you should use a "union map".
If you are trying to do something else, then you should probably
first explain what exactly you want to achieve.

Reply all
Reply to author
0 new messages