NCG: Fix dumping of graphs in regalloc stats for graph allocator
[ghc-hetmet.git] / compiler / nativeGen / RegAlloc / Graph / Coalesce.hs
index 18e4b0e..e0fad17 100644 (file)
@@ -8,17 +8,17 @@ module RegAlloc.Graph.Coalesce (
 
 where
 
-import Cmm
-import Regs
 import RegAlloc.Liveness
-import RegAllocInfo
+import Instruction
+import Reg
 
+import Cmm
 import Bag
+import Digraph
 import UniqFM
 import UniqSet
 import UniqSupply
 
-import Control.Monad
 import Data.List
 
 -- | Do register coalescing on this top level thing
@@ -26,7 +26,11 @@ import Data.List
 --     then the mov only serves to join live ranges. The two regs can be renamed to be 
 --     the same and the move instruction safely erased.
 
-regCoalesce :: [LiveCmmTop] -> UniqSM [LiveCmmTop]
+regCoalesce 
+       :: Instruction instr
+       => [LiveCmmTop instr] 
+       -> UniqSM [LiveCmmTop instr]
+
 regCoalesce code
  = do  
        let joins       = foldl' unionBags emptyBag
@@ -57,18 +61,21 @@ sinkReg fm r
 --     During a mov, if the source reg dies and the destiation reg is born
 --     then we can rename the two regs to the same thing and eliminate the move.
 --
-slurpJoinMovs :: LiveCmmTop -> Bag (Reg, Reg)
+slurpJoinMovs 
+       :: Instruction instr
+       => LiveCmmTop instr 
+       -> Bag (Reg, Reg)
+
 slurpJoinMovs live
        = slurpCmm emptyBag live
  where 
-       slurpCmm   rs  CmmData{}                         = rs
-       slurpCmm   rs (CmmProc _ _ _ (ListGraph blocks)) = foldl' slurpComp  rs blocks
-       slurpComp  rs (BasicBlock _ blocks)              = foldl' slurpBlock rs blocks
-        slurpBlock rs (BasicBlock _ instrs)              = foldl' slurpLI    rs instrs
+       slurpCmm   rs  CmmData{}                = rs
+       slurpCmm   rs (CmmProc _ _ _ sccs)      = foldl' slurpBlock rs (flattenSCCs sccs)
+        slurpBlock rs (BasicBlock _ instrs)    = foldl' slurpLI    rs instrs
                 
-        slurpLI    rs (Instr _ Nothing)                 = rs
-       slurpLI    rs (Instr instr (Just live))
-               | Just (r1, r2) <- isRegRegMove instr
+        slurpLI    rs (LiveInstr _     Nothing) = rs
+       slurpLI    rs (LiveInstr instr (Just live))
+               | Just (r1, r2) <- takeRegRegMoveInstr instr
                , elementOfUniqSet r1 $ liveDieRead live
                , elementOfUniqSet r2 $ liveBorn live
 
@@ -79,5 +86,5 @@ slurpJoinMovs live
                
                | otherwise
                = rs
-       
+