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: abstract or not? *) |
---|
12 | type sexpr = Sexpr of int*int |
---|
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 | (** [comp_index i s lbl] gives back the label [lbl] where index [i] is remapped |
---|
79 | to the simple expression [s]. *) |
---|
80 | val comp_index : index -> sexpr -> t -> t |
---|
81 | |
---|
82 | |
---|
83 | (** [ev_indexing ind lbl] returns [lbl] where its indexing has been |
---|
84 | evaluated in the constant indexing [ind]. |
---|
85 | @raise Invalid_argument "constant indexing not enough to be applied" if |
---|
86 | [ind] does not contain enough mappings to evaluate [lbl]'s indexing. *) |
---|
87 | val ev_indexing : const_indexing -> t -> t |
---|
88 | |
---|
89 | (** [string_of_cost_label pref t] converts an indexed label to a |
---|
90 | string suitable for a label name in source |
---|
91 | [string_of_cost_label ~pretty:true t] prints a more readable form *) |
---|
92 | val string_of_cost_label : ?pretty : bool -> t -> string |
---|
93 | |
---|
94 | (** [fresh i u] creates a fresh label using [u] as name universe, inside |
---|
95 | the indexing [i] (which represents the nested loops containing the label) *) |
---|
96 | val fresh : indexing -> Atom.Gen.universe -> t |
---|
97 | |
---|
98 | module Set : Set.S with type elt = t |
---|
99 | module Map : Map.S with type key = t |
---|
100 | |
---|
101 | (** [indexings_of a s] produces the set of indexings of an atom [a] occurring |
---|
102 | in the set of indexed labels [s]. *) |
---|
103 | val indexings_of : Atom.t -> Set.t -> IndexingSet.t |
---|
104 | |
---|
105 | (** [constant_map d x] produces a finite map which associates |
---|
106 | [x] to every element of the set [d]. *) |
---|
107 | val constant_map : Set.t -> 'a -> 'a Map.t |
---|
108 | |
---|