isl_schedule_tree.c: print_tree_band: use isl_bool for local variable
[isl.git] / isl_multi_splice_templ.c
blobc315b8531fac87dc37912cee07fcb73d4a4a5ddd
1 /*
2 * Copyright 2012 Ecole Normale Superieure
4 * Use of this software is governed by the MIT license
6 * Written by Sven Verdoolaege,
7 * Ecole Normale Superieure, 45 rue d'Ulm, 75230 Paris, France
8 */
10 #include <isl/ctx.h>
11 #include <isl/space.h>
13 #include <isl_multi_macro.h>
15 /* Given two multi expressions, "multi1"
17 * [A1 A2] -> [B1 B2]
19 * where A2 starts at position "in_pos" and B2 starts at position "out_pos",
20 * and "multi2"
22 * [C] -> [D]
24 * return the multi expression
26 * [A1 C A2] -> [B1 D B2]
28 * We first insert input dimensions to obtain
30 * [A1 C A2] -> [B1 B2]
32 * and
34 * [A1 C A2] -> [D]
36 * and then apply range_splice.
38 __isl_give MULTI(BASE) *FN(MULTI(BASE),splice)(
39 __isl_take MULTI(BASE) *multi1, unsigned in_pos, unsigned out_pos,
40 __isl_take MULTI(BASE) *multi2)
42 unsigned n_in1;
43 unsigned n_in2;
45 if (!multi1 || !multi2)
46 goto error;
48 n_in1 = FN(MULTI(BASE),dim)(multi1, isl_dim_in);
49 if (in_pos > n_in1)
50 isl_die(FN(MULTI(BASE),get_ctx)(multi1), isl_error_invalid,
51 "index out of bounds", goto error);
53 n_in2 = FN(MULTI(BASE),dim)(multi2, isl_dim_in);
55 multi1 = FN(MULTI(BASE),insert_dims)(multi1, isl_dim_in, in_pos, n_in2);
56 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, n_in2,
57 n_in1 - in_pos);
58 multi2 = FN(MULTI(BASE),insert_dims)(multi2, isl_dim_in, 0, in_pos);
60 return FN(MULTI(BASE),range_splice)(multi1, out_pos, multi2);
61 error:
62 FN(MULTI(BASE),free)(multi1);
63 FN(MULTI(BASE),free)(multi2);
64 return NULL;