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