diff options
author | Michal Terepeta <michal.terepeta@gmail.com> | 2018-03-05 15:16:02 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-03-06 13:03:06 -0500 |
commit | 64c0af7517148316b259300b851b966cfbcf3eaf (patch) | |
tree | 3c72f8eb06f7f7c5d86806d81dbe9177a995ba49 /compiler/cmm/CmmBuildInfoTables.hs | |
parent | 9bccfcdbbf97250ede05a9351de48f8fa1788217 (diff) | |
download | haskell-64c0af7517148316b259300b851b966cfbcf3eaf.tar.gz |
cmm/: Avoid using lazy left folds
This basically replaces all uses of `foldl` with `foldl'`. I've looked
at all the call sites and there doesn't seem to be any reason to prefer
the lazy version.
Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com>
Test Plan: ./validate
Reviewers: bgamari, simonmar
Reviewed By: bgamari
Subscribers: rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4463
Diffstat (limited to 'compiler/cmm/CmmBuildInfoTables.hs')
-rw-r--r-- | compiler/cmm/CmmBuildInfoTables.hs | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/compiler/cmm/CmmBuildInfoTables.hs b/compiler/cmm/CmmBuildInfoTables.hs index dc5cfd6ee0..ae192e504c 100644 --- a/compiler/cmm/CmmBuildInfoTables.hs +++ b/compiler/cmm/CmmBuildInfoTables.hs @@ -119,11 +119,13 @@ cafAnal cmmGraph = analyzeCmmBwd cafLattice cafTransfers cmmGraph mapEmpty -- Description of the SRT for a given module. -- Note that this SRT may grow as we greedily add new CAFs to it. -data TopSRT = TopSRT { lbl :: CLabel - , next_elt :: Int -- the next entry in the table - , rev_elts :: [CLabel] - , elt_map :: Map CLabel Int } - -- map: CLabel -> its last entry in the table +data TopSRT = TopSRT + { lbl :: CLabel + , next_elt :: {-# UNPACK #-} !Int -- the next entry in the table + , rev_elts :: [CLabel] + , elt_map :: !(Map CLabel Int) -- CLabel -> its last entry in the table + } + instance Outputable TopSRT where ppr (TopSRT lbl next elts eltmap) = text "TopSRT:" <+> ppr lbl @@ -176,7 +178,7 @@ buildSRT dflags topSRT cafs = do localSRTs <- procpointSRT dflags (lbl topSRT) (elt_map topSRT) cafs return (topSRT, localSRTs) in if cafs `lengthExceeds` maxBmpSize dflags then - mkSRT (foldl add_if_missing topSRT cafs) + mkSRT (foldl' add_if_missing topSRT cafs) else -- make sure all the cafs are near the bottom of the srt mkSRT (add_if_too_far topSRT cafs) add_if_missing srt caf = @@ -269,14 +271,14 @@ localCAFInfo cafEnv proc@(CmmProc _ top_l _ (CmmGraph {g_entry=entry})) = -- To do this replacement efficiently, we gather strongly connected -- components, then we sort the components in topological order. mkTopCAFInfo :: [(CAFSet, Maybe CLabel)] -> Map CLabel CAFSet -mkTopCAFInfo localCAFs = foldl addToTop Map.empty g +mkTopCAFInfo localCAFs = foldl' addToTop Map.empty g where - addToTop env (AcyclicSCC (l, cafset)) = + addToTop !env (AcyclicSCC (l, cafset)) = Map.insert l (flatten env cafset) env - addToTop env (CyclicSCC nodes) = + addToTop !env (CyclicSCC nodes) = let (lbls, cafsets) = unzip nodes - cafset = foldr Set.delete (foldl Set.union Set.empty cafsets) lbls - in foldl (\env l -> Map.insert l (flatten env cafset) env) env lbls + cafset = Set.unions cafsets `Set.difference` Set.fromList lbls + in foldl' (\env l -> Map.insert l (flatten env cafset) env) env lbls g = stronglyConnCompFromEdgedVerticesOrd [ DigraphNode (l,cafs) l (Set.elems cafs) |