- in do us <- getUs
- let g = runDFM us dualLiveLattice $ b_rewrite dualLivenessWithInsertion g''
- -- let igraph = buildIGraph
- return $ do g' <- g >>= return . map_nodes id spillAndReloadComments id
- return $ CmmProc h l args g'
+ -- Change types of middle nodes to allow spill/reload
+ in do { u1 <- getUs; u2 <- getUs; u3 <- getUs
+ ; entry <- getUniqueUs >>= return . BlockId
+ ; return $
+ do { g <- return g''
+ ; g <- dual_rewrite u1 dualLivenessWithInsertion g
+ -- Insert spills at defns; reloads at return points
+ ; g <- insertLateReloads' u2 (extend g)
+ -- Duplicate reloads just before uses
+ ; g <- dual_rewrite u3 removeDeadAssignmentsAndReloads (trim entry g)
+ -- Remove redundant reloads (and any other redundant asst)
+ ; return $ CmmProc h l args $ map_nodes id spillAndReloadComments id g
+ }
+ }
+ where dual_rewrite u pass g = runDFM u dualLiveLattice $ b_rewrite pass g
+ extend (LGraph eid blocks) = Graph (ZLast $ mkBranchNode eid) blocks
+ trim _ (Graph (ZLast (LastOther (LastBranch id))) blocks) = LGraph id blocks
+ trim e (Graph tail blocks) = LGraph e (insertBlock (Block e tail) blocks)