3 isl
= cdll
.LoadLibrary("libisl.so")
10 ptr
= isl
.isl_ctx_alloc()
12 Context
.instances
[ptr
] = self
15 isl
.isl_ctx_free(self
)
22 return Context
.instances
[ptr
]
25 def getDefaultInstance():
26 if Context
.defaultInstance
== None:
27 Context
.defaultInstance
= Context()
29 return Context
.defaultInstance
32 def __init__(self
, string
= "", ctx
= None, ptr
= None):
33 self
.initialize_isl_methods()
36 self
.ctx
= self
.get_isl_method("get_ctx")(self
)
40 ctx
= Context
.getDefaultInstance()
43 self
.ptr
= self
.get_isl_method("read_from_str")(ctx
, string
, -1)
46 self
.get_isl_method("free")(self
)
67 return "No isl name available"
69 def initialize_isl_methods(self
):
70 if hasattr(self
.__class
__, "initialized"):
73 self
.__class
__.initalized
= True
74 self
.get_isl_method("read_from_str").argtypes
= [Context
, c_char_p
, c_int
]
75 self
.get_isl_method("copy").argtypes
= [self
.__class
__]
76 self
.get_isl_method("copy").restype
= c_int
77 self
.get_isl_method("free").argtypes
= [self
.__class
__]
78 self
.get_isl_method("get_ctx").argtypes
= [self
.__class
__]
79 self
.get_isl_method("get_ctx").restype
= Context
.from_ptr
80 getattr(isl
, "isl_printer_print_" + self
.isl_name()).argtypes
= [Printer
, self
.__class
__]
82 def get_isl_method(self
, name
):
83 return getattr(isl
, "isl_" + self
.isl_name() + "_" + name
)
85 def to_printer(self
, printer
):
86 getattr(isl
, "isl_printer_print_" + self
.isl_name())(printer
, self
)
88 class BSet(IslObject
):
93 return BSet(ptr
= ptr
)
104 return Set(ptr
= ptr
)
110 class USet(IslObject
):
115 return USet(ptr
= ptr
)
122 class BMap(IslObject
):
127 return BMap(ptr
= ptr
)
129 def __mul__(self
, set):
130 return self
.intersect_domain(set)
136 class Map(IslObject
):
141 return Map(ptr
= ptr
)
143 def __mul__(self
, set):
144 return self
.intersect_domain(set)
152 dim
= isl
.isl_dim_copy(dim
)
153 return isl
.isl_map_lex_lt(dim
)
157 dim
= isl
.isl_dim_copy(dim
)
158 return isl
.isl_map_lex_le(dim
)
162 dim
= isl
.isl_dim_copy(dim
)
163 return isl
.isl_map_lex_gt(dim
)
167 dim
= isl
.isl_dim_copy(dim
)
168 return isl
.isl_map_lex_ge(dim
)
170 class UMap(IslObject
):
175 return UMap(ptr
= ptr
)
181 class Dim(IslObject
):
186 return Dim(ptr
= ptr
)
192 def initialize_isl_methods(self
):
193 if hasattr(self
.__class
__, "initialized"):
196 self
.__class
__.initalized
= True
197 self
.get_isl_method("copy").argtypes
= [self
.__class
__]
198 self
.get_isl_method("copy").restype
= c_int
199 self
.get_isl_method("free").argtypes
= [self
.__class
__]
200 self
.get_isl_method("get_ctx").argtypes
= [self
.__class
__]
201 self
.get_isl_method("get_ctx").restype
= Context
.from_ptr
208 dimParam
= isl
.isl_dim_size(self
, 1)
209 dimIn
= isl
.isl_dim_size(self
, 2)
210 dimOut
= isl
.isl_dim_size(self
, 3)
213 return "<dim In:%s, Out:%s, Param:%s>" % (dimIn
, dimOut
, dimParam
)
215 return "<dim Set:%s, Param:%s>" % (dimOut
, dimParam
)
220 FORMAT_POLYLIB_CONSTRAINTS
= 2
224 FORMAT_EXT_POLYLIB
= 6
226 def __init__(self
, ctx
= None):
228 ctx
= Context
.getDefaultInstance()
231 self
.ptr
= isl
.isl_printer_to_str(ctx
)
233 def setFormat(self
, format
):
234 self
.ptr
= isl
.isl_printer_set_output_format(self
, format
);
236 def from_param(self
):
240 isl
.isl_printer_free(self
)
243 return isl
.isl_printer_get_str(self
)
247 ("is_empty", BSet
, [BSet
], c_int
),
248 ("is_empty", Set
, [Set
], c_int
),
249 ("is_empty", USet
, [USet
], c_int
),
250 ("is_empty", BMap
, [BMap
], c_int
),
251 ("is_empty", Map
, [Map
], c_int
),
252 ("is_empty", UMap
, [UMap
], c_int
),
254 # ("is_universe", Set, [Set], c_int),
255 # ("is_universe", Map, [Map], c_int),
257 ("is_single_valued", Map
, [Map
], c_int
),
259 ("is_bijective", Map
, [Map
], c_int
),
261 ("is_wrapping", BSet
, [BSet
], c_int
),
262 ("is_wrapping", Set
, [Set
], c_int
),
265 ("is_equal", BSet
, [BSet
, BSet
], c_int
),
266 ("is_equal", Set
, [Set
, Set
], c_int
),
267 ("is_equal", USet
, [USet
, USet
], c_int
),
268 ("is_equal", BMap
, [BMap
, BMap
], c_int
),
269 ("is_equal", Map
, [Map
, Map
], c_int
),
270 ("is_equal", UMap
, [UMap
, UMap
], c_int
),
272 # is_disjoint missing
274 # ("is_subset", BSet, [BSet, BSet], c_int),
275 ("is_subset", Set
, [Set
, Set
], c_int
),
276 ("is_subset", USet
, [USet
, USet
], c_int
),
277 ("is_subset", BMap
, [BMap
, BMap
], c_int
),
278 ("is_subset", Map
, [Map
, Map
], c_int
),
279 ("is_subset", UMap
, [UMap
, UMap
], c_int
),
280 #("is_strict_subset", BSet, [BSet, BSet], c_int),
281 ("is_strict_subset", Set
, [Set
, Set
], c_int
),
282 ("is_strict_subset", USet
, [USet
, USet
], c_int
),
283 ("is_strict_subset", BMap
, [BMap
, BMap
], c_int
),
284 ("is_strict_subset", Map
, [Map
, Map
], c_int
),
285 ("is_strict_subset", UMap
, [UMap
, UMap
], c_int
),
288 ("complement", Set
, [Set
], Set
),
289 ("reverse", BMap
, [BMap
], BMap
),
290 ("reverse", Map
, [Map
], Map
),
291 ("reverse", UMap
, [UMap
], UMap
),
294 ("range", BMap
, [BMap
], BSet
),
295 ("range", Map
, [Map
], Set
),
296 ("range", UMap
, [UMap
], USet
),
297 ("domain", BMap
, [BMap
], BSet
),
298 ("domain", Map
, [Map
], Set
),
299 ("domain", UMap
, [UMap
], USet
),
301 ("identity", Set
, [Set
], Map
),
302 ("identity", USet
, [USet
], UMap
),
304 ("deltas", BMap
, [BMap
], BSet
),
305 ("deltas", Map
, [Map
], Set
),
306 ("deltas", UMap
, [UMap
], USet
),
308 ("coalesce", Set
, [Set
], Set
),
309 ("coalesce", USet
, [USet
], USet
),
310 ("coalesce", Map
, [Map
], Map
),
311 ("coalesce", UMap
, [UMap
], UMap
),
313 ("detect_equalities", BSet
, [BSet
], BSet
),
314 ("detect_equalities", Set
, [Set
], Set
),
315 ("detect_equalities", USet
, [USet
], USet
),
316 ("detect_equalities", BMap
, [BMap
], BMap
),
317 ("detect_equalities", Map
, [Map
], Map
),
318 ("detect_equalities", UMap
, [UMap
], UMap
),
320 ("convex_hull", Set
, [Set
], Set
),
321 ("convex_hull", Map
, [Map
], Map
),
323 ("simple_hull", Set
, [Set
], Set
),
324 ("simple_hull", Map
, [Map
], Map
),
326 ("affine_hull", BSet
, [BSet
], BSet
),
327 ("affine_hull", Set
, [Set
], BSet
),
328 ("affine_hull", USet
, [USet
], USet
),
329 ("affine_hull", BMap
, [BMap
], BMap
),
330 ("affine_hull", Map
, [Map
], BMap
),
331 ("affine_hull", UMap
, [UMap
], UMap
),
333 ("polyhedral_hull", Set
, [Set
], Set
),
334 ("polyhedral_hull", USet
, [USet
], USet
),
335 ("polyhedral_hull", Map
, [Map
], Map
),
336 ("polyhedral_hull", UMap
, [UMap
], UMap
),
339 # Transitive closure missing
340 # Reaching path lengths missing
342 ("wrap", BMap
, [BMap
], BSet
),
343 ("wrap", Map
, [Map
], Set
),
344 ("wrap", UMap
, [UMap
], USet
),
345 ("unwrap", BSet
, [BMap
], BMap
),
346 ("unwrap", Set
, [Map
], Map
),
347 ("unwrap", USet
, [UMap
], UMap
),
349 ("flatten", Set
, [Set
], Set
),
350 ("flatten", Map
, [Map
], Map
),
351 ("flatten_map", Set
, [Set
], Map
),
353 # Dimension manipulation missing
356 ("intersect", BSet
, [BSet
, BSet
], BSet
),
357 ("intersect", Set
, [Set
, Set
], Set
),
358 ("intersect", USet
, [USet
, USet
], USet
),
359 ("intersect", BMap
, [BMap
, BMap
], BMap
),
360 ("intersect", Map
, [Map
, Map
], Map
),
361 ("intersect", UMap
, [UMap
, UMap
], UMap
),
362 ("intersect_domain", BMap
, [BMap
, BSet
], BMap
),
363 ("intersect_domain", Map
, [Map
, Set
], Map
),
364 ("intersect_domain", UMap
, [UMap
, USet
], UMap
),
365 ("intersect_range", BMap
, [BMap
, BSet
], BMap
),
366 ("intersect_range", Map
, [Map
, Set
], Map
),
367 ("intersect_range", UMap
, [UMap
, USet
], UMap
),
369 ("union", BSet
, [BSet
, BSet
], Set
),
370 ("union", Set
, [Set
, Set
], Set
),
371 ("union", USet
, [USet
, USet
], USet
),
372 ("union", BMap
, [BMap
, BMap
], Map
),
373 ("union", Map
, [Map
, Map
], Map
),
374 ("union", UMap
, [UMap
, UMap
], UMap
),
376 ("subtract", Set
, [Set
, Set
], Set
),
377 ("subtract", Map
, [Map
, Map
], Map
),
378 ("subtract", USet
, [USet
, USet
], USet
),
379 ("subtract", UMap
, [UMap
, UMap
], UMap
),
381 ("apply", BSet
, [BSet
, BMap
], BSet
),
382 ("apply", Set
, [Set
, Map
], Set
),
383 ("apply", USet
, [USet
, UMap
], USet
),
384 ("apply_domain", BMap
, [BMap
, BMap
], BMap
),
385 ("apply_domain", Map
, [Map
, Map
], Map
),
386 ("apply_domain", UMap
, [UMap
, UMap
], UMap
),
387 ("apply_range", BMap
, [BMap
, BMap
], BMap
),
388 ("apply_range", Map
, [Map
, Map
], Map
),
389 ("apply_range", UMap
, [UMap
, UMap
], UMap
),
391 ("gist", BSet
, [BSet
, BSet
], BSet
),
392 ("gist", Set
, [Set
, Set
], Set
),
393 ("gist", USet
, [USet
, USet
], USet
),
394 ("gist", BMap
, [BMap
, BMap
], BMap
),
395 ("gist", Map
, [Map
, Map
], Map
),
396 ("gist", UMap
, [UMap
, UMap
], UMap
),
398 # Lexicographic Optimizations
399 # partial_lexmin missing
400 ("lexmin", BSet
, [BSet
], BSet
),
401 ("lexmin", Set
, [Set
], Set
),
402 ("lexmin", USet
, [USet
], USet
),
403 ("lexmin", BMap
, [BMap
], BMap
),
404 ("lexmin", Map
, [Map
], Map
),
405 ("lexmin", UMap
, [UMap
], UMap
),
407 ("lexmax", BSet
, [BSet
], BSet
),
408 ("lexmax", Set
, [Set
], Set
),
409 ("lexmax", USet
, [USet
], USet
),
410 ("lexmax", BMap
, [BMap
], BMap
),
411 ("lexmax", Map
, [Map
], Map
),
412 ("lexmax", UMap
, [UMap
], UMap
),
415 ("lex_lt_union_set", USet
, [USet
, USet
], UMap
),
416 ("lex_le_union_set", USet
, [USet
, USet
], UMap
),
417 ("lex_gt_union_set", USet
, [USet
, USet
], UMap
),
418 ("lex_ge_union_set", USet
, [USet
, USet
], UMap
),
423 ("get_dim", BSet
, [BSet
], Dim
),
424 ("get_dim", Set
, [Set
], Dim
),
425 ("get_dim", USet
, [USet
], Dim
),
426 ("get_dim", BMap
, [BMap
], Dim
),
427 ("get_dim", Map
, [Map
], Dim
),
428 ("get_dim", UMap
, [UMap
], Dim
)
431 def addIslFunction(object, name
):
432 functionName
= "isl_" + object.isl_name() + "_" + name
433 islFunction
= getattr(isl
, functionName
)
434 if len(islFunction
.argtypes
) == 1:
435 f
= lambda a
: islFunctionOneOp(islFunction
, a
)
436 elif len(islFunction
.argtypes
) == 2:
437 f
= lambda a
, b
: islFunctionTwoOp(islFunction
, a
, b
)
438 object.__dict
__[name
] = f
441 def islFunctionOneOp(islFunction
, ops
):
442 ops
= getattr(isl
, "isl_" + ops
.isl_name() + "_copy")(ops
)
443 return islFunction(ops
)
445 def islFunctionTwoOp(islFunction
, opOne
, opTwo
):
446 opOne
= getattr(isl
, "isl_" + opOne
.isl_name() + "_copy")(opOne
)
447 opTwo
= getattr(isl
, "isl_" + opTwo
.isl_name() + "_copy")(opTwo
)
448 return islFunction(opOne
, opTwo
)
450 for (operation
, base
, operands
, ret
) in functions
:
451 functionName
= "isl_" + base
.isl_name() + "_" + operation
452 islFunction
= getattr(isl
, functionName
)
453 if len(operands
) == 1:
454 islFunction
.argtypes
= [c_int
]
455 elif len(operands
) == 2:
456 islFunction
.argtypes
= [c_int
, c_int
]
459 islFunction
.restype
= ret
461 islFunction
.restype
= ret
.from_ptr
463 addIslFunction(base
, operation
)
465 def addIslFunctionKeep(object, name
):
466 functionName
= "isl_" + object.isl_name() + "_" + name
467 islFunction
= getattr(isl
, functionName
)
468 if len(islFunction
.argtypes
) == 1:
469 f
= lambda a
: islFunctionOneOpKeep(islFunction
, a
)
470 elif len(islFunction
.argtypes
) == 2:
471 f
= lambda a
, b
: islFunctionTwoOpKeep(islFunction
, a
, b
)
472 object.__dict
__[name
] = f
474 def islFunctionOneOpKeep(islFunction
, ops
):
475 return islFunction(ops
)
477 def islFunctionTwoOpKeep(islFunction
, opOne
, opTwo
):
478 return islFunction(opOne
, opTwo
)
480 for (operation
, base
, operands
, ret
) in keep_functions
:
481 functionName
= "isl_" + base
.isl_name() + "_" + operation
482 islFunction
= getattr(isl
, functionName
)
483 if len(operands
) == 1:
484 islFunction
.argtypes
= [c_int
]
485 elif len(operands
) == 2:
486 islFunction
.argtypes
= [c_int
, c_int
]
489 islFunction
.restype
= ret
491 islFunction
.restype
= ret
.from_ptr
493 addIslFunctionKeep(base
, operation
)
495 isl
.isl_ctx_free
.argtypes
= [Context
]
496 isl
.isl_basic_set_read_from_str
.argtypes
= [Context
, c_char_p
, c_int
]
497 isl
.isl_set_read_from_str
.argtypes
= [Context
, c_char_p
, c_int
]
498 isl
.isl_basic_set_copy
.argtypes
= [BSet
]
499 isl
.isl_basic_set_copy
.restype
= c_int
500 isl
.isl_set_copy
.argtypes
= [Set
]
501 isl
.isl_set_copy
.restype
= c_int
502 isl
.isl_set_copy
.argtypes
= [Set
]
503 isl
.isl_set_copy
.restype
= c_int
504 isl
.isl_set_free
.argtypes
= [Set
]
505 isl
.isl_basic_set_get_ctx
.argtypes
= [BSet
]
506 isl
.isl_basic_set_get_ctx
.restype
= Context
.from_ptr
507 isl
.isl_set_get_ctx
.argtypes
= [Set
]
508 isl
.isl_set_get_ctx
.restype
= Context
.from_ptr
509 isl
.isl_basic_set_get_dim
.argtypes
= [BSet
]
510 isl
.isl_basic_set_get_dim
.restype
= Dim
.from_ptr
511 isl
.isl_set_get_dim
.argtypes
= [Set
]
512 isl
.isl_set_get_dim
.restype
= Dim
.from_ptr
513 isl
.isl_union_set_get_dim
.argtypes
= [USet
]
514 isl
.isl_union_set_get_dim
.restype
= Dim
.from_ptr
516 isl
.isl_basic_map_read_from_str
.argtypes
= [Context
, c_char_p
, c_int
]
517 isl
.isl_map_read_from_str
.argtypes
= [Context
, c_char_p
, c_int
]
518 isl
.isl_basic_map_free
.argtypes
= [BMap
]
519 isl
.isl_map_free
.argtypes
= [Map
]
520 isl
.isl_basic_map_copy
.argtypes
= [BMap
]
521 isl
.isl_basic_map_copy
.restype
= c_int
522 isl
.isl_map_copy
.argtypes
= [Map
]
523 isl
.isl_map_copy
.restype
= c_int
524 isl
.isl_map_get_ctx
.argtypes
= [Map
]
525 isl
.isl_basic_map_get_ctx
.argtypes
= [BMap
]
526 isl
.isl_basic_map_get_ctx
.restype
= Context
.from_ptr
527 isl
.isl_map_get_ctx
.argtypes
= [Map
]
528 isl
.isl_map_get_ctx
.restype
= Context
.from_ptr
529 isl
.isl_basic_map_get_dim
.argtypes
= [BMap
]
530 isl
.isl_basic_map_get_dim
.restype
= Dim
.from_ptr
531 isl
.isl_map_get_dim
.argtypes
= [Map
]
532 isl
.isl_map_get_dim
.restype
= Dim
.from_ptr
533 isl
.isl_union_map_get_dim
.argtypes
= [UMap
]
534 isl
.isl_union_map_get_dim
.restype
= Dim
.from_ptr
535 isl
.isl_printer_free
.argtypes
= [Printer
]
536 isl
.isl_printer_to_str
.argtypes
= [Context
]
537 isl
.isl_printer_print_basic_set
.argtypes
= [Printer
, BSet
]
538 isl
.isl_printer_print_set
.argtypes
= [Printer
, Set
]
539 isl
.isl_printer_print_basic_map
.argtypes
= [Printer
, BMap
]
540 isl
.isl_printer_print_map
.argtypes
= [Printer
, Map
]
541 isl
.isl_printer_get_str
.argtypes
= [Printer
]
542 isl
.isl_printer_get_str
.restype
= c_char_p
543 isl
.isl_printer_set_output_format
.argtypes
= [Printer
, c_int
]
544 isl
.isl_printer_set_output_format
.restype
= c_int
545 isl
.isl_dim_size
.argtypes
= [Dim
, c_int
]
546 isl
.isl_dim_size
.restype
= c_int
548 isl
.isl_map_lex_lt
.argtypes
= [c_int
]
549 isl
.isl_map_lex_lt
.restype
= Map
.from_ptr
550 isl
.isl_map_lex_le
.argtypes
= [c_int
]
551 isl
.isl_map_lex_le
.restype
= Map
.from_ptr
552 isl
.isl_map_lex_gt
.argtypes
= [c_int
]
553 isl
.isl_map_lex_gt
.restype
= Map
.from_ptr
554 isl
.isl_map_lex_ge
.argtypes
= [c_int
]
555 isl
.isl_map_lex_ge
.restype
= Map
.from_ptr
557 isl
.isl_union_map_compute_flow
.argtypes
= [c_int
, c_int
, c_int
, c_int
, c_void_p
,
558 c_void_p
, c_void_p
, c_void_p
]
560 def dependences(sink
, must_source
, may_source
, schedule
):
561 sink
= getattr(isl
, "isl_" + sink
.isl_name() + "_copy")(sink
)
562 must_source
= getattr(isl
, "isl_" + must_source
.isl_name() + "_copy")(must_source
)
563 may_source
= getattr(isl
, "isl_" + may_source
.isl_name() + "_copy")(may_source
)
564 schedule
= getattr(isl
, "isl_" + schedule
.isl_name() + "_copy")(schedule
)
567 must_no_source
= c_int()
568 may_no_source
= c_int()
569 isl
.isl_union_map_compute_flow(sink
, must_source
, may_source
, schedule
, \
570 byref(must_dep
), byref(may_dep
),
571 byref(must_no_source
),
572 byref(may_no_source
))
574 return (UMap
.from_ptr(must_dep
), UMap
.from_ptr(may_dep
), \
575 USet
.from_ptr(must_no_source
), USet
.from_ptr(may_no_source
))
578 __all__
= ['Set', 'Map', 'Printer', 'Context']