Coverage Report

Created: 2017-06-28 17:40

/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
153k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
14.5M
{
18
14.5M
  struct isl_blk block;
19
14.5M
  block.size = 0;
20
14.5M
  block.data = NULL;
21
14.5M
  return block;
22
14.5M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
12.6M
{
26
5.27M
  return block.size == 0 && block.data == NULL;
27
12.6M
}
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
16.6M
{
39
0
  return block.size == -1 && block.data == NULL;
40
16.6M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
305k
{
44
305k
  int i;
45
305k
46
28.2M
  for (i = 0; 
i < block.size28.2M
;
++i27.9M
)
47
27.9M
    isl_int_clear(block.data[i]);
48
305k
  free(block.data);
49
305k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
9.43M
{
54
9.43M
  int i;
55
9.43M
  isl_int *p;
56
9.43M
57
9.43M
  if (block.size >= new_n)
58
8.83M
    return block;
59
9.43M
60
600k
  
p = 600k
isl_realloc_array600k
(ctx, block.data, isl_int, new_n);
61
600k
  if (
!p600k
)
{0
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
600k
  block.data = p;
66
600k
67
28.5M
  for (i = block.size; 
i < new_n28.5M
;
++i27.9M
)
68
27.9M
    isl_int_init(block.data[i]);
69
600k
  block.size = new_n;
70
600k
71
600k
  return block;
72
600k
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
9.33M
{
76
9.33M
  int i;
77
9.33M
  struct isl_blk block;
78
9.33M
79
9.33M
  block = isl_blk_empty();
80
9.33M
  if (
n && 9.33M
ctx->n_cached7.28M
)
{7.13M
81
7.13M
    int best = 0;
82
66.1M
    for (i = 1; 
ctx->cache[best].size != n && 66.1M
i < ctx->n_cached64.2M
;
++i59.0M
)
{59.0M
83
59.0M
      if (
ctx->cache[best].size < n59.0M
)
{7.03M
84
7.03M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
3.34M
          best = i;
86
52.0M
      } else 
if (52.0M
ctx->cache[i].size >= n &&52.0M
87
33.5M
           ctx->cache[i].size < ctx->cache[best].size)
88
10.9M
          best = i;
89
59.0M
    }
90
7.13M
    if (
ctx->cache[best].size < 2 * n + 1007.13M
)
{6.98M
91
6.98M
      block = ctx->cache[best];
92
6.98M
      if (--ctx->n_cached != best)
93
5.06M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
6.98M
      if (best == 0)
95
984k
        ctx->n_miss = 0;
96
153k
    } else 
if (153k
ctx->n_miss++ >= 153k
ISL_BLK_MAX_MISS153k
)
{106
97
106
      isl_blk_free_force(ctx, ctx->cache[0]);
98
106
      if (--ctx->n_cached != 0)
99
105
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
106
      ctx->n_miss = 0;
101
106
    }
102
7.13M
  }
103
9.33M
104
9.33M
  return extend(ctx, block, n);
105
9.33M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
182k
{
110
182k
  if (isl_blk_is_empty(block))
111
82.1k
    return isl_blk_alloc(ctx, new_n);
112
182k
113
100k
  return extend(ctx, block, new_n);
114
182k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
12.4M
{
118
12.4M
  if (
isl_blk_is_empty(block) || 12.4M
isl_blk_is_error(block)7.28M
)
119
5.19M
    return;
120
12.4M
121
7.28M
  
if (7.28M
ctx->n_cached < 7.28M
ISL_BLK_CACHE_SIZE7.28M
)
122
7.00M
    ctx->cache[ctx->n_cached++] = block;
123
7.28M
  else
124
284k
    isl_blk_free_force(ctx, block);
125
7.28M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
1.11k
{
129
1.11k
  int i;
130
1.11k
131
22.0k
  for (i = 0; 
i < ctx->n_cached22.0k
;
++i20.9k
)
132
20.9k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
1.11k
  ctx->n_cached = 0;
134
1.11k
}