LCOV - code coverage report
Current view: top level - metalib_isl - isl_dim_map.c (source / functions) Hit Total Coverage
Test: 2018-10-31_point_maint_greina16.lcov Lines: 0 103 0.0 %
Date: 2018-11-01 11:27:00 Functions: 0 12 0.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright 2008-2009 Katholieke Universiteit Leuven
       3             :  * Copyright 2010-2011 INRIA Saclay
       4             :  *
       5             :  * Use of this software is governed by the MIT license
       6             :  *
       7             :  * Written by Sven Verdoolaege, K.U.Leuven, Departement
       8             :  * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
       9             :  * and INRIA Saclay - Ile-de-France, Parc Club Orsay Universite,
      10             :  * ZAC des vignes, 4 rue Jacques Monod, 91893 Orsay, France 
      11             :  */
      12             : 
      13             : #include <isl_map_private.h>
      14             : #include <isl_space_private.h>
      15             : #include <isl_dim_map.h>
      16             : #include <isl_reordering.h>
      17             : 
      18             : struct isl_dim_map_entry {
      19             :         int pos;
      20             :         int sgn;
      21             : };
      22             : 
      23             : /* Maps dst positions to src positions */
      24             : struct isl_dim_map {
      25             :         unsigned len;
      26             :         struct isl_dim_map_entry m[1];
      27             : };
      28             : 
      29           0 : __isl_give isl_dim_map *isl_dim_map_alloc(isl_ctx *ctx, unsigned len)
      30             : {
      31             :         int i;
      32             :         struct isl_dim_map *dim_map;
      33           0 :         dim_map = isl_alloc(ctx, struct isl_dim_map,
      34             :             sizeof(struct isl_dim_map) + len * sizeof(struct isl_dim_map_entry));
      35           0 :         if (!dim_map)
      36           0 :                 return NULL;
      37           0 :         dim_map->len = 1 + len;
      38           0 :         dim_map->m[0].pos = 0;
      39           0 :         dim_map->m[0].sgn = 1;
      40           0 :         for (i = 0; i < len; ++i)
      41           0 :                 dim_map->m[1 + i].sgn = 0;
      42           0 :         return dim_map;
      43             : }
      44             : 
      45           0 : void isl_dim_map_range(__isl_keep isl_dim_map *dim_map,
      46             :         unsigned dst_pos, int dst_stride, unsigned src_pos, int src_stride,
      47             :         unsigned n, int sign)
      48             : {
      49             :         int i;
      50             : 
      51           0 :         if (!dim_map)
      52           0 :                 return;
      53             : 
      54           0 :         for (i = 0; i < n; ++i) {
      55           0 :                 unsigned d = 1 + dst_pos + dst_stride * i;
      56           0 :                 unsigned s = 1 + src_pos + src_stride * i;
      57           0 :                 dim_map->m[d].pos = s;
      58           0 :                 dim_map->m[d].sgn = sign;
      59             :         }
      60             : }
      61             : 
      62           0 : void isl_dim_map_dim_range(__isl_keep isl_dim_map *dim_map,
      63             :         __isl_keep isl_space *dim, enum isl_dim_type type,
      64             :         unsigned first, unsigned n, unsigned dst_pos)
      65             : {
      66             :         int i;
      67             :         unsigned src_pos;
      68             : 
      69           0 :         if (!dim_map || !dim)
      70           0 :                 return;
      71             :         
      72           0 :         src_pos = 1 + isl_space_offset(dim, type);
      73           0 :         for (i = 0; i < n; ++i) {
      74           0 :                 dim_map->m[1 + dst_pos + i].pos = src_pos + first + i;
      75           0 :                 dim_map->m[1 + dst_pos + i].sgn = 1;
      76             :         }
      77             : }
      78             : 
      79           0 : void isl_dim_map_dim(__isl_keep isl_dim_map *dim_map, __isl_keep isl_space *dim,
      80             :         enum isl_dim_type type, unsigned dst_pos)
      81             : {
      82           0 :         isl_dim_map_dim_range(dim_map, dim, type,
      83             :                               0, isl_space_dim(dim, type), dst_pos);
      84           0 : }
      85             : 
      86           0 : void isl_dim_map_div(__isl_keep isl_dim_map *dim_map,
      87             :         __isl_keep isl_basic_map *bmap, unsigned dst_pos)
      88             : {
      89             :         int i;
      90             :         unsigned src_pos;
      91             : 
      92           0 :         if (!dim_map || !bmap)
      93           0 :                 return;
      94             :         
      95           0 :         src_pos = 1 + isl_space_dim(bmap->dim, isl_dim_all);
      96           0 :         for (i = 0; i < bmap->n_div; ++i) {
      97           0 :                 dim_map->m[1 + dst_pos + i].pos = src_pos + i;
      98           0 :                 dim_map->m[1 + dst_pos + i].sgn = 1;
      99             :         }
     100             : }
     101             : 
     102           0 : void isl_dim_map_dump(struct isl_dim_map *dim_map)
     103             : {
     104             :         int i;
     105             : 
     106           0 :         for (i = 0; i < dim_map->len; ++i)
     107           0 :                 fprintf(stderr, "%d -> %d * %d; ", i,
     108             :                         dim_map->m[i].sgn, dim_map->m[i].pos);
     109           0 :         fprintf(stderr, "\n");
     110           0 : }
     111             : 
     112           0 : static void copy_constraint_dim_map(isl_int *dst, isl_int *src,
     113             :                                         struct isl_dim_map *dim_map)
     114             : {
     115             :         int i;
     116             : 
     117           0 :         for (i = 0; i < dim_map->len; ++i) {
     118           0 :                 if (dim_map->m[i].sgn == 0)
     119           0 :                         isl_int_set_si(dst[i], 0);
     120           0 :                 else if (dim_map->m[i].sgn > 0)
     121           0 :                         isl_int_set(dst[i], src[dim_map->m[i].pos]);
     122             :                 else
     123           0 :                         isl_int_neg(dst[i], src[dim_map->m[i].pos]);
     124             :         }
     125           0 : }
     126             : 
     127           0 : static void copy_div_dim_map(isl_int *dst, isl_int *src,
     128             :                                         struct isl_dim_map *dim_map)
     129             : {
     130           0 :         isl_int_set(dst[0], src[0]);
     131           0 :         copy_constraint_dim_map(dst+1, src+1, dim_map);
     132           0 : }
     133             : 
     134           0 : __isl_give isl_basic_map *isl_basic_map_add_constraints_dim_map(
     135             :         __isl_take isl_basic_map *dst, __isl_take isl_basic_map *src,
     136             :         __isl_take isl_dim_map *dim_map)
     137             : {
     138             :         int i;
     139             : 
     140           0 :         if (!src || !dst || !dim_map)
     141             :                 goto error;
     142             : 
     143           0 :         for (i = 0; i < src->n_eq; ++i) {
     144           0 :                 int i1 = isl_basic_map_alloc_equality(dst);
     145           0 :                 if (i1 < 0)
     146           0 :                         goto error;
     147           0 :                 copy_constraint_dim_map(dst->eq[i1], src->eq[i], dim_map);
     148             :         }
     149             : 
     150           0 :         for (i = 0; i < src->n_ineq; ++i) {
     151           0 :                 int i1 = isl_basic_map_alloc_inequality(dst);
     152           0 :                 if (i1 < 0)
     153           0 :                         goto error;
     154           0 :                 copy_constraint_dim_map(dst->ineq[i1], src->ineq[i], dim_map);
     155             :         }
     156             : 
     157           0 :         for (i = 0; i < src->n_div; ++i) {
     158           0 :                 int i1 = isl_basic_map_alloc_div(dst);
     159           0 :                 if (i1 < 0)
     160           0 :                         goto error;
     161           0 :                 copy_div_dim_map(dst->div[i1], src->div[i], dim_map);
     162             :         }
     163             : 
     164           0 :         free(dim_map);
     165           0 :         isl_basic_map_free(src);
     166             : 
     167           0 :         return dst;
     168             : error:
     169           0 :         free(dim_map);
     170           0 :         isl_basic_map_free(src);
     171           0 :         isl_basic_map_free(dst);
     172           0 :         return NULL;
     173             : }
     174             : 
     175           0 : __isl_give isl_basic_set *isl_basic_set_add_constraints_dim_map(
     176             :         __isl_take isl_basic_set *dst, __isl_take isl_basic_set *src,
     177             :         __isl_take isl_dim_map *dim_map)
     178             : {
     179           0 :         return isl_basic_map_add_constraints_dim_map(dst, src, dim_map);
     180             : }
     181             : 
     182             : /* Extend the given dim_map with mappings for the divs in bmap.
     183             :  */
     184           0 : __isl_give isl_dim_map *isl_dim_map_extend(__isl_keep isl_dim_map *dim_map,
     185             :         __isl_keep isl_basic_map *bmap)
     186             : {
     187             :         int i;
     188             :         struct isl_dim_map *res;
     189             :         int offset;
     190             : 
     191           0 :         if (!dim_map)
     192           0 :                 return NULL;
     193             : 
     194           0 :         offset = isl_basic_map_offset(bmap, isl_dim_div);
     195             : 
     196           0 :         res = isl_dim_map_alloc(bmap->ctx, dim_map->len - 1 + bmap->n_div);
     197           0 :         if (!res)
     198           0 :                 return NULL;
     199             : 
     200           0 :         for (i = 0; i < dim_map->len; ++i)
     201           0 :                 res->m[i] = dim_map->m[i];
     202           0 :         for (i = 0; i < bmap->n_div; ++i) {
     203           0 :                 res->m[dim_map->len + i].pos = offset + i;
     204           0 :                 res->m[dim_map->len + i].sgn = 1;
     205             :         }
     206             : 
     207           0 :         return res;
     208             : }
     209             : 
     210             : /* Extract a dim_map from a reordering.
     211             :  * We essentially need to reverse the mapping, and add an offset
     212             :  * of 1 for the constant term.
     213             :  */
     214           0 : __isl_give isl_dim_map *isl_dim_map_from_reordering(
     215             :         __isl_keep isl_reordering *exp)
     216             : {
     217             :         int i;
     218             :         isl_ctx *ctx;
     219             :         isl_space *space;
     220             :         struct isl_dim_map *dim_map;
     221             : 
     222           0 :         if (!exp)
     223           0 :                 return NULL;
     224             : 
     225           0 :         ctx = isl_reordering_get_ctx(exp);
     226           0 :         space = isl_reordering_peek_space(exp);
     227           0 :         dim_map = isl_dim_map_alloc(ctx, isl_space_dim(space, isl_dim_all));
     228           0 :         if (!dim_map)
     229           0 :                 return NULL;
     230             : 
     231           0 :         for (i = 0; i < exp->len; ++i) {
     232           0 :                 dim_map->m[1 + exp->pos[i]].pos = 1 + i;
     233           0 :                 dim_map->m[1 + exp->pos[i]].sgn = 1;
     234             :         }
     235             : 
     236           0 :         return dim_map;
     237             : }

Generated by: LCOV version 1.12