add isl_basic_map_add_ineq and isl_basic_map_add_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 isl_ctx *isl_ctx_alloc_with_options(struct isl_options *opt)
8 {
9         struct isl_ctx *ctx = NULL;
10
11         if (!opt)
12                 return NULL;
13
14         ctx = isl_calloc_type(NULL, struct isl_ctx);
15         if (!ctx)
16                 goto error;
17
18         if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
19                 goto error;
20
21         ctx->stats = isl_calloc_type(ctx, struct isl_stats);
22         if (!ctx->stats)
23                 goto error;
24
25         ctx->opt = opt;
26         ctx->ref = 0;
27
28         isl_int_init(ctx->one);
29         isl_int_set_si(ctx->one, 1);
30
31         isl_int_init(ctx->negone);
32         isl_int_set_si(ctx->negone, -1);
33
34         isl_int_init(ctx->normalize_gcd);
35
36         ctx->n_cached = 0;
37
38 #ifdef ISL_POLYLIB
39         ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
40 #endif
41
42         return ctx;
43 error:
44         free(ctx);
45         return NULL;
46 }
47
48 struct isl_ctx *isl_ctx_alloc()
49 {
50         struct isl_options *opt;
51
52         opt = isl_options_new_with_defaults();
53
54         return isl_ctx_alloc_with_options(opt);
55 }
56
57 void isl_ctx_ref(struct isl_ctx *ctx)
58 {
59         ctx->ref++;
60 }
61
62 void isl_ctx_deref(struct isl_ctx *ctx)
63 {
64         isl_assert(ctx, ctx->ref > 0, return);
65         ctx->ref--;
66 }
67
68 void isl_ctx_free(struct isl_ctx *ctx)
69 {
70         if (!ctx)
71                 return;
72         isl_assert(ctx, ctx->ref == 0, return);
73         isl_hash_table_clear(&ctx->name_hash);
74         isl_blk_clear_cache(ctx);
75         isl_int_clear(ctx->one);
76         isl_int_clear(ctx->negone);
77         isl_int_clear(ctx->normalize_gcd);
78         free(ctx->opt);
79         free(ctx->stats);
80         free(ctx);
81 }
82
83 struct isl_options *isl_ctx_options(isl_ctx *ctx)
84 {
85         if (!ctx)
86                 return NULL;
87         return ctx->opt;
88 }