Coverage Report

Created: 2017-03-27 23:01

/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
133k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
12.0M
{
18
12.0M
  struct isl_blk block;
19
12.0M
  block.size = 0;
20
12.0M
  block.data = NULL;
21
12.0M
  return block;
22
12.0M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
10.5M
{
26
4.48M
  return block.size == 0 && block.data == NULL;
27
10.5M
}
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
13.6M
{
39
0
  return block.size == -1 && block.data == NULL;
40
13.6M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
247k
{
44
247k
  int i;
45
247k
46
25.1M
  for (i = 0; 
i < block.size25.1M
;
++i24.8M
)
47
24.8M
    isl_int_clear(block.data[i]);
48
247k
  free(block.data);
49
247k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
7.79M
{
54
7.79M
  int i;
55
7.79M
  isl_int *p;
56
7.79M
57
7.79M
  if (block.size >= new_n)
58
7.31M
    return block;
59
7.79M
60
477k
  
p = 477k
isl_realloc_array477k
(ctx, block.data, isl_int, new_n);
61
477k
  if (
!p477k
)
{0
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
477k
  block.data = p;
66
477k
67
25.3M
  for (i = block.size; 
i < new_n25.3M
;
++i24.8M
)
68
24.8M
    isl_int_init(block.data[i]);
69
477k
  block.size = new_n;
70
477k
71
477k
  return block;
72
477k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
7.70M
{
76
7.70M
  int i;
77
7.70M
  struct isl_blk block;
78
7.70M
79
7.70M
  block = isl_blk_empty();
80
7.70M
  if (
n && 7.70M
ctx->n_cached5.95M
)
{5.84M
81
5.84M
    int best = 0;
82
55.7M
    for (i = 1; 
ctx->cache[best].size != n && 55.7M
i < ctx->n_cached54.1M
;
++i49.9M
)
{49.9M
83
49.9M
      if (
ctx->cache[best].size < n49.9M
)
{6.17M
84
6.17M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
2.84M
          best = i;
86
43.7M
      } else 
if (43.7M
ctx->cache[i].size >= n &&43.7M
87
27.7M
           ctx->cache[i].size < ctx->cache[best].size)
88
9.17M
          best = i;
89
49.9M
    }
90
5.84M
    if (
ctx->cache[best].size < 2 * n + 1005.84M
)
{5.71M
91
5.71M
      block = ctx->cache[best];
92
5.71M
      if (--ctx->n_cached != best)
93
4.15M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
5.71M
      if (best == 0)
95
788k
        ctx->n_miss = 0;
96
133k
    } else 
if (133k
ctx->n_miss++ >= 133k
ISL_BLK_MAX_MISS133k
)
{105
97
105
      isl_blk_free_force(ctx, ctx->cache[0]);
98
105
      if (--ctx->n_cached != 0)
99
105
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
105
      ctx->n_miss = 0;
101
105
    }
102
5.84M
  }
103
7.70M
104
7.70M
  return extend(ctx, block, n);
105
7.70M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
145k
{
110
145k
  if (isl_blk_is_empty(block))
111
62.3k
    return isl_blk_alloc(ctx, new_n);
112
145k
113
83.3k
  return extend(ctx, block, new_n);
114
145k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
10.3M
{
118
10.3M
  if (
isl_blk_is_empty(block) || 10.3M
isl_blk_is_error(block)5.95M
)
119
4.41M
    return;
120
10.3M
121
5.95M
  
if (5.95M
ctx->n_cached < 5.95M
ISL_BLK_CACHE_SIZE5.95M
)
122
5.72M
    ctx->cache[ctx->n_cached++] = block;
123
5.95M
  else
124
228k
    isl_blk_free_force(ctx, block);
125
5.95M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
986
{
129
986
  int i;
130
986
131
19.5k
  for (i = 0; 
i < ctx->n_cached19.5k
;
++i18.5k
)
132
18.5k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
986
  ctx->n_cached = 0;
134
986
}