introduce generalized basis reduction based sampling
[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         ctx->n_cached = 0;
31
32 #ifdef ISL_POLYLIB
33         ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
34 #endif
35
36         ctx->lp_solver = ISL_LP_TAB;
37         ctx->ilp_solver = ISL_ILP_GBR;
38
39         return ctx;
40 error:
41         free(ctx);
42         return NULL;
43 }
44
45 void isl_ctx_ref(struct isl_ctx *ctx)
46 {
47         ctx->ref++;
48 }
49
50 void isl_ctx_deref(struct isl_ctx *ctx)
51 {
52         isl_assert(ctx, ctx->ref > 0, return);
53         ctx->ref--;
54 }
55
56 void isl_ctx_free(struct isl_ctx *ctx)
57 {
58         if (!ctx)
59                 return;
60         isl_assert(ctx, ctx->ref == 0, return);
61         isl_hash_table_clear(&ctx->name_hash);
62         isl_blk_clear_cache(ctx);
63         isl_int_clear(ctx->one);
64         isl_int_clear(ctx->negone);
65         free(ctx->stats);
66         free(ctx);
67 }