2 * interference graph generator
3 * Takes a list of interfering temps and generates the interference graph
4 * Author: Chris Lu <czl@andrew.cmu.edu>
9 type interferences = x86.oper list list
10 type graph = (Temp.temp * x86.oper list) list
11 val gengraph : interferences -> graph
14 structure Igraph :> IGRAPH =
16 type interferences = x86.oper list list
17 type graph = (Temp.temp * x86.oper list) list
20 (* val canonicalize : graph -> graph
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) = (if X.opereq (x,y) then merge ((x, List.revAppend(yl,xl))::rl) else (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) = (if X.opereq (x,y) then merge' (x::rl) else 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 * graph -> graph
45 * helper function to convert a list of interfering registers to a graph
49 (fn item1 => (item1, (List.filter (fn item2 => not (X.opereq(item1, item2))) x)))
52 (* val gengraph : interferences -> graph
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 "Non-live register type found in igraph"