$ graph
, ksTrivFound <- map nodeId nsTrivFound
- , graph3 <- foldr delNode graph ksTrivFound
+ , graph3 <- foldr (\k g -> let Just g' = delNode k g
+ in g')
+ graph ksTrivFound
+
= colorScan_spin iterative triv spill graph3
(ksTrivFound ++ ksTriv)
ksSpill
colorScan_spill iterative triv spill graph
ksTriv ksSpill kksCoalesce
- = let kSpill = spill graph
- graph' = delNode kSpill graph
+ = let kSpill = spill graph
+ Just graph' = delNode kSpill graph
in colorScan_spin iterative triv spill graph'
ksTriv (kSpill : ksSpill) kksCoalesce
{ 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.
| 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
| 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
-- add an edge betwen the this reg and the last one stored into the slot
| RELOAD slot reg <- instr
= case lookupUFM slotMap slot of
- Just reg2 -> (slotMap, Just (reg, reg2))
+ Just reg2
+ | reg /= reg2 -> (slotMap, Just (reg, reg2))
+ | otherwise -> (slotMap, Nothing)
+
Nothing -> (slotMap, Nothing)
| otherwise