/compiler/GHC/CmmToAsm/X86/RegInfo.hs

https://github.com/bgamari/ghc · Haskell · 72 lines · 40 code · 17 blank · 15 comment · 2 complexity · e22ad29068189bed18e0c44b0eabef8e MD5 · raw file

  1. module GHC.CmmToAsm.X86.RegInfo (
  2. mkVirtualReg,
  3. regDotColor
  4. )
  5. where
  6. import GHC.Prelude
  7. import GHC.CmmToAsm.Format
  8. import GHC.Platform.Reg
  9. import GHC.Utils.Outputable
  10. import GHC.Utils.Panic
  11. import GHC.Platform
  12. import GHC.Types.Unique
  13. import GHC.Types.Unique.FM
  14. import GHC.CmmToAsm.X86.Regs
  15. mkVirtualReg :: Unique -> Format -> VirtualReg
  16. mkVirtualReg u format
  17. = case format of
  18. FF32 -> VirtualRegD u
  19. -- for scalar F32, we use the same xmm as F64!
  20. -- this is a hack that needs some improvement.
  21. -- For now we map both to being allocated as "Double" Registers
  22. -- on X86/X86_64
  23. FF64 -> VirtualRegD u
  24. _other -> VirtualRegI u
  25. regDotColor :: Platform -> RealReg -> SDoc
  26. regDotColor platform reg
  27. = case (lookupUFM (regColors platform) reg) of
  28. Just str -> text str
  29. _ -> panic "Register not assigned a color"
  30. regColors :: Platform -> UniqFM RealReg [Char]
  31. regColors platform = listToUFM (normalRegColors platform)
  32. normalRegColors :: Platform -> [(RealReg,String)]
  33. normalRegColors platform =
  34. zip (map realRegSingle [0..lastint platform]) colors
  35. ++ zip (map realRegSingle [firstxmm..lastxmm platform]) greys
  36. where
  37. -- 16 colors - enough for amd64 gp regs
  38. colors = ["#800000","#ff0000","#808000","#ffff00","#008000"
  39. ,"#00ff00","#008080","#00ffff","#000080","#0000ff"
  40. ,"#800080","#ff00ff","#87005f","#875f00","#87af00"
  41. ,"#ff00af"]
  42. -- 16 shades of grey, enough for the currently supported
  43. -- SSE extensions.
  44. greys = ["#0e0e0e","#1c1c1c","#2a2a2a","#383838","#464646"
  45. ,"#545454","#626262","#707070","#7e7e7e","#8c8c8c"
  46. ,"#9a9a9a","#a8a8a8","#b6b6b6","#c4c4c4","#d2d2d2"
  47. ,"#e0e0e0"]
  48. -- 32 shades of grey - use for avx 512 if we ever need it
  49. -- greys = ["#070707","#0e0e0e","#151515","#1c1c1c"
  50. -- ,"#232323","#2a2a2a","#313131","#383838","#3f3f3f"
  51. -- ,"#464646","#4d4d4d","#545454","#5b5b5b","#626262"
  52. -- ,"#696969","#707070","#777777","#7e7e7e","#858585"
  53. -- ,"#8c8c8c","#939393","#9a9a9a","#a1a1a1","#a8a8a8"
  54. -- ,"#afafaf","#b6b6b6","#bdbdbd","#c4c4c4","#cbcbcb"
  55. -- ,"#d2d2d2","#d9d9d9","#e0e0e0"]