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   structure OperSet : ORD_SET
 
  10     where type Key.ord_key = x86.basicop
 
  11   structure LiveMap : ORD_MAP
 
  12     where type Key.ord_key = int
 
  13   structure TempMap : ORD_MAP
 
  14     where type Key.ord_key = Temp.temp
 
  16   type predicates = Liveness.predicates
 
  17   type livenesses = Liveness.livenesses
 
  18   type graph = OperSet.set TempMap.map
 
  19   val gengraph : predicates * livenesses -> graph * Temp.temp list
 
  22 structure Igraph :> IGRAPH =
 
  24   structure OperSet = Liveness.OperSet
 
  25   structure LiveMap = Liveness.LiveMap
 
  27   structure TempSet = BinarySetFn (
 
  29       type ord_key = Temp.temp
 
  30       val compare = Temp.compare
 
  34   structure TempMap = SplayMapFn (
 
  36       type ord_key = Temp.temp
 
  37       val compare = Temp.compare
 
  40   type predicates = Liveness.predicates
 
  41   type livenesses = Liveness.livenesses
 
  42   type graph = OperSet.set TempMap.map
 
  46   fun add_temp_interfere g (t, oper) =
 
  48       val set = (valOf (TempMap.find (g, t))) handle Option => OperSet.empty
 
  50       TempMap.insert (g, t, OperSet.union (set, OperSet.singleton oper))
 
  53   fun add_interfere g (o1, o2) =
 
  56         of (X.TEMP t) => add_temp_interfere g (t, o2)
 
  60         of (X.TEMP t) => add_temp_interfere g (t, o1)
 
  66       (fn (ps, ts) => List.foldr
 
  67         (fn (Liveness.DEF(X.TEMP t), ts') => TempSet.add (ts', t)
 
  68           | (Liveness.USE(X.TEMP t), ts') => TempSet.add (ts', t)
 
  76   (* val gengraph : interferences -> graph
 
  77    * generates the interference graph from a list of interfering temps
 
  78    * by creating separate interference graphs for each line, concatenating them,
 
  79    * and putting them in canonical form
 
  81   fun gengraph (preds, lives) : graph * Temp.temp list =
 
  83       (fn (ln, predlist, map) =>
 
  85           val ismove = Liveness.ismove predlist
 
  92                     val liveat = valOf (LiveMap.find (lives, ln'))
 
  96                       else OperSet.difference
 
  98                               OperSet.addList (OperSet.empty, Liveness.uses predlist))
 
 101                       (fn (oper', map) => add_interfere map (oper, oper'))
 
 106                 (Liveness.succs predlist))
 
 108             (Liveness.defs predlist)
 
 113       TempSet.listItems (alltemps preds))