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