ax_create_stdint_h.m4: protect some limits from redefinition
[isl.git] / include / isl_ctx.h
blob874b1a889cc933c3eeb78c3174b154c5bd74772c
1 #ifndef ISL_CTX_H
2 #define ISL_CTX_H
4 #include <assert.h>
5 #include <stdlib.h>
7 #include <isl_int.h>
8 #include <isl_blk.h>
9 #include <isl_hash.h>
10 #include <isl_libs.h>
12 #if defined(__cplusplus)
13 extern "C" {
14 #endif
16 /* Nearly all isa functions require a struct isl_ctx allocated using
17 * isl_ctx_alloc. This ctx contains (or will contain) options that
18 * control the behavior of the library and some caches.
20 * An object allocated within a given ctx should never be used inside
21 * another ctx. Functions for moving objects from one ctx to another
22 * will be added as the need arises.
24 * A given context should only be used inside a single thread.
25 * A global context for synchronization between different threads
26 * as well as functions for moving a context to a different thread
27 * will be added as the need arises.
29 * If anything goes wrong (out of memory, failed assertion), then
30 * the library will currently simply abort. This will be made
31 * configurable in the future.
32 * Users of the library should expect functions that return
33 * a pointer to a structure, to return NULL, indicating failure.
34 * Any function accepting a pointer to a structure will treat
35 * a NULL argument as a failure, resulting in the function freeing
36 * the remaining structures (if any) and returning NULL itself
37 * (in case of pointer return type).
38 * The only exception is the isl_ctx argument, which shoud never be NULL.
40 struct isl_stats {
41 long gbr_solved_lps;
43 struct isl_ctx {
44 int ref;
46 struct isl_stats *stats;
48 isl_int one;
49 isl_int negone;
51 isl_int normalize_gcd;
53 int n_cached;
54 struct isl_blk cache[ISL_BLK_CACHE_SIZE];
55 struct isl_hash_table name_hash;
56 #ifdef ISL_POLYLIB
57 unsigned MaxRays;
58 #endif
60 #define ISL_LP_TAB 0
61 #define ISL_LP_PIP 1
62 unsigned lp_solver;
64 #define ISL_ILP_GBR 0
65 #define ISL_ILP_PIP 1
66 unsigned ilp_solver;
68 #define ISL_PIP_TAB 0
69 #define ISL_PIP_PIP 1
70 unsigned pip;
72 #define ISL_GBR_NEVER 0
73 #define ISL_GBR_ONCE 1
74 #define ISL_GBR_ALWAYS 2
75 unsigned gbr;
76 unsigned gbr_only_first;
79 /* Some helper macros */
81 #define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
82 #define ISL_FL_SET(l, f) ((l) |= (f))
83 #define ISL_FL_CLR(l, f) ((l) &= ~(f))
84 #define ISL_FL_ISSET(l, f) (!!((l) & (f)))
86 #define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
87 #define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
88 #define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
89 #define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
91 #define isl_alloc(ctx,type,size) (type *)malloc(size)
92 #define isl_calloc(ctx,type,size) (type *)calloc(1, size)
93 #define isl_realloc(ctx,ptr,type,size) (type *)realloc(ptr,size)
94 #define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
95 #define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
96 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
97 #define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
98 #define isl_calloc_array(ctx,type,n) (type *)calloc(n, sizeof(type))
99 #define isl_realloc_array(ctx,ptr,type,n) \
100 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
102 #define isl_assert(ctx,test,code) assert(test)
104 #define isl_min(a,b) ((a < b) ? (a) : (b))
106 /* struct isl_ctx functions */
108 struct isl_ctx *isl_ctx_alloc();
109 void isl_ctx_ref(struct isl_ctx *ctx);
110 void isl_ctx_deref(struct isl_ctx *ctx);
111 void isl_ctx_free(struct isl_ctx *ctx);
113 #if defined(__cplusplus)
115 #endif
117 #endif