Coverage Report

Created: 2017-10-03 07:32

/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
254k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
19.9M
{
18
19.9M
  struct isl_blk block;
19
19.9M
  block.size = 0;
20
19.9M
  block.data = NULL;
21
19.9M
  return block;
22
19.9M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
17.3M
{
26
6.99M
  return block.size == 0 && block.data == NULL;
27
17.3M
}
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
23.1M
{
39
0
  return block.size == -1 && block.data == NULL;
40
23.1M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
434k
{
44
434k
  int i;
45
434k
46
48.8M
  for (i = 0; 
i < block.size48.8M
;
++i48.4M
)
47
48.4M
    isl_int_clear(block.data[i]);
48
434k
  free(block.data);
49
434k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
13.0M
{
54
13.0M
  int i;
55
13.0M
  isl_int *p;
56
13.0M
57
13.0M
  if (block.size >= new_n)
58
12.1M
    return block;
59
881k
60
881k
  
p = 881k
isl_realloc_array881k
(ctx, block.data, isl_int, new_n);
61
881k
  if (
!p881k
) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
881k
  block.data = p;
66
881k
67
49.3M
  for (i = block.size; 
i < new_n49.3M
;
++i48.4M
)
68
48.4M
    isl_int_init(block.data[i]);
69
13.0M
  block.size = new_n;
70
13.0M
71
13.0M
  return block;
72
13.0M
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
12.9M
{
76
12.9M
  int i;
77
12.9M
  struct isl_blk block;
78
12.9M
79
12.9M
  block = isl_blk_empty();
80
12.9M
  if (
n && 12.9M
ctx->n_cached10.2M
) {
81
10.0M
    int best = 0;
82
95.6M
    for (i = 1; 
ctx->cache[best].size != n && 95.6M
i < ctx->n_cached92.9M
;
++i85.6M
) {
83
85.6M
      if (
ctx->cache[best].size < n85.6M
) {
84
12.2M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
5.43M
          best = i;
86
85.6M
      } else 
if (73.3M
ctx->cache[i].size >= n &&
87
45.0M
           ctx->cache[i].size < ctx->cache[best].size)
88
14.7M
          best = i;
89
85.6M
    }
90
10.0M
    if (
ctx->cache[best].size < 2 * n + 10010.0M
) {
91
9.77M
      block = ctx->cache[best];
92
9.77M
      if (--ctx->n_cached != best)
93
7.14M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
9.77M
      if (best == 0)
95
1.25M
        ctx->n_miss = 0;
96
10.0M
    } else 
if (254k
ctx->n_miss++ >= 254k
ISL_BLK_MAX_MISS254k
) {
97
172
      isl_blk_free_force(ctx, ctx->cache[0]);
98
172
      if (--ctx->n_cached != 0)
99
170
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
254k
      ctx->n_miss = 0;
101
254k
    }
102
10.0M
  }
103
12.9M
104
12.9M
  return extend(ctx, block, n);
105
12.9M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
245k
{
110
245k
  if (isl_blk_is_empty(block))
111
111k
    return isl_blk_alloc(ctx, new_n);
112
133k
113
133k
  return extend(ctx, block, new_n);
114
133k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
17.0M
{
118
17.0M
  if (
isl_blk_is_empty(block) || 17.0M
isl_blk_is_error(block)10.2M
)
119
6.88M
    return;
120
10.2M
121
10.2M
  
if (10.2M
ctx->n_cached < 10.2M
ISL_BLK_CACHE_SIZE10.2M
)
122
9.79M
    ctx->cache[ctx->n_cached++] = block;
123
10.2M
  else
124
411k
    isl_blk_free_force(ctx, block);
125
17.0M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.21k
{
129
1.21k
  int i;
130
1.21k
131
24.1k
  for (i = 0; 
i < ctx->n_cached24.1k
;
++i22.9k
)
132
22.9k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.21k
  ctx->n_cached = 0;
134
1.21k
}