diff options
author | tomsmeding <tom.smeding@gmail.com> | 2019-11-22 20:38:16 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2019-11-22 20:38:16 +0100 |
commit | eb424bfc184132c0f8075e706ffb0494ef80b2b3 (patch) | |
tree | 3520a8db38d0aa29bf106355d413e49b69314310 /Optimiser.hs | |
parent | 5571189b64ea3a566f89aa55a15a99d8122815c6 (diff) |
Deduplicate data table entries
Diffstat (limited to 'Optimiser.hs')
-rw-r--r-- | Optimiser.hs | 34 |
1 files changed, 27 insertions, 7 deletions
diff --git a/Optimiser.hs b/Optimiser.hs index a6c5e10..b6dd902 100644 --- a/Optimiser.hs +++ b/Optimiser.hs @@ -11,13 +11,17 @@ import Intermediate optimise :: IRProgram -> IRProgram -optimise (IRProgram bbs gfds datas) = - let optf = foldl (.) id - [ tailCallIntro - , deadBBElim gfds, mergeRets - , deadStoreElim, deadBBElim gfds - , map propAssigns - , mergeRets, mergeBlocks] +optimise prog = + let progoptf = foldl (.) id . reverse $ + [ dedupDatas ] + optf = foldl (.) id . reverse $ + [ mergeBlocks, mergeRets + , map propAssigns + , deadBBElim gfds, deadStoreElim + , mergeRets, deadBBElim gfds + , tailCallIntro ] + + IRProgram bbs gfds datas = progoptf prog in IRProgram (optf bbs) gfds datas mergeBlocks :: [BB] -> [BB] @@ -119,6 +123,17 @@ tailCallIntro bbs = map introduce bbs BB bid (init inss) (ITailC cl as) _ -> orig +dedupDatas :: IRProgram -> IRProgram +dedupDatas (IRProgram origbbs gfds datatbl) = IRProgram (map goBB origbbs) gfds values + where + values = uniq (sort datatbl) + valueIdx = Map.fromList (zip values [0..]) + + goBB (BB bid inss term) = BB bid (map goI inss) term + + goI (ref, IData i) = (ref, IData (valueIdx Map.! (datatbl !! i))) + goI ins = ins + outEdges :: BB -> [Int] outEdges (BB _ _ term) = outEdgesT term @@ -161,3 +176,8 @@ readTempsR RNone = [] mapFoldl :: (s -> a -> (s, b)) -> s -> [a] -> (s, [b]) mapFoldl f s = fmap reverse . foldl' (\(s', yet) x -> fmap (: yet) (f s' x)) (s, []) + +uniq :: Eq a => [a] -> [a] +uniq (x:y:zs) | x == y = uniq (y:zs) + | otherwise = x : uniq (y:zs) +uniq l = l |