[Git][ghc/ghc][wip/romes/ncg-perf] 3 commits: ngc: Workaround WW vs SPEC bug in pprinting
Rodrigo Mesquita (@alt-romes)
gitlab at gitlab.haskell.org
Fri Jul 5 13:37:07 UTC 2024
Rodrigo Mesquita pushed to branch wip/romes/ncg-perf at Glasgow Haskell Compiler / GHC
Commits:
9a60f33d by Rodrigo Mesquita at 2024-07-05T14:32:11+01:00
ngc: Workaround WW vs SPEC bug in pprinting
Adds INLINABLE to `pprName` and `pprCLabelStyle` which turned up in a
profile as unspecialised at types where it should have been specialised.
The INLINABLE pragma works around a bug which causes specialisation
to be missed due to Worker Wrapper (#25060).
See also #25060 and #21851
Specialising these functions improves compile time allocations:
geo. mean -0.5%
minimum -3.2%
maximum +0.2%
-------------------------
Metric Decrease:
ManyAlternatives
ManyConstructors
T12707
T13035
T13379
T1969
T9961
-------------------------
- - - - -
993c1dc5 by Rodrigo Mesquita at 2024-07-05T14:36:55+01:00
ncg: Don't execute dwarfGen for SDoc unnecessarily
`dwarfGen @SDoc` is only needed if -ddump-asm is enabled (see emitNativeCode).
Matching on the tuple forced unnecessary execution since the unique supply
is threaded through -- use a lazy pattern instead.
- - - - -
e2d7632b by Rodrigo Mesquita at 2024-07-05T14:36:55+01:00
ncg: INLINEABLE regAlloc
regAlloc showed up in a time profile unspecialised, and making sure it
is specialised is noticeable in the profile.
Enabling it shaved off some 15ms compiling Cabal on my machine.
- - - - -
4 changed files:
- compiler/GHC/Cmm/CLabel.hs
- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/Reg/Linear.hs
- compiler/GHC/Types/Name.hs
Changes:
=====================================
compiler/GHC/Cmm/CLabel.hs
=====================================
@@ -1583,6 +1583,7 @@ pprCLabelStyle !platform !sty lbl = -- see Note [Bangs in CLabel]
CmmLabel _ _ fs CmmRetInfo -> maybe_underscore $ ftext fs <> text "_info"
CmmLabel _ _ fs CmmRet -> maybe_underscore $ ftext fs <> text "_ret"
CmmLabel _ _ fs CmmClosure -> maybe_underscore $ ftext fs <> text "_closure"
+{-# INLINABLE pprCLabelStyle #-} -- Workaround a bug which prevented pprCLabelStyle from specialising (see #25060).
{-# SPECIALIZE pprCLabelStyle :: Platform -> LabelStyle -> CLabel -> SDoc #-}
{-# SPECIALIZE pprCLabelStyle :: Platform -> LabelStyle -> CLabel -> HLine #-} -- see Note [SPECIALIZE to HDoc] in GHC.Utils.Outputable
=====================================
compiler/GHC/CmmToAsm.hs
=====================================
@@ -234,7 +234,10 @@ finishNativeGen logger config modLoc bufh us ngs
else do
compPath <- getCurrentDirectory
let (dwarf_h, us') = dwarfGen compPath config modLoc us (ngs_debug ngs)
- (dwarf_s, _) = dwarfGen compPath config modLoc us (ngs_debug ngs)
+ -- `dwarfGen @SDoc` is only needed if -ddump-asm is enabled (see emitNativeCode)
+ -- Matching on the tuple forced unnecessary execution since the unique supply
+ -- is threaded through -- use a lazy pattern instead.
+ ~(dwarf_s, _) = dwarfGen compPath config modLoc us (ngs_debug ngs)
emitNativeCode logger config bufh dwarf_h dwarf_s
return us'
=====================================
compiler/GHC/CmmToAsm/Reg/Linear.hs
=====================================
@@ -189,6 +189,9 @@ regAlloc config (CmmProc static lbl live sccs)
-- bogus. to make non-exhaustive match warning go away.
regAlloc _ (CmmProc _ _ _ _)
= panic "RegAllocLinear.regAlloc: no match"
+-- regAlloc showed up in a profile unspecialised.
+-- Enabling it shaved off some 15ms compiling Cabal:
+{-# INLINEABLE regAlloc #-}
-- -----------------------------------------------------------------------------
=====================================
compiler/GHC/Types/Name.hs
=====================================
@@ -713,6 +713,7 @@ pprName name@(Name {n_sort = sort, n_uniq = uniq, n_occ = occ})
handlePuns :: Bool -> Maybe FastString -> SDoc -> SDoc
handlePuns True (Just pun) _ = ftext pun
handlePuns _ _ r = r
+{-# INLINABLE pprName #-} -- Workaround a bug which prevented pprName from specialising (see #25060).
{-# SPECIALISE pprName :: Name -> SDoc #-}
{-# SPECIALISE pprName :: Name -> HLine #-} -- see Note [SPECIALIZE to HDoc] in GHC.Utils.Outputable
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/658780cb6f231e56a6a50ed9ff4f7489816bf475...e2d7632b3be674d005e535297e85ec394a507a89
--
This project does not include diff previews in email notifications.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/658780cb6f231e56a6a50ed9ff4f7489816bf475...e2d7632b3be674d005e535297e85ec394a507a89
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240705/018627b8/attachment-0001.html>
More information about the ghc-commits
mailing list