module DDC.Core.Flow.Transform.Forward
( forwardProcesses )
where
import DDC.Core.Flow.Profile
import DDC.Core.Flow.Prim
import DDC.Core.Flow.Prim.KiConFlow
import DDC.Core.Flow.Prim.TyConFlow
import DDC.Core.Exp.Annot
import DDC.Core.Module
import qualified DDC.Core.Simplifier as C
import qualified DDC.Core.Transform.Forward as Forward
import qualified DDC.Core.Transform.TransformModX as T
forwardProcesses :: Module () Name -> Module () Name
forwardProcesses mm
= T.transformModLet forwardBind mm
forwardBind :: Bind Name -> Exp () Name -> Exp () Name
forwardBind b xx
| isProcessType $ snd $ takeTFunAllArgResult $ typeOfBind b
= C.result $ Forward.forwardX profile conf_process xx
| otherwise
= C.result $ Forward.forwardX profile conf_nonproc xx
where
conf_process = Forward.Config isFloatable_process False
conf_nonproc = Forward.Config isFloatable_nonproc False
isFloatable_process lts
= case lts of
LLet (BName _ _) x
| Just (n,_) <- takeXPrimApps x
-> case n of
NameOpConcrete _ -> Forward.FloatDeny
NameOpControl _ -> Forward.FloatDeny
NameOpSeries _ -> Forward.FloatDeny
NameOpStore _ -> Forward.FloatDeny
NameOpVector _ -> Forward.FloatDeny
_ -> Forward.FloatForceUsedOnce
_ -> Forward.FloatForceUsedOnce
isFloatable_nonproc lts
= case lts of
LLet _ x
| Just (lams,_) <- takeXLamFlags x
, any (\(_,bo) -> typeOfBind bo == kRate) lams
-> Forward.FloatForce
_ -> Forward.FloatAllow