+ int i, j;
+ isl_ctx *ctx = isl_schedule_get_ctx(schedule);
+ isl_band *band;
+ unsigned start, end;
+
+ band = isl_calloc_type(ctx, isl_band);
+ if (!band)
+ return NULL;
+
+ band->ref = 1;
+ band->schedule = schedule;
+ band->parent = parent;
+
+ for (i = 0; i < schedule->n; ++i)
+ if (active[i] && schedule->node[i].n_band > band_nr + 1)
+ break;
+
+ if (i < schedule->n) {
+ band->children = construct_band_list(schedule, band,
+ band_nr + 1, active, n_active);
+ if (!band->children)
+ goto error;
+ }
+
+ for (i = 0; i < schedule->n; ++i)
+ if (active[i])
+ break;
+
+ if (i >= schedule->n)
+ isl_die(ctx, isl_error_internal,
+ "band without active statements", goto error);
+
+ start = band_nr ? schedule->node[i].band_end[band_nr - 1] : 0;
+ end = band_nr < schedule->node[i].n_band ?
+ schedule->node[i].band_end[band_nr] : start;
+ band->n = end - start;
+
+ band->zero = isl_alloc_array(ctx, int, band->n);
+ if (!band->zero)
+ goto error;
+
+ for (j = 0; j < band->n; ++j)
+ band->zero[j] = schedule->node[i].zero[start + j];
+
+ band->map = isl_union_map_empty(isl_space_copy(schedule->dim));
+ for (i = 0; i < schedule->n; ++i) {
+ isl_map *map;
+ unsigned n_out;
+
+ if (!active[i])
+ continue;
+
+ map = isl_map_copy(schedule->node[i].sched);
+ n_out = isl_map_dim(map, isl_dim_out);
+ map = isl_map_project_out(map, isl_dim_out, end, n_out - end);
+ map = isl_map_project_out(map, isl_dim_out, 0, start);
+ band->map = isl_union_map_union(band->map,
+ isl_union_map_from_map(map));
+ }
+ if (!band->map)
+ goto error;
+
+ return band;
+error:
+ isl_band_free(band);
+ return NULL;