isl_basic_map_simplify: avoid removal of div definitions in eliminate_divs_eq
[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_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->ref = 0;
23
24         isl_int_init(ctx->one);
25         isl_int_set_si(ctx->one, 1);
26
27         isl_int_init(ctx->negone);
28         isl_int_set_si(ctx->negone, -1);
29
30         isl_int_init(ctx->normalize_gcd);
31
32         ctx->n_cached = 0;
33
34 #ifdef ISL_POLYLIB
35         ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
36 #endif
37
38         ctx->lp_solver = ISL_LP_TAB;
39         ctx->ilp_solver = ISL_ILP_GBR;
40         ctx->pip = ISL_PIP_TAB;
41         ctx->context = ISL_CONTEXT_GBR;
42
43         ctx->gbr = ISL_GBR_ONCE;
44         ctx->gbr_only_first = 0;
45
46         return ctx;
47 error:
48         free(ctx);
49         return NULL;
50 }
51
52 void isl_ctx_ref(struct isl_ctx *ctx)
53 {
54         ctx->ref++;
55 }
56
57 void isl_ctx_deref(struct isl_ctx *ctx)
58 {
59         isl_assert(ctx, ctx->ref > 0, return);
60         ctx->ref--;
61 }
62
63 void isl_ctx_free(struct isl_ctx *ctx)
64 {
65         if (!ctx)
66                 return;
67         isl_assert(ctx, ctx->ref == 0, return);
68         isl_hash_table_clear(&ctx->name_hash);
69         isl_blk_clear_cache(ctx);
70         isl_int_clear(ctx->one);
71         isl_int_clear(ctx->negone);
72         isl_int_clear(ctx->normalize_gcd);
73         free(ctx->stats);
74         free(ctx);
75 }