PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/ghc-7.0.4/compiler/nativeGen/RegAlloc/Linear/Stats.hs

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