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),
map1Space.dim(isl::dim::set).release());
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::identity(map1Space.map_from_domain_and_range(combinedSpace));
isl::map map2ToCombined =
isl::map::identity(map2Space.map_from_domain_and_range(combinedSpace));
// 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();
}