Coverage Report

Created: 2018-08-20 19:24

/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
267k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
20.0M
{
18
20.0M
  struct isl_blk block;
19
20.0M
  block.size = 0;
20
20.0M
  block.data = NULL;
21
20.0M
  return block;
22
20.0M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
17.3M
{
26
17.3M
  return block.size == 0 && 
block.data == NULL6.99M
;
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.2M
{
39
23.2M
  return block.size == -1 && 
block.data == NULL0
;
40
23.2M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
452k
{
44
452k
  int i;
45
452k
46
49.8M
  for (i = 0; i < block.size; 
++i49.3M
)
47
49.3M
    isl_int_clear(block.data[i]);
48
452k
  free(block.data);
49
452k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
13.1M
{
54
13.1M
  int i;
55
13.1M
  isl_int *p;
56
13.1M
57
13.1M
  if (block.size >= new_n)
58
12.2M
    return block;
59
888k
60
888k
  p = isl_realloc_array(ctx, block.data, isl_int, new_n);
61
888k
  if (!p) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
888k
  block.data = p;
66
888k
67
50.3M
  for (i = block.size; i < new_n; 
++i49.4M
)
68
49.4M
    isl_int_init(block.data[i]);
69
888k
  block.size = new_n;
70
888k
71
888k
  return block;
72
888k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
13.0M
{
76
13.0M
  int i;
77
13.0M
  struct isl_blk block;
78
13.0M
79
13.0M
  block = isl_blk_empty();
80
13.0M
  if (n && 
ctx->n_cached10.2M
) {
81
10.0M
    int best = 0;
82
97.0M
    for (i = 1; ctx->cache[best].size != n && 
i < ctx->n_cached94.3M
;
++i86.9M
) {
83
86.9M
      if (ctx->cache[best].size < n) {
84
11.8M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
5.41M
          best = i;
86
75.1M
      } else if (ctx->cache[i].size >= n &&
87
75.1M
           
ctx->cache[i].size < ctx->cache[best].size46.3M
)
88
15.0M
          best = i;
89
86.9M
    }
90
10.0M
    if (ctx->cache[best].size < 2 * n + 100) {
91
9.78M
      block = ctx->cache[best];
92
9.78M
      if (--ctx->n_cached != best)
93
7.18M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
9.78M
      if (best == 0)
95
1.27M
        ctx->n_miss = 0;
96
9.78M
    } else 
if (267k
ctx->n_miss++ >= 267k
ISL_BLK_MAX_MISS267k
) {
97
193
      isl_blk_free_force(ctx, ctx->cache[0]);
98
193
      if (--ctx->n_cached != 0)
99
193
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
193
      ctx->n_miss = 0;
101
193
    }
102
10.0M
  }
103
13.0M
104
13.0M
  return extend(ctx, block, n);
105
13.0M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
244k
{
110
244k
  if (isl_blk_is_empty(block))
111
116k
    return isl_blk_alloc(ctx, new_n);
112
127k
113
127k
  return extend(ctx, block, new_n);
114
127k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
17.1M
{
118
17.1M
  if (isl_blk_is_empty(block) || 
isl_blk_is_error(block)10.2M
)
119
6.88M
    return;
120
10.2M
121
10.2M
  if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
122
10.2M
    
ctx->cache[ctx->n_cached++] = block9.80M
;
123
428k
  else
124
428k
    isl_blk_free_force(ctx, block);
125
10.2M
}
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.7k
)
132
23.7k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.25k
  ctx->n_cached = 0;
134
1.25k
}