24f1455dfd9250e9446f0d59e447c0027a499cfa
[platform/upstream/isl.git] / isl_ctx.c
1 #include "isl_ctx.h"
2 #include "isl_vec.h"
3 #ifdef ISL_POLYLIB
4 #include <polylib/polylibgmp.h>
5 #endif
6
7 struct isl_ctx *isl_ctx_alloc()
8 {
9         struct isl_ctx *ctx = NULL;
10
11         ctx = isl_alloc_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->ref = 0;
19
20         isl_int_init(ctx->one);
21         isl_int_set_si(ctx->one, 1);
22
23         ctx->n_cached = 0;
24
25 #ifdef ISL_POLYLIB
26         ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
27 #endif
28
29         return ctx;
30 error:
31         free(ctx);
32         return NULL;
33 }
34
35 void isl_ctx_ref(struct isl_ctx *ctx)
36 {
37         ctx->ref++;
38 }
39
40 void isl_ctx_deref(struct isl_ctx *ctx)
41 {
42         isl_assert(ctx, ctx->ref > 0, return);
43         ctx->ref--;
44 }
45
46 void isl_ctx_free(struct isl_ctx *ctx)
47 {
48         if (!ctx)
49                 return;
50         isl_assert(ctx, ctx->ref == 0, return);
51         isl_hash_table_clear(&ctx->name_hash);
52         isl_blk_clear_cache(ctx);
53         isl_int_clear(ctx->one);
54         free(ctx);
55 }