From ecd369e0fbdc71c74ccd327899f8915045a01630 Mon Sep 17 00:00:00 2001 From: tomsmeding Date: Fri, 29 Nov 2019 21:06:54 +0100 Subject: WIP liveness analysis implementation --- Main.hs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'Main.hs') diff --git a/Main.hs b/Main.hs index 14f3202..c378dde 100644 --- a/Main.hs +++ b/Main.hs @@ -1,11 +1,15 @@ module Main where import Control.Monad +import qualified Data.Map.Strict as Map +import qualified Data.Set as Set import System.Environment import System.Exit import Compiler import CompilerMacros +import Intermediate +import Liveness import Optimiser import Parser import VM @@ -34,6 +38,29 @@ parseOptions' (_, Just _) (_:_) = putStrLn "At most one filename argument expect parseOptions :: [String] -> IO (Options, Maybe FilePath) parseOptions = parseOptions' (Options False False, Nothing) +liveness :: IRProgram -> Map.Map Int [Set.Set Int] +liveness (IRProgram bbs _ _) = + let sets = livenessAnalysis bbs bidOf itemsOf outEdges fread fwrite + in Map.fromList (zip (map bidOf bbs) sets) + where + itemsOf (BB _ inss term) = map Right inss ++ [Left term] + fread (Right (_, IAssign r)) = collect [r] + fread (Right (_, IParam _)) = [] + fread (Right (_, IClosure _)) = [] + fread (Right (_, IData _)) = [] + fread (Right (_, ICallC r rs)) = collect (r : rs) + fread (Right (_, IAllocClo _ rs)) = collect rs + fread (Right (_, IDiscard r)) = collect [r] + fread (Left (IBr r _ _)) = collect [r] + fread (Left (IJmp _)) = [] + fread (Left (IRet r)) = collect [r] + fread (Left (ITailC r rs)) = collect (r : rs) + fread (Left IExit) = [] + fread (Left IUnknown) = [] + fwrite (Right (r, _)) = collect [r] + fwrite (Left _) = [] + collect rs = [i | RTemp i <- rs] + main :: IO () main = do (opts, mfname) <- getArgs >>= parseOptions @@ -45,4 +72,5 @@ main = do irprog <- either die return (compileProgram prog') let opt = optimise irprog when (optIR opts) $ print opt + print (liveness opt) vmRun opt -- cgit v1.2.3-70-g09d2