From f050557eba193f92d818de7c9fc261af595173d0 Mon Sep 17 00:00:00 2001 From: Simon Jakobi Date: Sat, 2 Apr 2022 04:10:18 +0200 Subject: Remove two uses of IntMap.size IntMap.size is O(n). The new code should be slightly more efficient. The transformation of GHC.CmmToAsm.CFG.calcFreqs.nodeCount can be described formally as the transformation: (\sum_{0}^{n-1} \sum_{0}^{k-1} i_nk) + n ==> (\sum_{0}^{n-1} 1 + \sum_{0}^{k-1} i_nk) --- compiler/GHC/CmmToAsm/CFG.hs | 2 +- compiler/GHC/CmmToAsm/Reg/Graph/Base.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/GHC/CmmToAsm/CFG.hs b/compiler/GHC/CmmToAsm/CFG.hs index 8f8b71b1f7..99df21c46b 100644 --- a/compiler/GHC/CmmToAsm/CFG.hs +++ b/compiler/GHC/CmmToAsm/CFG.hs @@ -1350,7 +1350,7 @@ calcFreqs graph backEdges loops revPostOrder = runST $ do vcat (map (\(k,m) -> ppr (k,m :: IM.IntMap Double)) $ IM.toList g) ) - nodeCount = IM.foldl' (\count toMap -> IM.foldlWithKey' countTargets count toMap) (IM.size graph) graph + nodeCount = IM.foldl' (\count toMap -> IM.foldlWithKey' countTargets (count + 1) toMap) 0 graph where countTargets = (\count k _ -> countNode k + count ) countNode n = if IM.member n graph then 0 else 1 diff --git a/compiler/GHC/CmmToAsm/Reg/Graph/Base.hs b/compiler/GHC/CmmToAsm/Reg/Graph/Base.hs index 32b49a61e8..7756030ed8 100644 --- a/compiler/GHC/CmmToAsm/Reg/Graph/Base.hs +++ b/compiler/GHC/CmmToAsm/Reg/Graph/Base.hs @@ -104,7 +104,7 @@ worst regsOfClass regAlias neighbors classN classC regsC = regsOfClass classC -- all the possible subsets of c which have size < m - regsS = filter (\s -> sizeUniqSet s >= 1 + regsS = filter (\s -> not (isEmptyUniqSet s) && sizeUniqSet s <= neighbors) $ powersetLS regsC -- cgit v1.2.1