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>
9 type tiberium = x86.oper list list
10 type rockets = (Temp.temp * x86.oper list) list
11 val gengraph : tiberium -> rockets
14 structure Igraph :> IGRAPH =
16 type tiberium = x86.oper list list
17 type rockets = (Temp.temp * x86.oper list) list
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
24 fun canonicalize orig =
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]
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]
41 List.map (fn (a, x) => (a, uniq x)) ml
44 (* val proc_one : Temp.temp list * rockets -> rockets
45 * helper function to convert a list of interfering registers to a graph
49 (fn item1 => (item1, (List.filter (fn item2 => X.cmpoper(item1, item2) <> EQUAL) x)))
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
59 val igraph' = canonicalize (List.concat (List.map proc_one x))
62 (fn ((a,l),b) => case a
64 | X.TEMP(t) => (t,l)::b
65 | _ => raise ErrorMsg.InternalError "I'm a doooodyyyheaadddd"