wiki:Commentary/Compiler/Hoopl/Examples

Version 1 (modified by jstolarek, 18 months ago) (diff)

--

Hoopl examples

This page gathers examples of Hoopl usage so that beginners can learn from them.

Dead assignment removal

This was originally part of CmmLive module:

removeDeadAssignments :: DynFlags -> CmmGraph
                      -> UniqSM (CmmGraph, BlockEnv CmmLocalLive)
removeDeadAssignments dflags g =
   dataflowPassBwd g [] $ analRewBwd liveLattice (xferLive dflags) rewrites
   where rewrites = mkBRewrite3 nothing middle nothing
         -- SDM: no need for deepBwdRw here, we only rewrite to empty
         -- Beware: deepBwdRw with one polymorphic function seems more
         -- reasonable here, but GHC panics while compiling, see bug
         -- #4045.
         middle :: CmmNode O O -> Fact O CmmLocalLive -> CmmReplGraph O O
         middle (CmmAssign (CmmLocal reg') _) live
                 | not (reg' `elemRegSet` live)
                 = return $ Just emptyGraph
         -- XXX maybe this should be somewhere else...
         middle (CmmAssign lhs (CmmReg rhs))   _ | lhs == rhs
                 = return $ Just emptyGraph
         middle (CmmStore lhs (CmmLoad rhs _)) _ | lhs == rhs
                 = return $ Just emptyGraph
         middle _ _ = return Nothing

         nothing :: CmmNode e x -> Fact x CmmLocalLive -> CmmReplGraph e x
         nothing _ _ = return Nothing

Attachments (1)

Download all attachments as: .zip