summaryrefslogtreecommitdiff
path: root/isl_ctx.c
blob: a9e29f7f202347cfd6322c076d0904a7521cbebf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "isl_ctx.h"
#include "isl_vec.h"
#ifdef ISL_POLYLIB
#include <polylib/polylibgmp.h>
#endif

struct isl_ctx *isl_ctx_alloc()
{
	struct isl_ctx *ctx = NULL;

	ctx = isl_calloc_type(NULL, struct isl_ctx);
	if (!ctx)
		goto error;

	if (isl_hash_table_init(ctx, &ctx->name_hash, 0))
		goto error;

	ctx->stats = isl_calloc_type(ctx, struct isl_stats);
	if (!ctx->stats)
		goto error;

	ctx->ref = 0;

	isl_int_init(ctx->one);
	isl_int_set_si(ctx->one, 1);

	isl_int_init(ctx->negone);
	isl_int_set_si(ctx->negone, -1);

	isl_int_init(ctx->normalize_gcd);

	ctx->n_cached = 0;

#ifdef ISL_POLYLIB
	ctx->MaxRays = POL_NO_DUAL | POL_INTEGER;
#endif

	ctx->lp_solver = ISL_LP_TAB;
	ctx->ilp_solver = ISL_ILP_GBR;
	ctx->pip = ISL_PIP_TAB;

	ctx->gbr = ISL_GBR_ONCE;
	ctx->gbr_only_first = 0;

	return ctx;
error:
	free(ctx);
	return NULL;
}

void isl_ctx_ref(struct isl_ctx *ctx)
{
	ctx->ref++;
}

void isl_ctx_deref(struct isl_ctx *ctx)
{
	isl_assert(ctx, ctx->ref > 0, return);
	ctx->ref--;
}

void isl_ctx_free(struct isl_ctx *ctx)
{
	if (!ctx)
		return;
	isl_assert(ctx, ctx->ref == 0, return);
	isl_hash_table_clear(&ctx->name_hash);
	isl_blk_clear_cache(ctx);
	isl_int_clear(ctx->one);
	isl_int_clear(ctx->negone);
	isl_int_clear(ctx->normalize_gcd);
	free(ctx->stats);
	free(ctx);
}