summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2022-04-02 04:10:18 +0200
committerSimon Jakobi <simon.jakobi@gmail.com>2022-04-22 14:09:00 +0200
commit0216512be66daca0a44dc65a86b45e029b39d163 (patch)
tree4e3f9685b73b319f358d3f6c7eb2254de0b3c7cf
parent78ec692d9c8d6d138f68e179a7ca57784daa2342 (diff)
downloadhaskell-wip/sjakobi/less-intmap-size.tar.gz
Remove two uses of IntMap.sizewip/sjakobi/less-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