Coverage Report

Created: 2017-08-18 19:41

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/tools/polly/lib/External/isl/isl_blk.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2008-2009 Katholieke Universiteit Leuven
3
 *
4
 * Use of this software is governed by the MIT license
5
 *
6
 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7
 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8
 */
9
10
#include <isl_blk.h>
11
#include <isl_ctx_private.h>
12
13
/* The maximal number of cache misses before first element is evicted */
14
180k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
16.3M
{
18
16.3M
  struct isl_blk block;
19
16.3M
  block.size = 0;
20
16.3M
  block.data = NULL;
21
16.3M
  return block;
22
16.3M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
14.2M
{
26
5.86M
  return block.size == 0 && block.data == NULL;
27
14.2M
}
28
29
static struct isl_blk isl_blk_error()
30
0
{
31
0
  struct isl_blk block;
32
0
  block.size = -1;
33
0
  block.data = NULL;
34
0
  return block;
35
0
}
36
37
int isl_blk_is_error(struct isl_blk block)
38
18.7M
{
39
0
  return block.size == -1 && block.data == NULL;
40
18.7M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
341k
{
44
341k
  int i;
45
341k
46
38.5M
  for (i = 0; 
i < block.size38.5M
;
++i38.1M
)
47
38.1M
    isl_int_clear(block.data[i]);
48
341k
  free(block.data);
49
341k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
10.5M
{
54
10.5M
  int i;
55
10.5M
  isl_int *p;
56
10.5M
57
10.5M
  if (block.size >= new_n)
58
9.90M
    return block;
59
10.5M
60
691k
  
p = 691k
isl_realloc_array691k
(ctx, block.data, isl_int, new_n);
61
691k
  if (
!p691k
)
{0
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
691k
  }
65
691k
  block.data = p;
66
691k
67
38.9M
  for (i = block.size; 
i < new_n38.9M
;
++i38.2M
)
68
38.2M
    isl_int_init(block.data[i]);
69
691k
  block.size = new_n;
70
691k
71
691k
  return block;
72
10.5M
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
10.4M
{
76
10.4M
  int i;
77
10.4M
  struct isl_blk block;
78
10.4M
79
10.4M
  block = isl_blk_empty();
80
10.4M
  if (
n && 10.4M
ctx->n_cached8.23M
)
{8.07M
81
8.07M
    int best = 0;
82
75.6M
    for (i = 1; 
ctx->cache[best].size != n && 75.6M
i < ctx->n_cached73.4M
;
++i67.5M
)
{67.5M
83
67.5M
      if (
ctx->cache[best].size < n67.5M
)
{8.77M
84
8.77M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
4.08M
          best = i;
86
67.5M
      } else 
if (58.8M
ctx->cache[i].size >= n &&58.8M
87
37.4M
           ctx->cache[i].size < ctx->cache[best].size)
88
12.3M
          best = i;
89
67.5M
    }
90
8.07M
    if (
ctx->cache[best].size < 2 * n + 1008.07M
)
{7.89M
91
7.89M
      block = ctx->cache[best];
92
7.89M
      if (--ctx->n_cached != best)
93
5.72M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
7.89M
      if (best == 0)
95
1.06M
        ctx->n_miss = 0;
96
8.07M
    } else 
if (180k
ctx->n_miss++ >= 180k
ISL_BLK_MAX_MISS180k
)
{149
97
149
      isl_blk_free_force(ctx, ctx->cache[0]);
98
149
      if (--ctx->n_cached != 0)
99
147
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
149
      ctx->n_miss = 0;
101
8.07M
    }
102
10.4M
  }
103
10.4M
104
10.4M
  return extend(ctx, block, n);
105
10.4M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
203k
{
110
203k
  if (isl_blk_is_empty(block))
111
95.7k
    return isl_blk_alloc(ctx, new_n);
112
203k
113
107k
  return extend(ctx, block, new_n);
114
203k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
14.0M
{
118
14.0M
  if (
isl_blk_is_empty(block) || 14.0M
isl_blk_is_error(block)8.23M
)
119
5.76M
    return;
120
14.0M
121
8.23M
  
if (8.23M
ctx->n_cached < 8.23M
ISL_BLK_CACHE_SIZE8.23M
)
122
7.91M
    ctx->cache[ctx->n_cached++] = block;
123
8.23M
  else
124
319k
    isl_blk_free_force(ctx, block);
125
14.0M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.16k
{
129
1.16k
  int i;
130
1.16k
131
23.2k
  for (i = 0; 
i < ctx->n_cached23.2k
;
++i22.0k
)
132
22.0k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.16k
  ctx->n_cached = 0;
134
1.16k
}