940f51aed26f68896efbeb6e75ede97509768d55
[platform/upstream/isl.git] / isl_ctx.c
1 #include "isl_ctx.h"
2 #include "isl_vec.h"
3
4 isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt)
5 {
6         struct isl_ctx *ctx = NULL;
7
8         if (!opt)
9                 return NULL;
10
11         ctx = isl_calloc_type(NULL, struct isl_ctx);
12         if (!ctx)
13                 goto error;
14
15         if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
16                 goto error;
17
18         ctx->stats = isl_calloc_type(ctx, struct isl_stats);
19         if (!ctx->stats)
20                 goto error;
21
22         ctx->opt = opt;
23         ctx->ref = 0;
24
25         isl_int_init(ctx->one);
26         isl_int_set_si(ctx->one, 1);
27
28         isl_int_init(ctx->negone);
29         isl_int_set_si(ctx->negone, -1);
30
31         isl_int_init(ctx->normalize_gcd);
32
33         ctx->n_cached = 0;
34
35         return ctx;
36 error:
37         free(ctx);
38         return NULL;
39 }
40
41 struct isl_ctx *isl_ctx_alloc()
42 {
43         struct isl_options *opt;
44
45         opt = isl_options_new_with_defaults();
46
47         return isl_ctx_alloc_with_options(opt);
48 }
49
50 void isl_ctx_ref(struct isl_ctx *ctx)
51 {
52         ctx->ref++;
53 }
54
55 void isl_ctx_deref(struct isl_ctx *ctx)
56 {
57         isl_assert(ctx, ctx->ref > 0, return);
58         ctx->ref--;
59 }
60
61 void isl_ctx_free(struct isl_ctx *ctx)
62 {
63         if (!ctx)
64                 return;
65         isl_assert(ctx, ctx->ref == 0, return);
66         isl_hash_table_clear(&ctx->name_hash);
67         isl_blk_clear_cache(ctx);
68         isl_int_clear(ctx->one);
69         isl_int_clear(ctx->negone);
70         isl_int_clear(ctx->normalize_gcd);
71         free(ctx->opt);
72         free(ctx->stats);
73         free(ctx);
74 }
75
76 struct isl_options *isl_ctx_options(isl_ctx *ctx)
77 {
78         if (!ctx)
79                 return NULL;
80         return ctx->opt;
81 }