+-- | Count spill/reload/reg-reg moves.
+-- Lets us see how well the register allocator has done.
+--
+countSRMs :: LiveCmmTop -> (Int, Int, Int)
+countSRMs cmm
+ = execState (mapBlockTopM countSRM_block cmm) (0, 0, 0)
+
+countSRM_block (BasicBlock i instrs)
+ = do instrs' <- mapM countSRM_instr instrs
+ return $ BasicBlock i instrs'
+
+countSRM_instr li@(Instr instr _)
+ | SPILL _ _ <- instr
+ = do modify $ \(s, r, m) -> (s + 1, r, m)
+ return li
+
+ | RELOAD _ _ <- instr
+ = do modify $ \(s, r, m) -> (s, r + 1, m)
+ return li
+
+ | Just _ <- isRegRegMove instr
+ = do modify $ \(s, r, m) -> (s, r, m + 1)
+ return li
+
+ | otherwise
+ = return li
+
+-- sigh..
+addSRM (s1, r1, m1) (s2, r2, m2)
+ = (s1+s2, r1+r2, m1+m2)
+