From b041ea7784f036dd7cfc5fae6380db4f3c392ab4 Mon Sep 17 00:00:00 2001 From: Matthew Pickering Date: Wed, 15 Sep 2021 13:06:07 +0100 Subject: Code Gen: Optimise successors calculation in loop calculation Before this change, the whole map would be traversed in order to delete a node from the graph before calculating successors. This is quite inefficient if the CFG is big, as was the case in the mmark package. A more efficient alternative is to leave the CFG untouched and then just delete the node once after the lookups have been performed. Ticket: #19471 --- compiler/GHC/CmmToAsm/CFG.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'compiler/GHC/CmmToAsm') diff --git a/compiler/GHC/CmmToAsm/CFG.hs b/compiler/GHC/CmmToAsm/CFG.hs index 5c1f23ceab..d698ae12ca 100644 --- a/compiler/GHC/CmmToAsm/CFG.hs +++ b/compiler/GHC/CmmToAsm/CFG.hs @@ -860,7 +860,7 @@ loopInfo cfg root = LoopInfo { liBackEdges = backEdges = ( edge, setInsert head $ go (setSingleton tail) (setSingleton tail) ) where -- See Note [Determining the loop body] - cfg' = delNode head revCfg + go :: LabelSet -> LabelSet -> LabelSet go found current @@ -870,10 +870,9 @@ loopInfo cfg root = LoopInfo { liBackEdges = backEdges where -- Really predecessors, since we use the reversed cfg. newSuccessors = setFilter (\n -> not $ setMember n found) successors :: LabelSet - successors = setFromList $ concatMap - (getSuccessors cfg') - -- we filter head as it's no longer part of the cfg. - (filter (/= head) $ setElems current) :: LabelSet + successors = setDelete head $ setUnions $ map + (\x -> if x == head then setEmpty else setFromList (getSuccessors revCfg x)) + (setElems current) :: LabelSet backEdges = filter isBackEdge edges loopBodies = map findBody backEdges :: [(Edge, LabelSet)] -- cgit v1.2.1