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