Coverage Report

Created: 2018-10-23 09:19

/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
284k
#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.10M
;
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.7M
{
39
23.7M
  return block.size == -1 && 
block.data == NULL0
;
40
23.7M
}
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
52.3M
  for (i = 0; i < block.size; 
++i51.8M
)
47
51.8M
    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.4M
{
54
13.4M
  int i;
55
13.4M
  isl_int *p;
56
13.4M
57
13.4M
  if (block.size >= new_n)
58
12.5M
    return block;
59
912k
60
912k
  p = isl_realloc_array(ctx, block.data, isl_int, new_n);
61
912k
  if (!p) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
912k
  block.data = p;
66
912k
67
52.8M
  for (i = block.size; i < new_n; 
++i51.9M
)
68
51.9M
    isl_int_init(block.data[i]);
69
912k
  block.size = new_n;
70
912k
71
912k
  return block;
72
912k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
13.2M
{
76
13.2M
  int i;
77
13.2M
  struct isl_blk block;
78
13.2M
79
13.2M
  block = isl_blk_empty();
80
13.2M
  if (n && 
ctx->n_cached10.4M
) {
81
10.2M
    int best = 0;
82
99.8M
    for (i = 1; ctx->cache[best].size != n && 
i < ctx->n_cached97.0M
;
++i89.5M
) {
83
89.5M
      if (ctx->cache[best].size < n) {
84
12.0M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
5.56M
          best = i;
86
77.4M
      } else if (ctx->cache[i].size >= n &&
87
77.4M
           
ctx->cache[i].size < ctx->cache[best].size47.5M
)
88
15.4M
          best = i;
89
89.5M
    }
90
10.2M
    if (ctx->cache[best].size < 2 * n + 100) {
91
9.99M
      block = ctx->cache[best];
92
9.99M
      if (--ctx->n_cached != best)
93
7.35M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
9.99M
      if (best == 0)
95
1.29M
        ctx->n_miss = 0;
96
9.99M
    } else 
if (284k
ctx->n_miss++ >= 284k
ISL_BLK_MAX_MISS284k
) {
97
205
      isl_blk_free_force(ctx, ctx->cache[0]);
98
205
      if (--ctx->n_cached != 0)
99
205
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
205
      ctx->n_miss = 0;
101
205
    }
102
10.2M
  }
103
13.2M
104
13.2M
  return extend(ctx, block, n);
105
13.2M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
248k
{
110
248k
  if (isl_blk_is_empty(block))
111
118k
    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.4M
)
119
6.98M
    return;
120
10.4M
121
10.4M
  if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
122
10.4M
    
ctx->cache[ctx->n_cached++] = block10.0M
;
123
447k
  else
124
447k
    isl_blk_free_force(ctx, block);
125
10.4M
}
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
}