Coverage Report

Created: 2018-04-23 18:20

/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
289k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
20.4M
{
18
20.4M
  struct isl_blk block;
19
20.4M
  block.size = 0;
20
20.4M
  block.data = NULL;
21
20.4M
  return block;
22
20.4M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
17.7M
{
26
17.7M
  return block.size == 0 && 
block.data == NULL7.25M
;
27
17.7M
}
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.4M
{
39
23.4M
  return block.size == -1 && 
block.data == NULL0
;
40
23.4M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
471k
{
44
471k
  int i;
45
471k
46
54.5M
  for (i = 0; i < block.size; 
++i54.1M
)
47
54.1M
    isl_int_clear(block.data[i]);
48
471k
  free(block.data);
49
471k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
13.3M
{
54
13.3M
  int i;
55
13.3M
  isl_int *p;
56
13.3M
57
13.3M
  if (block.size >= new_n)
58
12.4M
    return block;
59
877k
60
877k
  p = isl_realloc_array(ctx, block.data, isl_int, new_n);
61
877k
  if (!p) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
877k
  block.data = p;
66
877k
67
55.0M
  for (i = block.size; i < new_n; 
++i54.1M
)
68
54.1M
    isl_int_init(block.data[i]);
69
877k
  block.size = new_n;
70
877k
71
877k
  return block;
72
877k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
13.1M
{
76
13.1M
  int i;
77
13.1M
  struct isl_blk block;
78
13.1M
79
13.1M
  block = isl_blk_empty();
80
13.1M
  if (n && 
ctx->n_cached10.3M
) {
81
10.1M
    int best = 0;
82
98.5M
    for (i = 1; ctx->cache[best].size != n && 
i < ctx->n_cached95.8M
;
++i88.4M
) {
83
88.4M
      if (ctx->cache[best].size < n) {
84
10.9M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
5.29M
          best = i;
86
77.5M
      } else if (ctx->cache[i].size >= n &&
87
77.5M
           
ctx->cache[i].size < ctx->cache[best].size46.3M
)
88
15.3M
          best = i;
89
88.4M
    }
90
10.1M
    if (ctx->cache[best].size < 2 * n + 100) {
91
9.84M
      block = ctx->cache[best];
92
9.84M
      if (--ctx->n_cached != best)
93
7.26M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
9.84M
      if (best == 0)
95
1.27M
        ctx->n_miss = 0;
96
9.84M
    } else 
if (289k
ctx->n_miss++ >= 289k
ISL_BLK_MAX_MISS289k
) {
97
186
      isl_blk_free_force(ctx, ctx->cache[0]);
98
186
      if (--ctx->n_cached != 0)
99
186
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
186
      ctx->n_miss = 0;
101
186
    }
102
10.1M
  }
103
13.1M
104
13.1M
  return extend(ctx, block, n);
105
13.1M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
247k
{
110
247k
  if (isl_blk_is_empty(block))
111
116k
    return isl_blk_alloc(ctx, new_n);
112
130k
113
130k
  return extend(ctx, block, new_n);
114
130k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
17.4M
{
118
17.4M
  if (isl_blk_is_empty(block) || 
isl_blk_is_error(block)10.3M
)
119
7.13M
    return;
120
10.3M
121
10.3M
  if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
122
10.3M
    
ctx->cache[ctx->n_cached++] = block9.86M
;
123
447k
  else
124
447k
    isl_blk_free_force(ctx, block);
125
10.3M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.25k
{
129
1.25k
  int i;
130
1.25k
131
25.0k
  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
}