- = (ksTrivFound ++ ksTriv, ksSpill)
-
- -- if we haven't found a trivially colorable node then we'll have to
- -- choose a spill candidate and leave it uncolored
- | [] <- ksTrivFound
- , kSpill <- spill graph -- choose a spill candiate
- , graph' <- delNode kSpill graph -- remove it from the graph
- , nsRest' <- eltsUFM $ graphMap graph' -- graph has changed, so get new node list
-
- = colorScan' triv spill graph'
- ksTriv ksTrivFound
- (kSpill : ksSpill)
- nsRest'
-
- -- we're at the end of the candidates list but we've found some triv nodes
- -- along the way. We can delete them from the graph and go back for more.
- | graph' <- foldr delNode graph ksTrivFound
- , nsRest' <- eltsUFM $ graphMap graph'
-
- = colorScan' triv spill graph'
- (ksTrivFound ++ ksTriv) []
- ksSpill
- nsRest'
-
--- check if the current node is triv colorable
-colorScan' triv spill graph
- ksTriv ksTrivFound
- ksSpill
- (node : nsRest)
-
- -- node is trivially colorable
- -- add it to the found nodes list and carry on.
- | k <- nodeId node
- , triv (nodeClass node) (nodeConflicts node) (nodeExclusions node)
-
- = colorScan' triv spill graph
- ksTriv (k : ksTrivFound)
+ = (ksTriv, ksSpill, kksCoalesce)
+
+ -- Simplify:
+ -- Look for trivially colorable nodes.
+ -- If we can find some then remove them from the graph and go back for more.
+ --
+ | nsTrivFound@(_:_)
+ <- scanGraph (\node -> triv (nodeClass node) (nodeConflicts node) (nodeExclusions node)
+
+ -- for iterative coalescing we only want non-move related
+ -- nodes here
+ && (not iterative || isEmptyUniqSet (nodeCoalesce node)))
+ $ graph
+
+ , ksTrivFound <- map nodeId nsTrivFound
+ , graph3 <- foldr delNode graph ksTrivFound
+ = colorScan_spin iterative triv spill graph3
+ (ksTrivFound ++ ksTriv)