summaryrefslogtreecommitdiff
path: root/Optimiser.hs
diff options
context:
space:
mode:
authortomsmeding <tom.smeding@gmail.com>2019-12-13 13:39:35 +0100
committertomsmeding <tom.smeding@gmail.com>2019-12-13 13:39:35 +0100
commit3595d3c75503158e4eedaedbac8e81cbbe5ae54b (patch)
treed5de3449acabdf0af4d7e361d1063d3934bb0064 /Optimiser.hs
parent80fee1089b659a7c7ee3a96d4cf999d369c0eb48 (diff)
Follow caller-save convention using stack, not full state restore
Diffstat (limited to 'Optimiser.hs')
-rw-r--r--Optimiser.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/Optimiser.hs b/Optimiser.hs
index 42ebdb1..c59c40e 100644
--- a/Optimiser.hs
+++ b/Optimiser.hs
@@ -20,7 +20,7 @@ optimise (IRProgram bbs gfds datas) =
, deadBBElim gfds, deadStoreElim, mergeRets
, map propAssigns
, deadBBElim gfds, deadStoreElim, mergeRets
- , tailCallIntro
+ , tailCallIntro, deadBBElim gfds
]
progoptf = foldl (.) id . reverse $
[ dedupDatas ]
@@ -81,6 +81,8 @@ propAssigns (BB bid inss term) =
propagateI mp (d, ICallC r rs) = (Map.empty, (d, ICallC (propR mp r) (map (propR mp) rs)))
propagateI mp (d, IAllocClo n rs) = (mp, (d, IAllocClo n (map (propR mp) rs)))
propagateI mp (d, IDiscard r) = (mp, (d, IDiscard (propR mp r)))
+ propagateI mp (d, IPush rs) = (mp, (d, IPush (map (propR mp) rs)))
+ propagateI mp (d, IPop rs) = (foldr Map.delete mp (onlyTemporaries rs), (d, IPop rs))
propagateT mp (IBr r a b) = IBr (propR mp r) a b
propagateT _ t@(IJmp _) = t
@@ -112,9 +114,12 @@ globalPropAssigns bbs =
(d, ICallC r rs) -> (d, ICallC (replace r) (map replace rs))
(d, IAllocClo n rs) -> (d, IAllocClo n (map replace rs))
(d, IDiscard r) -> (d, IDiscard (replace r))
+ (d, IPush rs) -> (d, IPush (map replace rs))
ins@(_, IParam _) -> ins
ins@(_, IClosure _) -> ins
ins@(_, IData _) -> ins
+ -- Cannot replace in an IPop, because its arguments are output parameters
+ ins@(_, IPop _) -> ins
in BB bid inss' term
deadBBElim :: Map.Map Name GlobFuncDef -> [BB] -> [BB]
@@ -147,6 +152,8 @@ deadStoreElim bbs = [BB bid (filter (not . shouldRemove) inss) term | BB bid ins
pureIC (IAllocClo _ _) = True
pureIC (ICallC _ _) = False
pureIC (IDiscard _) = False
+ pureIC (IPush _) = False
+ pureIC (IPop _) = False
tailCallIntro :: [BB] -> [BB]
tailCallIntro bbs = map introduce bbs