summaryrefslogtreecommitdiff
path: root/compiler/cmm/CmmContFlowOpt.hs
diff options
context:
space:
mode:
authorMichal Terepeta <michal.terepeta@gmail.com>2016-12-08 16:34:10 -0500
committerBen Gamari <ben@smart-cactus.org>2016-12-08 18:44:55 -0500
commit2bb099e5ccd7255f9742cb8bc5d512cd92d035b6 (patch)
treebf4bf1fbff529c082e55f9a2b85cb55e1e9722a3 /compiler/cmm/CmmContFlowOpt.hs
parent55361b381d14d8752f00d90868fcbe82f86c6b2d (diff)
downloadhaskell-2bb099e5ccd7255f9742cb8bc5d512cd92d035b6.tar.gz
BlockId: remove BlockMap and BlockSet synonyms
This continues removal of `BlockId` module in favor of Hoopl's `Label`. Most of the changes here are mechanical, apart from the orphan `Outputable` instances for `LabelMap` and `LabelSet`. For now I've moved them to `cmm/Hoopl`, since it's already trying to manage all imports from Hoopl (to avoid any collisions). Signed-off-by: Michal Terepeta <michal.terepeta@gmail.com> Test Plan: validate Reviewers: bgamari, austin, simonmar Reviewed By: simonmar Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2800
Diffstat (limited to 'compiler/cmm/CmmContFlowOpt.hs')
-rw-r--r--compiler/cmm/CmmContFlowOpt.hs20
1 files changed, 10 insertions, 10 deletions
diff --git a/compiler/cmm/CmmContFlowOpt.hs b/compiler/cmm/CmmContFlowOpt.hs
index b825f86275..d8740df3f2 100644
--- a/compiler/cmm/CmmContFlowOpt.hs
+++ b/compiler/cmm/CmmContFlowOpt.hs
@@ -74,7 +74,7 @@ import Prelude hiding (succ, unzip, zip)
-- Note [Shortcut call returns]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--
--- We are going to maintain the "current" graph (BlockEnv CmmBlock) as
+-- We are going to maintain the "current" graph (LabelMap CmmBlock) as
-- we go, and also a mapping from BlockId to BlockId, representing
-- continuation labels that we have renamed. This latter mapping is
-- important because we might shortcut a CmmCall continuation. For
@@ -153,7 +153,7 @@ cmmCfgOptsProc split (CmmProc info lbl live g) = CmmProc info' lbl live g'
cmmCfgOptsProc _ top = top
-blockConcat :: Bool -> CmmGraph -> (CmmGraph, BlockEnv BlockId)
+blockConcat :: Bool -> CmmGraph -> (CmmGraph, LabelMap BlockId)
blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
= (replaceLabels shortcut_map $ ofBlockMap new_entry new_blocks, shortcut_map')
where
@@ -188,8 +188,8 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
initialBackEdges = incPreds entry_id (predMap blocks)
maybe_concat :: CmmBlock
- -> (BlockEnv CmmBlock, BlockEnv BlockId, BlockEnv Int)
- -> (BlockEnv CmmBlock, BlockEnv BlockId, BlockEnv Int)
+ -> (LabelMap CmmBlock, LabelMap BlockId, LabelMap Int)
+ -> (LabelMap CmmBlock, LabelMap BlockId, LabelMap Int)
maybe_concat block (blocks, shortcut_map, backEdges)
-- If:
-- (1) current block ends with unconditional branch to b' and
@@ -313,7 +313,7 @@ blockConcat splitting_procs g@CmmGraph { g_entry = entry_id }
-- that invariant, but calling replaceLabels may introduce unreachable blocks.
-- We rely on subsequent passes in the Cmm pipeline to remove unreachable
-- blocks.
-incPreds, decPreds :: BlockId -> BlockEnv Int -> BlockEnv Int
+incPreds, decPreds :: BlockId -> LabelMap Int -> LabelMap Int
incPreds bid edges = mapInsertWith (+) bid 1 edges
decPreds bid edges = case mapLookup bid edges of
Just preds | preds > 1 -> mapInsert bid (preds - 1) edges
@@ -352,8 +352,8 @@ callContinuation_maybe _ = Nothing
-- Map over the CmmGraph, replacing each label with its mapping in the
--- supplied BlockEnv.
-replaceLabels :: BlockEnv BlockId -> CmmGraph -> CmmGraph
+-- supplied LabelMap.
+replaceLabels :: LabelMap BlockId -> CmmGraph -> CmmGraph
replaceLabels env g
| mapNull env = g
| otherwise = replace_eid $ mapGraphNodes1 txnode g
@@ -383,7 +383,7 @@ mkCmmCondBranch p t f l =
if t == f then CmmBranch t else CmmCondBranch p t f l
-- Build a map from a block to its set of predecessors.
-predMap :: [CmmBlock] -> BlockEnv Int
+predMap :: [CmmBlock] -> LabelMap Int
predMap blocks = foldr add_preds mapEmpty blocks
where
add_preds block env = foldr add env (successors block)
@@ -401,10 +401,10 @@ removeUnreachableBlocksProc proc@(CmmProc info lbl live g)
info' = info { info_tbls = keep_used (info_tbls info) }
-- Remove any info_tbls for unreachable
- keep_used :: BlockEnv CmmInfoTable -> BlockEnv CmmInfoTable
+ keep_used :: LabelMap CmmInfoTable -> LabelMap CmmInfoTable
keep_used bs = mapFoldWithKey keep mapEmpty bs
- keep :: Label -> CmmInfoTable -> BlockEnv CmmInfoTable -> BlockEnv CmmInfoTable
+ keep :: Label -> CmmInfoTable -> LabelMap CmmInfoTable -> LabelMap CmmInfoTable
keep l i env | l `setMember` used_lbls = mapInsert l i env
| otherwise = env