]> Joshua Wise's Git repositories - snipe.git/blame_incremental - codegen/igraph.sml
Initial import of l1c
[snipe.git] / codegen / igraph.sml
... / ...
CommitLineData
1(* interference graph generator
2 * Gathers tiberium, fires rockets
3 * Takes a list of interfering temps and generates the interference graph
4 * Author: Chris Lu <czl@andrew>
5 *)
6
7signature IGRAPH =
8sig
9 type tiberium = x86.oper list list
10 type rockets = (Temp.temp * x86.oper list) list
11 val gengraph : tiberium -> rockets
12end
13
14structure Igraph :> IGRAPH =
15struct
16 type tiberium = x86.oper list list
17 type rockets = (Temp.temp * x86.oper list) list
18 structure X = x86
19
20 (* val canonicalize : rockets -> rockets
21 * canonicalize a => puts a in the canonical form by eliminating repeat nodes and edges
22 * does so by sorting them first, then eliminating consecutive temps
23 *)
24 fun canonicalize orig =
25 let
26 val sorig = ListMergeSort.sort (fn ((a,_),(b,_)) => X.cmpoper (a,b) = LESS) orig
27 fun merge ((x, xl)::(y, yl)::rl) = (case X.cmpoper (x,y) of EQUAL => merge ((x, xl @ yl)::rl) | _ => (x, xl) :: merge ((y, yl)::rl))
28 | merge (a::nil) = [a]
29 | merge nil = nil
30 val ml = merge sorig
31 fun uniq l =
32 let
33 val sl = ListMergeSort.sort (fn (a,b) => X.cmpoper (a,b) = LESS) l
34 fun merge' (x::y::rl) = (case X.cmpoper (x,y) of EQUAL => merge' (x::rl) | _ => x :: merge' (y::rl))
35 | merge' (x::nil) = [x]
36 | merge' nil = nil
37 in
38 merge' sl
39 end
40 in
41 List.map (fn (a, x) => (a, uniq x)) ml
42 end
43
44 (* val proc_one : Temp.temp list * rockets -> rockets
45 * helper function to convert a list of interfering registers to a graph
46 *)
47 fun proc_one x =
48 List.map
49 (fn item1 => (item1, (List.filter (fn item2 => X.cmpoper(item1, item2) <> EQUAL) x)))
50 x
51
52 (* val gengraph : tiberium -> rockets
53 * generates the interference graph from a list of interfering temps
54 * by creating separate interference graphs for each line, concatenating them,
55 * and putting them in canonical form
56 *)
57 fun gengraph x =
58 let
59 val igraph' = canonicalize (List.concat (List.map proc_one x))
60 in
61 foldr
62 (fn ((a,l),b) => case a
63 of X.REG(_) => b
64 | X.TEMP(t) => (t,l)::b
65 | _ => raise ErrorMsg.InternalError "I'm a doooodyyyheaadddd"
66 )
67 nil
68 igraph'
69 end
70
71end
This page took 0.026149 seconds and 4 git commands to generate.