Coverage Report

Created: 2017-04-27 19:33

/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
138k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
13.1M
{
18
13.1M
  struct isl_blk block;
19
13.1M
  block.size = 0;
20
13.1M
  block.data = NULL;
21
13.1M
  return block;
22
13.1M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
11.4M
{
26
4.82M
  return block.size == 0 && block.data == NULL;
27
11.4M
}
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
14.9M
{
39
0
  return block.size == -1 && block.data == NULL;
40
14.9M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
268k
{
44
268k
  int i;
45
268k
46
26.3M
  for (i = 0; 
i < block.size26.3M
;
++i26.0M
)
47
26.0M
    isl_int_clear(block.data[i]);
48
268k
  free(block.data);
49
268k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
8.50M
{
54
8.50M
  int i;
55
8.50M
  isl_int *p;
56
8.50M
57
8.50M
  if (block.size >= new_n)
58
7.97M
    return block;
59
8.50M
60
529k
  
p = 529k
isl_realloc_array529k
(ctx, block.data, isl_int, new_n);
61
529k
  if (
!p529k
)
{0
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
529k
  block.data = p;
66
529k
67
26.5M
  for (i = block.size; 
i < new_n26.5M
;
++i26.0M
)
68
26.0M
    isl_int_init(block.data[i]);
69
529k
  block.size = new_n;
70
529k
71
529k
  return block;
72
529k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
8.42M
{
76
8.42M
  int i;
77
8.42M
  struct isl_blk block;
78
8.42M
79
8.42M
  block = isl_blk_empty();
80
8.42M
  if (
n && 8.42M
ctx->n_cached6.55M
)
{6.42M
81
6.42M
    int best = 0;
82
60.3M
    for (i = 1; 
ctx->cache[best].size != n && 60.3M
i < ctx->n_cached58.5M
;
++i53.8M
)
{53.8M
83
53.8M
      if (
ctx->cache[best].size < n53.8M
)
{6.72M
84
6.72M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
3.14M
          best = i;
86
47.1M
      } else 
if (47.1M
ctx->cache[i].size >= n &&47.1M
87
30.0M
           ctx->cache[i].size < ctx->cache[best].size)
88
9.76M
          best = i;
89
53.8M
    }
90
6.42M
    if (
ctx->cache[best].size < 2 * n + 1006.42M
)
{6.28M
91
6.28M
      block = ctx->cache[best];
92
6.28M
      if (--ctx->n_cached != best)
93
4.58M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
6.28M
      if (best == 0)
95
879k
        ctx->n_miss = 0;
96
138k
    } else 
if (138k
ctx->n_miss++ >= 138k
ISL_BLK_MAX_MISS138k
)
{92
97
92
      isl_blk_free_force(ctx, ctx->cache[0]);
98
92
      if (--ctx->n_cached != 0)
99
92
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
92
      ctx->n_miss = 0;
101
92
    }
102
6.42M
  }
103
8.42M
104
8.42M
  return extend(ctx, block, n);
105
8.42M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
160k
{
110
160k
  if (isl_blk_is_empty(block))
111
71.7k
    return isl_blk_alloc(ctx, new_n);
112
160k
113
88.3k
  return extend(ctx, block, new_n);
114
160k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
11.3M
{
118
11.3M
  if (
isl_blk_is_empty(block) || 11.3M
isl_blk_is_error(block)6.55M
)
119
4.75M
    return;
120
11.3M
121
6.55M
  
if (6.55M
ctx->n_cached < 6.55M
ISL_BLK_CACHE_SIZE6.55M
)
122
6.30M
    ctx->cache[ctx->n_cached++] = block;
123
6.55M
  else
124
248k
    isl_blk_free_force(ctx, block);
125
6.55M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.02k
{
129
1.02k
  int i;
130
1.02k
131
20.1k
  for (i = 0; 
i < ctx->n_cached20.1k
;
++i19.1k
)
132
19.1k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.02k
  ctx->n_cached = 0;
134
1.02k
}