1 | |
---|
2 | (** This module provides functions to manipulate and create indexed cost |
---|
3 | labels. *) |
---|
4 | |
---|
5 | (** [Atom] provides functions for cost atoms, the root of indexed costs *) |
---|
6 | module Atom : sig |
---|
7 | include StringSig.S |
---|
8 | end |
---|
9 | |
---|
10 | (** Simple expressions corresponding to loop tranformations. |
---|
11 | TODO: leave it abstract or not? *) |
---|
12 | type sexpr |
---|
13 | |
---|
14 | val sexpr_id : sexpr |
---|
15 | |
---|
16 | (* trying a nameless approach *) |
---|
17 | type index = int |
---|
18 | |
---|
19 | val make_id : string -> index -> string |
---|
20 | |
---|
21 | type indexing = sexpr list |
---|
22 | |
---|
23 | type const_indexing |
---|
24 | |
---|
25 | val const_ind_iter : (int -> unit) -> const_indexing -> unit |
---|
26 | |
---|
27 | (** Top of the stack. |
---|
28 | @raise [Invalid_argument "non-empty indexing stack"] if argument is empty *) |
---|
29 | val curr_const_ind : const_indexing list -> const_indexing |
---|
30 | |
---|
31 | (** [enter_loop inds n] is used to update the indexing stack [ind] when one |
---|
32 | is entering a loop indexed by [n]. Raises [Invalid_argument |
---|
33 | "non-empty indexing stack"] if [inds] is empty. *) |
---|
34 | val enter_loop : const_indexing list -> index -> unit |
---|
35 | |
---|
36 | (** [enter_loop_opt inds (Some n)] behaves like [enter_loop inds n], and does |
---|
37 | nothing in case of [None]. |
---|
38 | @see enter_loop *) |
---|
39 | val enter_loop_opt : const_indexing list -> index option -> unit |
---|
40 | |
---|
41 | (** [continue_loop inds n] is used to update the indexing stack [inds] when |
---|
42 | one is continuing a loop indexed by [n]. |
---|
43 | @raise [Invalid_argument "non-empty indexing stack"] if [inds] is empty. |
---|
44 | @raise [Invalid_argument "uninitialized loop index"] if the head of |
---|
45 | [inds] has no value for [index]. *) |
---|
46 | val continue_loop : const_indexing list -> index -> unit |
---|
47 | |
---|
48 | (** [continue_loop_opt inds (Some n)] behaves like [continue_loop inds n], and |
---|
49 | does nothing in case of [None]. |
---|
50 | @see continue_loop *) |
---|
51 | val continue_loop_opt : const_indexing list -> index option -> unit |
---|
52 | |
---|
53 | (** [new_const_ind inds] pushes a new empty constant indexing on top of the |
---|
54 | stack [inds]. *) |
---|
55 | val new_const_ind : const_indexing list -> const_indexing list |
---|
56 | |
---|
57 | (** [forget_const_ind inds] pops and discards the top constant indexing from the |
---|
58 | stack [inds]. Raises [Invalid_argument "non-empty indexing stack"] if |
---|
59 | [inds] is empty. *) |
---|
60 | val forget_const_ind : const_indexing list -> const_indexing list |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | |
---|
65 | (** [empty_indexing] generates an empty indexing *) |
---|
66 | val empty_indexing : indexing |
---|
67 | |
---|
68 | (** [add_id_indexing ind] adds an identity mapping in front of ind **) |
---|
69 | val add_id_indexing : indexing -> indexing |
---|
70 | |
---|
71 | module IndexingSet : Set.S with type elt = indexing |
---|
72 | |
---|
73 | type t = { |
---|
74 | name : Atom.t; |
---|
75 | i : indexing |
---|
76 | } |
---|
77 | |
---|
78 | (** [apply_const_indexing ind lbl] returns [lbl] where its indexing has been |
---|
79 | evaluated in the constant indexing [ind]. |
---|
80 | @raise Invalid_argument "constant indexing not enough to be applied" if |
---|
81 | [ind] does not contain enough mappings to evaluate [lbl]'s indexing. *) |
---|
82 | val ev_indexing : const_indexing -> t -> t |
---|
83 | |
---|
84 | (** [string_of_cost_label pref t] converts an indexed label to a |
---|
85 | string suitable for a label name in source |
---|
86 | [string_of_cost_label ~pretty:true t] prints a more readable form *) |
---|
87 | val string_of_cost_label : ?pretty : bool -> t -> string |
---|
88 | |
---|
89 | (** [fresh i u] creates a fresh label using [u] as name universe, inside |
---|
90 | the indexing [i] (which represents the nested loops containing the label) *) |
---|
91 | val fresh : indexing -> Atom.Gen.universe -> t |
---|
92 | |
---|
93 | module Set : Set.S with type elt = t |
---|
94 | module Map : Map.S with type key = t |
---|
95 | |
---|
96 | (** [indexings_of a s] produces the set of indexings of an atom [a] occurring |
---|
97 | in the set of indexed labels [s]. *) |
---|
98 | val indexings_of : Atom.t -> Set.t -> IndexingSet.t |
---|
99 | |
---|
100 | (** [constant_map d x] produces a finite map which associates |
---|
101 | [x] to every element of the set [d]. *) |
---|
102 | val constant_map : Set.t -> 'a -> 'a Map.t |
---|
103 | |
---|