Coverage Report

Created: 2018-06-24 14:39

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/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
298k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
20.9M
{
18
20.9M
  struct isl_blk block;
19
20.9M
  block.size = 0;
20
20.9M
  block.data = NULL;
21
20.9M
  return block;
22
20.9M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
18.1M
{
26
18.1M
  return block.size == 0 && 
block.data == NULL7.29M
;
27
18.1M
}
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
24.2M
{
39
24.2M
  return block.size == -1 && 
block.data == NULL0
;
40
24.2M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
488k
{
44
488k
  int i;
45
488k
46
56.4M
  for (i = 0; i < block.size; 
++i55.9M
)
47
55.9M
    isl_int_clear(block.data[i]);
48
488k
  free(block.data);
49
488k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
13.7M
{
54
13.7M
  int i;
55
13.7M
  isl_int *p;
56
13.7M
57
13.7M
  if (block.size >= new_n)
58
12.7M
    return block;
59
908k
60
908k
  p = isl_realloc_array(ctx, block.data, isl_int, new_n);
61
908k
  if (!p) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
908k
  block.data = p;
66
908k
67
56.9M
  for (i = block.size; i < new_n; 
++i56.0M
)
68
56.0M
    isl_int_init(block.data[i]);
69
908k
  block.size = new_n;
70
908k
71
908k
  return block;
72
908k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
13.5M
{
76
13.5M
  int i;
77
13.5M
  struct isl_blk block;
78
13.5M
79
13.5M
  block = isl_blk_empty();
80
13.5M
  if (n && 
ctx->n_cached10.6M
) {
81
10.4M
    int best = 0;
82
102M
    for (i = 1; ctx->cache[best].size != n && 
i < ctx->n_cached99.3M
;
++i91.6M
) {
83
91.6M
      if (ctx->cache[best].size < n) {
84
11.1M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
5.45M
          best = i;
86
80.4M
      } else if (ctx->cache[i].size >= n &&
87
80.4M
           
ctx->cache[i].size < ctx->cache[best].size47.9M
)
88
15.8M
          best = i;
89
91.6M
    }
90
10.4M
    if (ctx->cache[best].size < 2 * n + 100) {
91
10.1M
      block = ctx->cache[best];
92
10.1M
      if (--ctx->n_cached != best)
93
7.53M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
10.1M
      if (best == 0)
95
1.31M
        ctx->n_miss = 0;
96
10.1M
    } else 
if (298k
ctx->n_miss++ >= 298k
ISL_BLK_MAX_MISS298k
) {
97
171
      isl_blk_free_force(ctx, ctx->cache[0]);
98
171
      if (--ctx->n_cached != 0)
99
171
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
171
      ctx->n_miss = 0;
101
171
    }
102
10.4M
  }
103
13.5M
104
13.5M
  return extend(ctx, block, n);
105
13.5M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
251k
{
110
251k
  if (isl_blk_is_empty(block))
111
116k
    return isl_blk_alloc(ctx, new_n);
112
135k
113
135k
  return extend(ctx, block, new_n);
114
135k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
17.8M
{
118
17.8M
  if (isl_blk_is_empty(block) || 
isl_blk_is_error(block)10.6M
)
119
7.17M
    return;
120
10.6M
121
10.6M
  if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
122
10.6M
    
ctx->cache[ctx->n_cached++] = block10.2M
;
123
464k
  else
124
464k
    isl_blk_free_force(ctx, block);
125
10.6M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.25k
{
129
1.25k
  int i;
130
1.25k
131
24.9k
  for (i = 0; i < ctx->n_cached; 
++i23.6k
)
132
23.6k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.25k
  ctx->n_cached = 0;
134
1.25k
}