7b83243a0f2c02360db237bf6f3049a658d52b1e
[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         ctx->ref = 0;
16
17         isl_int_init(ctx->one);
18         isl_int_set_si(ctx->one, 1);
19
20         ctx->n_cached = 0;
21
22 #ifdef ISL_POLYLIB
23         ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
24 #endif
25
26         return ctx;
27 error:
28         free(ctx);
29         return NULL;
30 }
31
32 void isl_ctx_ref(struct isl_ctx *ctx)
33 {
34         ctx->ref++;
35 }
36
37 void isl_ctx_deref(struct isl_ctx *ctx)
38 {
39         isl_assert(ctx, ctx->ref > 0, return);
40         ctx->ref--;
41 }
42
43 void isl_ctx_free(struct isl_ctx *ctx)
44 {
45         if (!ctx)
46                 return;
47         isl_assert(ctx, ctx->ref == 0, return);
48         isl_blk_clear_cache(ctx);
49         isl_int_clear(ctx->one);
50         free(ctx);
51 }