1 /* 2 * Copyright 2011 Sven Verdoolaege 3 * Copyright 2012-2013 Ecole Normale Superieure 4 * 5 * Use of this software is governed by the MIT license 6 * 7 * Written by Sven Verdoolaege, 8 * Ecole Normale Superieure, 45 rue d’Ulm, 75230 Paris, France 9 */ 10 11 #include <isl_multi_macro.h> 12 13 /* Transform the elements of "multi" by applying "fn" to them 14 * with extra argument "set". 15 * If "multi" has an explicit domain, then apply "fn_domain" or 16 * "fn_params" to this explicit domain instead. 17 * In particular, if the explicit domain is a parameter set, 18 * then apply "fn_params". Otherwise, apply "fn_domain". 19 */ 20 static __isl_give MULTI(BASE) *FN(FN(MULTI(BASE),apply),APPLY_DOMBASE)( 21 __isl_take MULTI(BASE) *multi, __isl_take APPLY_DOM *set, 22 __isl_give EL *(*fn)(EL *el, __isl_take APPLY_DOM *set), 23 __isl_give DOM *(*fn_domain)(DOM *domain, __isl_take APPLY_DOM *set), 24 __isl_give DOM *(*fn_params)(DOM *domain, __isl_take APPLY_DOM *set)) 25 { 26 isl_size n; 27 int i; 28 29 FN(FN(MULTI(BASE),align_params),APPLY_DOMBASE)(&multi, &set); 30 31 if (FN(MULTI(BASE),has_explicit_domain)(multi)) 32 return FN(FN(MULTI(BASE),apply_domain),APPLY_DOMBASE)(multi, 33 set, fn_domain, fn_params); 34 35 n = FN(MULTI(BASE),size)(multi); 36 if (n < 0 || !set) 37 goto error; 38 39 for (i = 0; i < n; ++i) { 40 EL *el; 41 42 el = FN(MULTI(BASE),take_at)(multi, i); 43 el = fn(el, FN(APPLY_DOM,copy)(set)); 44 multi = FN(MULTI(BASE),restore_at)(multi, i, el); 45 } 46 47 FN(APPLY_DOM,free)(set); 48 return multi; 49 error: 50 FN(APPLY_DOM,free)(set); 51 FN(MULTI(BASE),free)(multi); 52 return NULL; 53 } 54