- -- Expand reachable set until you hit fixpoint
- initReachable = setSingleton base_id :: BlockSet
- expandReachable old_set new_set =
- if setSize new_set > setSize old_set
- then expandReachable new_set $ setFold
- (\x s -> maybe setEmpty id (mapLookup x reachableMap) `setUnion` s)
- new_set
- (setDifference new_set old_set)
- else new_set -- fixpoint achieved
- reachable = expandReachable setEmpty initReachable
+ -- go todo done
+ reachable = go [base_id] (setEmpty :: BlockSet)
+ where go [] m = m
+ go (x:xs) m
+ | setMember x m = go xs m
+ | otherwise = go (add ++ xs) (setInsert x m)
+ where add = fromMaybe (panic "cmmEliminateDeadBlocks: unknown block")
+ (lookupUFM reachableMap x)