summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2022-04-02 04:10:18 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-05-05 12:47:32 -0400
commitf050557eba193f92d818de7c9fc261af595173d0 (patch)
tree3cdfd1df6146bc1a4fd625dde76ccfb02e66eeb8
parent691aacf688c3c8b83fb79256cffb5d9ce40fd359 (diff)
downloadhaskell-f050557eba193f92d818de7c9fc261af595173d0.tar.gz
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)
-rw-r--r--compiler/GHC/CmmToAsm/CFG.hs2
-rw-r--r--compiler/GHC/CmmToAsm/Reg/Graph/Base.hs2
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