From: Michael D. Adams Date: Thu, 10 May 2007 13:46:00 +0000 (+0000) Subject: Hooked the C-- CPS pass into the compilation pipeline X-Git-Tag: Before_type_family_merge~657 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=d0f6db5b0cf1189d84e292aeca350211f3b810dd Hooked the C-- CPS pass into the compilation pipeline At present it just annotates each block with a comment indicating what local registers are live at the start of the block. --- diff --git a/compiler/cmm/CmmCPS.hs b/compiler/cmm/CmmCPS.hs new file mode 100644 index 0000000..4ec2fc6 --- /dev/null +++ b/compiler/cmm/CmmCPS.hs @@ -0,0 +1,36 @@ +module CmmCPS (cmmCPS) where + +#include "HsVersions.h" + +import Cmm +import CmmLint +import PprCmm + +import Dataflow (mapCmmTop, onBasicBlock, cmmLivenessComment, cmmLiveness) + +import DynFlags +import ErrUtils +import Maybes +import Outputable + +import Monad +import IO + +cmmCPS :: DynFlags + -> [Cmm] -- C-- with Proceedures + -> IO [Cmm] -- Output: CPS transformed C-- + +cmmCPS dflags abstractC = do + when (dopt Opt_DoCmmLinting dflags) $ + do showPass dflags "CmmLint" + case firstJust $ map cmmLint abstractC of + Just err -> do printDump err + ghcExit dflags 1 + Nothing -> return () + showPass dflags "CPS" + -- continuationC <- return abstractC + continuationC <- return $ map (mapCmmTop (onBasicBlock (\bs -> map (cmmLivenessComment (cmmLiveness bs)) bs))) abstractC + + dumpIfSet_dyn dflags Opt_D_dump_cps_cmm "CPS Cmm" (pprCmms continuationC) + -- TODO: add option to dump Cmm to file + return continuationC diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 82f0cfe..a5c1ab8 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -92,6 +92,7 @@ data DynFlag -- debugging flags = Opt_D_dump_cmm + | Opt_D_dump_cps_cmm | Opt_D_dump_asm | Opt_D_dump_cpranal | Opt_D_dump_deriv @@ -937,6 +938,7 @@ dynamic_flags = [ , ( "dstg-stats", NoArg (setDynFlag Opt_StgStats)) , ( "ddump-cmm", setDumpFlag Opt_D_dump_cmm) + , ( "ddump-cps-cmm", setDumpFlag Opt_D_dump_cps_cmm) , ( "ddump-asm", setDumpFlag Opt_D_dump_asm) , ( "ddump-cpranal", setDumpFlag Opt_D_dump_cpranal) , ( "ddump-deriv", setDumpFlag Opt_D_dump_deriv) diff --git a/compiler/main/HscMain.lhs b/compiler/main/HscMain.lhs index c86bd48..93324d5 100644 --- a/compiler/main/HscMain.lhs +++ b/compiler/main/HscMain.lhs @@ -75,6 +75,7 @@ import Name ( Name, NamedThing(..) ) import SimplStg ( stg2stg ) import CodeGen ( codeGen ) import CmmParse ( parseCmmFile ) +import CmmCPS import CodeOutput ( codeOutput ) import NameEnv ( emptyNameEnv ) @@ -603,10 +604,12 @@ hscCompile cgguts codeGen dflags this_mod data_tycons foreign_stubs dir_imps cost_centre_info stg_binds hpc_info + ------------------ Convert to CPS -------------------- + continuationC <- cmmCPS dflags abstractC ------------------ Code output ----------------------- (stub_h_exists,stub_c_exists) <- codeOutput dflags this_mod location foreign_stubs - dependencies abstractC + dependencies continuationC return stub_c_exists hscConst :: b -> a -> Comp b @@ -718,7 +721,8 @@ hscCmmFile dflags filename = do case maybe_cmm of Nothing -> return False Just cmm -> do - codeOutput dflags no_mod no_loc NoStubs [] [cmm] + continuationC <- cmmCPS dflags [cmm] + codeOutput dflags no_mod no_loc NoStubs [] continuationC return True where no_mod = panic "hscCmmFile: no_mod"