Coverage Report

Created: 2017-11-21 16:49

/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
134k
#define ISL_BLK_MAX_MISS  100
15
16
struct isl_blk isl_blk_empty()
17
7.82M
{
18
7.82M
  struct isl_blk block;
19
7.82M
  block.size = 0;
20
7.82M
  block.data = NULL;
21
7.82M
  return block;
22
7.82M
}
23
24
static int isl_blk_is_empty(struct isl_blk block)
25
6.77M
{
26
6.77M
  return block.size == 0 && 
block.data == NULL2.59M
;
27
6.77M
}
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
9.26M
{
39
9.26M
  return block.size == -1 && 
block.data == NULL0
;
40
9.26M
}
41
42
static void isl_blk_free_force(struct isl_ctx *ctx, struct isl_blk block)
43
196k
{
44
196k
  int i;
45
196k
46
28.3M
  for (i = 0; i < block.size; 
++i28.1M
)
47
28.1M
    isl_int_clear(block.data[i]);
48
196k
  free(block.data);
49
196k
}
50
51
static struct isl_blk extend(struct isl_ctx *ctx, struct isl_blk block,
52
        size_t new_n)
53
5.20M
{
54
5.20M
  int i;
55
5.20M
  isl_int *p;
56
5.20M
57
5.20M
  if (block.size >= new_n)
58
4.81M
    return block;
59
389k
60
389k
  p = isl_realloc_array(ctx, block.data, isl_int, new_n);
61
389k
  if (!p) {
62
0
    isl_blk_free_force(ctx, block);
63
0
    return isl_blk_error();
64
0
  }
65
389k
  block.data = p;
66
389k
67
28.5M
  for (i = block.size; i < new_n; 
++i28.1M
)
68
28.1M
    isl_int_init(block.data[i]);
69
5.20M
  block.size = new_n;
70
5.20M
71
5.20M
  return block;
72
5.20M
}
73
74
struct isl_blk isl_blk_alloc(struct isl_ctx *ctx, size_t n)
75
5.14M
{
76
5.14M
  int i;
77
5.14M
  struct isl_blk block;
78
5.14M
79
5.14M
  block = isl_blk_empty();
80
5.14M
  if (n && 
ctx->n_cached4.12M
) {
81
4.06M
    int best = 0;
82
39.7M
    for (i = 1; ctx->cache[best].size != n && 
i < ctx->n_cached38.7M
;
++i35.7M
) {
83
35.7M
      if (ctx->cache[best].size < n) {
84
5.68M
        if (ctx->cache[i].size > ctx->cache[best].size)
85
2.48M
          best = i;
86
30.0M
      } else if (ctx->cache[i].size >= n &&
87
30.0M
           
ctx->cache[i].size < ctx->cache[best].size17.6M
)
88
5.80M
          best = i;
89
35.7M
    }
90
4.06M
    if (ctx->cache[best].size < 2 * n + 100) {
91
3.92M
      block = ctx->cache[best];
92
3.92M
      if (--ctx->n_cached != best)
93
2.89M
        ctx->cache[best] = ctx->cache[ctx->n_cached];
94
3.92M
      if (best == 0)
95
456k
        ctx->n_miss = 0;
96
3.92M
    } else 
if (134k
ctx->n_miss++ >= 134k
ISL_BLK_MAX_MISS134k
) {
97
85
      isl_blk_free_force(ctx, ctx->cache[0]);
98
85
      if (--ctx->n_cached != 0)
99
85
        ctx->cache[0] = ctx->cache[ctx->n_cached];
100
134k
      ctx->n_miss = 0;
101
134k
    }
102
4.06M
  }
103
5.14M
104
5.14M
  return extend(ctx, block, n);
105
5.14M
}
106
107
struct isl_blk isl_blk_extend(struct isl_ctx *ctx, struct isl_blk block,
108
        size_t new_n)
109
102k
{
110
102k
  if (isl_blk_is_empty(block))
111
46.1k
    return isl_blk_alloc(ctx, new_n);
112
55.8k
113
55.8k
  return extend(ctx, block, new_n);
114
55.8k
}
115
116
void isl_blk_free(struct isl_ctx *ctx, struct isl_blk block)
117
6.66M
{
118
6.66M
  if (isl_blk_is_empty(block) || 
isl_blk_is_error(block)4.12M
)
119
2.54M
    return;
120
4.12M
121
4.12M
  if (ctx->n_cached < ISL_BLK_CACHE_SIZE)
122
4.12M
    
ctx->cache[ctx->n_cached++] = block3.93M
;
123
188k
  else
124
188k
    isl_blk_free_force(ctx, block);
125
6.66M
}
126
127
void isl_blk_clear_cache(struct isl_ctx *ctx)
128
437
{
129
437
  int i;
130
437
131
8.49k
  for (i = 0; i < ctx->n_cached; 
++i8.05k
)
132
8.05k
    isl_blk_free_force(ctx, ctx->cache[i]);
133
437
  ctx->n_cached = 0;
134
437
}