X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FnativeGen%2FGraphOps.hs;h=414abe4efce0489ebd138c563615252aaac166e5;hb=b8a64b8ec9cd3d8f6e3f23e44312c4903eccac45;hp=c494e633f1f2c8c3c26190136b5922e5c8388e44;hpb=12d0b38821771fd9820d655ed73b29c688cb7b59;p=ghc-hetmet.git diff --git a/compiler/nativeGen/GraphOps.hs b/compiler/nativeGen/GraphOps.hs index c494e63..414abe4 100644 --- a/compiler/nativeGen/GraphOps.hs +++ b/compiler/nativeGen/GraphOps.hs @@ -78,28 +78,28 @@ addNode k node graph { graphMap = addToUFM map_coalesce k node} - -- | Delete a node and all its edges from the graph. --- Throws an error if it's not there. -delNode :: Uniquable k - => k -> Graph k cls color -> Graph k cls color +delNode :: (Uniquable k, Outputable k) + => k -> Graph k cls color -> Maybe (Graph k cls color) delNode k graph - = let Just node = lookupNode graph k - - -- delete conflict edges from other nodes to this one. - graph1 = foldl' (\g k1 -> let Just g' = delConflict k1 k g in g') graph + | Just node <- lookupNode graph k + = let -- delete conflict edges from other nodes to this one. + graph1 = foldl' (\g k1 -> let Just g' = delConflict k1 k g in g') graph $ uniqSetToList (nodeConflicts node) - -- delete coalesce edge from other nodes to this one. - graph2 = foldl' (\g k1 -> let Just g' = delCoalesce k1 k g in g') graph1 + -- delete coalesce edge from other nodes to this one. + graph2 = foldl' (\g k1 -> let Just g' = delCoalesce k1 k g in g') graph1 $ uniqSetToList (nodeCoalesce node) - -- delete the node - graph3 = graphMapModify (\fm -> delFromUFM fm k) graph2 + -- delete the node + graph3 = graphMapModify (\fm -> delFromUFM fm k) graph2 - in graph3 + in Just graph3 + | otherwise + = Nothing + -- | Modify a node in the graph. -- returns Nothing if the node isn't present. @@ -350,6 +350,9 @@ coalesceNodes_merge aggressive triv graph kMin kMax nMin nMax | not (isNothing (nodeColor nMin) && isNothing (nodeColor nMax)) = error "GraphOps.coalesceNodes: can't coalesce colored nodes." + | nodeId nMin == nodeId nMax + = error "GraphOps.coalesceNodes: can't coalesce the same node." + --- | otherwise = let @@ -387,12 +390,11 @@ coalesceNodes_check aggressive triv graph kMin kMax node | otherwise = let -- delete the old nodes from the graph and add the new one - graph' = addNode kMin node - $ delNode kMin - $ delNode kMax - $ graph + Just graph1 = delNode kMax graph + Just graph2 = delNode kMin graph1 + graph3 = addNode kMin node graph2 - in (graph', Just (kMax, kMin)) + in (graph3, Just (kMax, kMin)) -- | Freeze a node