3 #include "isl_map_private.h"
5 static unsigned n(struct isl_div
*d
, enum isl_dim_type type
)
7 struct isl_dim
*dim
= d
->bmap
->dim
;
9 case isl_dim_param
: return dim
->nparam
;
10 case isl_dim_in
: return dim
->n_in
;
11 case isl_dim_out
: return dim
->n_out
;
12 case isl_dim_div
: return d
->bmap
->n_div
;
16 static unsigned offset(struct isl_div
*d
, enum isl_dim_type type
)
18 struct isl_dim
*dim
= d
->bmap
->dim
;
20 case isl_dim_param
: return 1 + 1;
21 case isl_dim_in
: return 1 + 1 + dim
->nparam
;
22 case isl_dim_out
: return 1 + 1 + dim
->nparam
+ dim
->n_in
;
23 case isl_dim_div
: return 1 + 1 + dim
->nparam
+ dim
->n_in
+ dim
->n_out
;
27 struct isl_div
*isl_basic_map_div(struct isl_basic_map
*bmap
, int pos
)
34 isl_assert(bmap
->ctx
, pos
< bmap
->n_div
, goto error
);
36 div
= isl_alloc_type(bmap
->ctx
, struct isl_div
);
41 isl_ctx_ref(div
->ctx
);
44 div
->line
= &bmap
->div
[pos
];
48 isl_basic_map_free(bmap
);
52 struct isl_div
*isl_basic_set_div(struct isl_basic_set
*bset
, int pos
)
54 return isl_basic_map_div((struct isl_basic_map
*)bset
, pos
);
57 struct isl_div
*isl_div_alloc(struct isl_dim
*dim
)
59 struct isl_basic_map
*bmap
;
64 bmap
= isl_basic_map_alloc_dim(dim
, 1, 0, 0);
68 isl_basic_map_alloc_div(bmap
);
69 isl_seq_clr(bmap
->div
[0], 1 + 1 + isl_basic_map_total_dim(bmap
));
70 return isl_basic_map_div(bmap
, 0);
73 struct isl_div
*isl_div_free(struct isl_div
*c
)
81 isl_basic_map_free(c
->bmap
);
82 isl_ctx_deref(c
->ctx
);
86 void isl_div_get_constant(struct isl_div
*div
, isl_int
*v
)
90 isl_int_set(*v
, div
->line
[0][1]);
93 void isl_div_get_denominator(struct isl_div
*div
, isl_int
*v
)
97 isl_int_set(*v
, div
->line
[0][0]);
100 void isl_div_get_coefficient(struct isl_div
*div
,
101 enum isl_dim_type type
, int pos
, isl_int
*v
)
106 isl_assert(div
->ctx
, pos
< n(div
, type
), return);
107 isl_int_set(*v
, div
->line
[0][offset(div
, type
) + pos
]);
110 void isl_div_set_constant(struct isl_div
*div
, isl_int v
)
114 isl_int_set(div
->line
[0][1], v
);
117 void isl_div_set_denominator(struct isl_div
*div
, isl_int v
)
121 isl_int_set(div
->line
[0][0], v
);
124 void isl_div_set_coefficient(struct isl_div
*div
,
125 enum isl_dim_type type
, int pos
, isl_int v
)
130 isl_assert(div
->ctx
, pos
< n(div
, type
), return);
131 isl_int_set(div
->line
[0][offset(div
, type
) + pos
], v
);