1 /*
2  * Copyright 2010      INRIA Saclay
3  *
4  * Use of this software is governed by the MIT license
5  *
6  * Written by Sven Verdoolaege, INRIA Saclay - Ile-de-France,
7  * Parc Club Orsay Universite, ZAC des vignes, 4 rue Jacques Monod,
8  * 91893 Orsay, France
9  */
10 
FN(PW,insert_dims)11 __isl_give PW *FN(PW,insert_dims)(__isl_take PW *pw, enum isl_dim_type type,
12 	unsigned first, unsigned n)
13 {
14 	int i;
15 	enum isl_dim_type set_type;
16 
17 	if (!pw)
18 		return NULL;
19 	if (n == 0 && !isl_space_is_named_or_nested(pw->dim, type))
20 		return pw;
21 
22 	set_type = type == isl_dim_in ? isl_dim_set : type;
23 
24 	pw = FN(PW,cow)(pw);
25 	if (!pw)
26 		return NULL;
27 
28 	pw->dim = isl_space_insert_dims(pw->dim, type, first, n);
29 	if (!pw->dim)
30 		goto error;
31 
32 	for (i = 0; i < pw->n; ++i) {
33 		pw->p[i].set = isl_set_insert_dims(pw->p[i].set,
34 							    set_type, first, n);
35 		if (!pw->p[i].set)
36 			goto error;
37 		pw->p[i].FIELD = FN(EL,insert_dims)(pw->p[i].FIELD,
38 								type, first, n);
39 		if (!pw->p[i].FIELD)
40 			goto error;
41 	}
42 
43 	return pw;
44 error:
45 	FN(PW,free)(pw);
46 	return NULL;
47 }
48 
FN(PW,add_dims)49 __isl_give PW *FN(PW,add_dims)(__isl_take PW *pw, enum isl_dim_type type,
50 	unsigned n)
51 {
52 	isl_size pos;
53 
54 	pos = FN(PW,dim)(pw, type);
55 	if (pos < 0)
56 		return FN(PW,free)(pw);
57 
58 	return FN(PW,insert_dims)(pw, type, pos, n);
59 }
60