Hooked the C-- CPS pass into the compilation pipeline
authorMichael D. Adams <t-madams@microsoft.com>
Thu, 10 May 2007 13:46:00 +0000 (13:46 +0000)
committerMichael D. Adams <t-madams@microsoft.com>
Thu, 10 May 2007 13:46:00 +0000 (13:46 +0000)
At present it just annotates each block with a comment
indicating what local registers are live at the start
of the block.

compiler/cmm/CmmCPS.hs [new file with mode: 0644]
compiler/main/DynFlags.hs
compiler/main/HscMain.lhs

diff --git a/compiler/cmm/CmmCPS.hs b/compiler/cmm/CmmCPS.hs
new file mode 100644 (file)
index 0000000..4ec2fc6
--- /dev/null
@@ -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
index 82f0cfe..a5c1ab8 100644 (file)
@@ -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)
index c86bd48..93324d5 100644 (file)
@@ -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"