aboutsummaryrefslogtreecommitdiff
path: root/Optimiser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Optimiser.hs')
-rw-r--r--Optimiser.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/Optimiser.hs b/Optimiser.hs
index 408bd24..f94441c 100644
--- a/Optimiser.hs
+++ b/Optimiser.hs
@@ -28,6 +28,12 @@ optimise prog =
fst $ fromJust $ find (uncurry (==)) $ zip passreslist (tail passreslist)
else return $ reslist !! 5
where
+ -- optimisations = map funcopt
+ -- [chainJumps, removeUnusedBlocks]
+ -- optimisations = map funcopt
+ -- [chainJumps, mergeTerminators, looseJumps,
+ -- removeUnusedBlocks,
+ -- constantPropagate, movPush]
optimisations = map funcopt
[chainJumps, mergeTerminators, looseJumps,
removeUnusedBlocks, removeDuplicateBlocks,
@@ -150,16 +156,20 @@ constantPropagate :: FuncOptimisation
constantPropagate (IRFunc rt name al bbs sid) = IRFunc rt name al bbs' sid
where
alltemps = findAllTempsBBList bbs
+ alltempsmuts = Map.fromList $ map (\ref -> (ref, findMutations' bbs ref)) alltemps
consttemps = catMaybes $ flip map alltemps $ \ref ->
- let locs = findMutations' bbs ref
+ let locs = fromJust $ Map.lookup ref alltempsmuts
loc = head locs
ins = insAt bbs loc
+ usedrefs = findAllRefsIns ins
readlocs = findMentions' bbs ref \\ locs
readinss = map (insAt' bbs) readlocs
allimov = all (maybe False isIMov) readinss
- in if length locs == 1 && (isIMov ins || ((isILoad ins || isIAri ins || isIResize ins) && allimov))
- then Just (loc, ins)
- else Nothing
+ in if length locs == 1 && -- check necessary because it shouldn't be 0
+ all (maybe True ((<=1) . length) . flip Map.lookup alltempsmuts) usedrefs &&
+ (isIMov ins || ((isILoad ins || isIAri ins || isIResize ins) && allimov))
+ then Just (loc, ins)
+ else Nothing
bbs' = case consttemps of
[] -> bbs
@@ -416,7 +426,7 @@ removeUnusedInstructions (IRFunc rt name al bbs sid) = IRFunc rt name al (map go
goI ins@(IGet d _ _) = pureInstruction d ins
goI ins@(IAri _ d _ _) = pureInstruction d ins
goI ins@(ICall _ _) = Just ins
- goI ins@(ICallr _ _ _) = Just ins
+ goI ins@(ICallr d f a) = if length (findMentions' bbs d) == 1 then Just (ICall f a) else Just ins
goI ins@(IResize d _) = pureInstruction d ins
goI IDebugger = Just IDebugger
goI INop = Nothing
@@ -537,6 +547,7 @@ findMutations (BB _ inss _) ref =
catMaybes $ flip map (zip inss [0..]) $ \(ins, idx) -> case ins of
(IMov r _) | r == ref -> Just idx
(ILoad r _) | r == ref -> Just idx
+ (ISet r _ _) | r == ref -> Just idx
(IAri _ r _ _) | r == ref -> Just idx
(ICallr r _ _) | r == ref -> Just idx
(IResize r _) | r == ref -> Just idx