PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/compiler/nativeGen/RegAlloc/Linear/Stats.hs

https://github.com/tibbe/ghc
Haskell | 86 lines | 63 code | 19 blank | 4 comment | 0 complexity | 5d9dedc047f5e60a5e6ca2c083aaa491 MD5 | raw file
  1. module RegAlloc.Linear.Stats (
  2. binSpillReasons,
  3. countRegRegMovesNat,
  4. pprStats
  5. )
  6. where
  7. import RegAlloc.Linear.Base
  8. import RegAlloc.Liveness
  9. import Instruction
  10. import UniqFM
  11. import Outputable
  12. import Data.List
  13. import State
  14. -- | Build a map of how many times each reg was alloced, clobbered, loaded etc.
  15. binSpillReasons
  16. :: [SpillReason] -> UniqFM [Int]
  17. binSpillReasons reasons
  18. = addListToUFM_C
  19. (zipWith (+))
  20. emptyUFM
  21. (map (\reason -> case reason of
  22. SpillAlloc r -> (r, [1, 0, 0, 0, 0])
  23. SpillClobber r -> (r, [0, 1, 0, 0, 0])
  24. SpillLoad r -> (r, [0, 0, 1, 0, 0])
  25. SpillJoinRR r -> (r, [0, 0, 0, 1, 0])
  26. SpillJoinRM r -> (r, [0, 0, 0, 0, 1])) reasons)
  27. -- | Count reg-reg moves remaining in this code.
  28. countRegRegMovesNat
  29. :: Instruction instr
  30. => NatCmmDecl statics instr -> Int
  31. countRegRegMovesNat cmm
  32. = execState (mapGenBlockTopM countBlock cmm) 0
  33. where
  34. countBlock b@(BasicBlock _ instrs)
  35. = do mapM_ countInstr instrs
  36. return b
  37. countInstr instr
  38. | Just _ <- takeRegRegMoveInstr instr
  39. = do modify (+ 1)
  40. return instr
  41. | otherwise
  42. = return instr
  43. -- | Pretty print some RegAllocStats
  44. pprStats
  45. :: Instruction instr
  46. => [NatCmmDecl statics instr] -> [RegAllocStats] -> SDoc
  47. pprStats code statss
  48. = let -- sum up all the instrs inserted by the spiller
  49. spills = foldl' (plusUFM_C (zipWith (+)))
  50. emptyUFM
  51. $ map ra_spillInstrs statss
  52. spillTotals = foldl' (zipWith (+))
  53. [0, 0, 0, 0, 0]
  54. $ eltsUFM spills
  55. -- count how many reg-reg-moves remain in the code
  56. moves = sum $ map countRegRegMovesNat code
  57. pprSpill (reg, spills)
  58. = parens $ (hcat $ punctuate (text ", ") (doubleQuotes (ppr reg) : map ppr spills))
  59. in ( text "-- spills-added-total"
  60. $$ text "-- (allocs, clobbers, loads, joinRR, joinRM, reg_reg_moves_remaining)"
  61. $$ (parens $ (hcat $ punctuate (text ", ") (map ppr spillTotals ++ [ppr moves])))
  62. $$ text ""
  63. $$ text "-- spills-added"
  64. $$ text "-- (reg_name, allocs, clobbers, loads, joinRR, joinRM)"
  65. $$ (vcat $ map pprSpill
  66. $ ufmToList spills)
  67. $$ text "")