add isl_pw_*_plain_is_equal
[isl.git] / include / isl / ctx.h
blob33d1f572b52a24b53570649d923eafb6e1270d08
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_CTX_H
11 #define ISL_CTX_H
13 #include <stdio.h>
14 #include <stdlib.h>
16 #include <isl/int.h>
17 #include <isl/options.h>
18 #include <isl/blk.h>
19 #include <isl/hash.h>
20 #include <isl/config.h>
22 #define __isl_give
23 #define __isl_take
24 #define __isl_keep
26 #ifdef GCC_WARN_UNUSED_RESULT
27 #define WARN_UNUSED GCC_WARN_UNUSED_RESULT
28 #else
29 #define WARN_UNUSED
30 #endif
32 #if defined(__cplusplus)
33 extern "C" {
34 #endif
36 /* Nearly all isa functions require a struct isl_ctx allocated using
37 * isl_ctx_alloc. This ctx contains (or will contain) options that
38 * control the behavior of the library and some caches.
40 * An object allocated within a given ctx should never be used inside
41 * another ctx. Functions for moving objects from one ctx to another
42 * will be added as the need arises.
44 * A given context should only be used inside a single thread.
45 * A global context for synchronization between different threads
46 * as well as functions for moving a context to a different thread
47 * will be added as the need arises.
49 * If anything goes wrong (out of memory, failed assertion), then
50 * the library will currently simply abort. This will be made
51 * configurable in the future.
52 * Users of the library should expect functions that return
53 * a pointer to a structure, to return NULL, indicating failure.
54 * Any function accepting a pointer to a structure will treat
55 * a NULL argument as a failure, resulting in the function freeing
56 * the remaining structures (if any) and returning NULL itself
57 * (in case of pointer return type).
58 * The only exception is the isl_ctx argument, which should never be NULL.
60 struct isl_stats {
61 long gbr_solved_lps;
63 enum isl_error {
64 isl_error_none = 0,
65 isl_error_abort,
66 isl_error_unknown,
67 isl_error_internal,
68 isl_error_invalid,
69 isl_error_unsupported
71 struct isl_ctx;
72 typedef struct isl_ctx isl_ctx;
74 /* Some helper macros */
76 #define ISL_FL_INIT(l, f) (l) = (f) /* Specific flags location. */
77 #define ISL_FL_SET(l, f) ((l) |= (f))
78 #define ISL_FL_CLR(l, f) ((l) &= ~(f))
79 #define ISL_FL_ISSET(l, f) (!!((l) & (f)))
81 #define ISL_F_INIT(p, f) ISL_FL_INIT((p)->flags, f) /* Structure element flags. */
82 #define ISL_F_SET(p, f) ISL_FL_SET((p)->flags, f)
83 #define ISL_F_CLR(p, f) ISL_FL_CLR((p)->flags, f)
84 #define ISL_F_ISSET(p, f) ISL_FL_ISSET((p)->flags, f)
86 /* isl_check_ctx() checks at compile time if 'ctx' is of type 'isl_ctx *' and
87 * returns the value of 'expr'. It is used to ensure, that always an isl_ctx is
88 * passed to the following macros, even if they currently do not use it.
90 #define isl_check_ctx(ctx, expr) (ctx != (isl_ctx *) 0) ? expr : expr
92 #define isl_alloc(ctx,type,size) isl_check_ctx(ctx, (type *)malloc(size))
93 #define isl_calloc(ctx,type,size) isl_check_ctx(ctx, \
94 (type *)calloc(1, size))
95 #define isl_realloc(ctx,ptr,type,size) isl_check_ctx(ctx, \
96 (type *)realloc(ptr,size))
97 #define isl_alloc_type(ctx,type) isl_alloc(ctx,type,sizeof(type))
98 #define isl_calloc_type(ctx,type) isl_calloc(ctx,type,sizeof(type))
99 #define isl_realloc_type(ctx,ptr,type) isl_realloc(ctx,ptr,type,sizeof(type))
100 #define isl_alloc_array(ctx,type,n) isl_alloc(ctx,type,(n)*sizeof(type))
101 #define isl_calloc_array(ctx,type,n) isl_check_ctx(ctx,\
102 (type *)calloc(n, sizeof(type)))
103 #define isl_realloc_array(ctx,ptr,type,n) \
104 isl_realloc(ctx,ptr,type,(n)*sizeof(type))
106 #define isl_die(ctx,errno,msg,code) \
107 do { \
108 isl_ctx_set_error(ctx, errno); \
109 fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \
110 code; \
111 } while (0)
112 #define isl_assert4(ctx,test,code,errno) \
113 do { \
114 if (test) \
115 break; \
116 isl_die(ctx, errno, "Assertion \"" #test "\" failed", code); \
117 } while (0)
118 #define isl_assert(ctx,test,code) \
119 isl_assert4(ctx,test,code,isl_error_unknown)
121 #define isl_min(a,b) ((a < b) ? (a) : (b))
123 /* struct isl_ctx functions */
125 struct isl_options *isl_ctx_options(isl_ctx *ctx);
127 isl_ctx *isl_ctx_alloc_with_options(struct isl_arg *arg, __isl_take void *opt);
128 isl_ctx *isl_ctx_alloc(void);
129 void *isl_ctx_peek_options(isl_ctx *ctx, struct isl_arg *arg);
130 void isl_ctx_ref(struct isl_ctx *ctx);
131 void isl_ctx_deref(struct isl_ctx *ctx);
132 void isl_ctx_free(isl_ctx *ctx);
134 void isl_ctx_abort(isl_ctx *ctx);
135 void isl_ctx_resume(isl_ctx *ctx);
136 int isl_ctx_aborted(isl_ctx *ctx);
138 #define ISL_ARG_CTX_DECL(prefix,st,arg) \
139 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx);
141 #define ISL_ARG_CTX_DEF(prefix,st,arg) \
142 st *isl_ctx_peek_ ## prefix(isl_ctx *ctx) \
144 return (st *)isl_ctx_peek_options(ctx, arg); \
147 enum isl_error isl_ctx_last_error(isl_ctx *ctx);
148 void isl_ctx_reset_error(isl_ctx *ctx);
149 void isl_ctx_set_error(isl_ctx *ctx, enum isl_error error);
151 #if defined(__cplusplus)
153 #endif
155 #endif