From f2033eff4f1f49728f2180e902db32ae9da29b0e Mon Sep 17 00:00:00 2001 From: "Ben.Lippmeier@anu.edu.au" Date: Fri, 24 Aug 2007 15:57:32 +0000 Subject: [PATCH] Add count of reg-reg moves remaining for linear allocator stats --- compiler/nativeGen/AsmCodeGen.lhs | 2 +- compiler/nativeGen/RegAllocLinear.hs | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/compiler/nativeGen/AsmCodeGen.lhs b/compiler/nativeGen/AsmCodeGen.lhs index 38c28b4..be64428 100644 --- a/compiler/nativeGen/AsmCodeGen.lhs +++ b/compiler/nativeGen/AsmCodeGen.lhs @@ -151,7 +151,7 @@ nativeCodeGen dflags cmms us (case catMaybes mLinearStats of [] -> return () stats -> dumpSDoc dflags Opt_D_dump_asm_stats "NCG stats" - $ Linear.pprStats (concat stats)) + $ Linear.pprStats (concat native) (concat stats)) return $ makeAsmDoc (concat native) (concat imports) diff --git a/compiler/nativeGen/RegAllocLinear.hs b/compiler/nativeGen/RegAllocLinear.hs index d761bae..d72a169 100644 --- a/compiler/nativeGen/RegAllocLinear.hs +++ b/compiler/nativeGen/RegAllocLinear.hs @@ -99,6 +99,7 @@ import UniqSet import UniqFM import UniqSupply import Outputable +import State #ifndef DEBUG import Data.Maybe ( fromJust ) @@ -1054,10 +1055,29 @@ binSpillReasons reasons SpillJoinRM r -> (r, [0, 0, 0, 0, 1])) reasons) +-- | Count reg-reg moves remaining in this code. +countRegRegMovesNat :: NatCmmTop -> Int +countRegRegMovesNat cmm + = execState (mapGenBlockTopM countBlock cmm) 0 + where + countBlock b@(BasicBlock i instrs) + = do instrs' <- mapM countInstr instrs + return b + + countInstr instr + | Just _ <- isRegRegMove instr + = do modify (+ 1) + return instr + + | otherwise + = return instr + + -- | Pretty print some RegAllocStats -pprStats :: [RegAllocStats] -> SDoc -pprStats statss - = let spills = foldl' (plusUFM_C (zipWith (+))) +pprStats :: [NatCmmTop] -> [RegAllocStats] -> SDoc +pprStats code statss + = let -- sum up all the instrs inserted by the spiller + spills = foldl' (plusUFM_C (zipWith (+))) emptyUFM $ map ra_spillInstrs statss @@ -1065,12 +1085,15 @@ pprStats statss [0, 0, 0, 0, 0] $ eltsUFM spills + -- count how many reg-reg-moves remain in the code + moves = sum $ map countRegRegMovesNat code + pprSpill (reg, spills) = parens $ (hcat $ punctuate (text ", ") (doubleQuotes (ppr reg) : map ppr spills)) in ( text "-- spills-added-total" - $$ text "-- (allocs, clobbers, loads, joinRR, joinRM)" - $$ (parens $ (hcat $ punctuate (text ", ") (map ppr spillTotals))) + $$ text "-- (allocs, clobbers, loads, joinRR, joinRM, reg_reg_moves_remaining)" + $$ (parens $ (hcat $ punctuate (text ", ") (map ppr spillTotals ++ [ppr moves]))) $$ text "" $$ text "-- spills-added" $$ text "-- (reg_name, allocs, clobbers, loads, joinRR, joinRM)" -- 1.7.10.4