PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/carter/ghc
Haskell | 95 lines | 64 code | 21 blank | 10 comment | 0 complexity | 059caa7dd4b2f4442be1dc5c3110a55a MD5 | raw file
  1. {-# OPTIONS -fno-warn-tabs #-}
  2. -- The above warning supression flag is a temporary kludge.
  3. -- While working on this module you are encouraged to remove it and
  4. -- detab the module (please do the detabbing in a separate patch). See
  5. -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
  6. -- for details
  7. module RegAlloc.Linear.Stats (
  8. binSpillReasons,
  9. countRegRegMovesNat,
  10. pprStats
  11. )
  12. where
  13. import RegAlloc.Linear.Base
  14. import RegAlloc.Liveness
  15. import Instruction
  16. import OldCmm (GenBasicBlock(..))
  17. import UniqFM
  18. import Outputable
  19. import Data.List
  20. import State
  21. -- | Build a map of how many times each reg was alloced, clobbered, loaded etc.
  22. binSpillReasons
  23. :: [SpillReason] -> UniqFM [Int]
  24. binSpillReasons reasons
  25. = addListToUFM_C
  26. (zipWith (+))
  27. emptyUFM
  28. (map (\reason -> case reason of
  29. SpillAlloc r -> (r, [1, 0, 0, 0, 0])
  30. SpillClobber r -> (r, [0, 1, 0, 0, 0])
  31. SpillLoad r -> (r, [0, 0, 1, 0, 0])
  32. SpillJoinRR r -> (r, [0, 0, 0, 1, 0])
  33. SpillJoinRM r -> (r, [0, 0, 0, 0, 1])) reasons)
  34. -- | Count reg-reg moves remaining in this code.
  35. countRegRegMovesNat
  36. :: Instruction instr
  37. => NatCmmDecl statics instr -> Int
  38. countRegRegMovesNat cmm
  39. = execState (mapGenBlockTopM countBlock cmm) 0
  40. where
  41. countBlock b@(BasicBlock _ instrs)
  42. = do mapM_ countInstr instrs
  43. return b
  44. countInstr instr
  45. | Just _ <- takeRegRegMoveInstr instr
  46. = do modify (+ 1)
  47. return instr
  48. | otherwise
  49. = return instr
  50. -- | Pretty print some RegAllocStats
  51. pprStats
  52. :: Instruction instr
  53. => [NatCmmDecl statics instr] -> [RegAllocStats] -> SDoc
  54. pprStats code statss
  55. = let -- sum up all the instrs inserted by the spiller
  56. spills = foldl' (plusUFM_C (zipWith (+)))
  57. emptyUFM
  58. $ map ra_spillInstrs statss
  59. spillTotals = foldl' (zipWith (+))
  60. [0, 0, 0, 0, 0]
  61. $ eltsUFM spills
  62. -- count how many reg-reg-moves remain in the code
  63. moves = sum $ map countRegRegMovesNat code
  64. pprSpill (reg, spills)
  65. = parens $ (hcat $ punctuate (text ", ") (doubleQuotes (ppr reg) : map ppr spills))
  66. in ( text "-- spills-added-total"
  67. $$ text "-- (allocs, clobbers, loads, joinRR, joinRM, reg_reg_moves_remaining)"
  68. $$ (parens $ (hcat $ punctuate (text ", ") (map ppr spillTotals ++ [ppr moves])))
  69. $$ text ""
  70. $$ text "-- spills-added"
  71. $$ text "-- (reg_name, allocs, clobbers, loads, joinRR, joinRM)"
  72. $$ (vcat $ map pprSpill
  73. $ ufmToList spills)
  74. $$ text "")