Commit 64339720 authored by Edward Z. Yang's avatar Edward Z. Yang
Browse files

Split -ddump-cmmz into many smaller flags.


Signed-off-by: Edward Z. Yang's avatarEdward Z. Yang <ezyang@mit.edu>
parent 080dabd4
...@@ -67,48 +67,47 @@ mutable reference cells in an 'HscEnv' and are ...@@ -67,48 +67,47 @@ mutable reference cells in an 'HscEnv' and are
global to one compiler session. global to one compiler session.
-} -}
-- EZY: It might be helpful to have an easy way of dumping the "pre"
-- input for any given phase, besides just turning it all on with
-- -ddump-cmmz
cpsTop :: HscEnv -> CmmTop -> IO ([(CLabel, CAFSet)], [(CAFSet, CmmTop)]) cpsTop :: HscEnv -> CmmTop -> IO ([(CLabel, CAFSet)], [(CAFSet, CmmTop)])
cpsTop _ p@(CmmData {}) = return ([], [(Map.empty, p)]) cpsTop _ p@(CmmData {}) = return ([], [(Map.empty, p)])
cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}}) l g) = cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}}) l g) =
do do
-- Why bother doing it this early? -- Why bother doing these early: dualLivenessWithInsertion,
-- g <- dual_rewrite run Opt_D_dump_cmmz "spills and reloads" -- insertLateReloads, rewriteAssignments?
-- (dualLivenessWithInsertion callPPs) g
-- g <- run $ insertLateReloads g -- Duplicate reloads just before uses
-- g <- dual_rewrite runOptimization Opt_D_dump_cmmz "Dead Assignment Elimination"
-- (removeDeadAssignmentsAndReloads callPPs) g
dump Opt_D_dump_cmmz "Pre common block elimination" g
g <- return $ elimCommonBlocks g
dump Opt_D_dump_cmmz "Post common block elimination" g
----------- Eliminate common blocks -------------------
g <- return $ elimCommonBlocks g
dump Opt_D_dump_cmmz_cbe "Post common block elimination" g
-- Any work storing block Labels must be performed _after_ elimCommonBlocks -- Any work storing block Labels must be performed _after_ elimCommonBlocks
----------- Proc points ------------------- ----------- Proc points -------------------
let callPPs = callProcPoints g let callPPs = callProcPoints g
procPoints <- run $ minimalProcPointSet callPPs g procPoints <- run $ minimalProcPointSet callPPs g
g <- run $ addProcPointProtocols callPPs procPoints g g <- run $ addProcPointProtocols callPPs procPoints g
dump Opt_D_dump_cmmz "Post Proc Points Added" g dump Opt_D_dump_cmmz_proc "Post Proc Points Added" g
----------- Spills and reloads ------------------- ----------- Spills and reloads -------------------
g <- g <- run $ dualLivenessWithInsertion procPoints g
-- pprTrace "pre Spills" (ppr g) $ dump Opt_D_dump_cmmz_spills "Post spills and reloads" g
dual_rewrite run Opt_D_dump_cmmz "spills and reloads"
(dualLivenessWithInsertion procPoints) g ----------- Sink and inline assignments -------------------
-- Insert spills at defns; reloads at return points g <- runOptimization $ rewriteAssignments g
g <- dump Opt_D_dump_cmmz_rewrite "Post rewrite assignments" g
runOptimization $ rewriteAssignments g
dump Opt_D_dump_cmmz "Post rewrite assignments" g ----------- Eliminate dead assignments -------------------
g <-
-- pprTrace "post insertLateReloads" (ppr g) $
dual_rewrite runOptimization Opt_D_dump_cmmz "Dead Assignment Elimination"
(removeDeadAssignmentsAndReloads procPoints) g
-- Remove redundant reloads (and any other redundant asst) -- Remove redundant reloads (and any other redundant asst)
g <- runOptimization $ removeDeadAssignmentsAndReloads procPoints g
dump Opt_D_dump_cmmz_dead "Post Dead Assignment Elimination" g
----------- Debug only: add code to put zero in dead stack slots---- ----------- Zero dead stack slots (Debug only) ---------------
-- Debugging: stubbing slots on death can cause crashes early -- Debugging: stubbing slots on death can cause crashes early
g <- -- trace "post dead-assign elim" $ g <- if opt_StubDeadValues
if opt_StubDeadValues then run $ stubSlotsOnDeath g else return g then run $ stubSlotsOnDeath g
else return g
dump Opt_D_dump_cmmz_stub "Post stub dead stack slots" g
--------------- Stack layout ---------------- --------------- Stack layout ----------------
slotEnv <- run $ liveSlotAnal g slotEnv <- run $ liveSlotAnal g
...@@ -119,16 +118,16 @@ cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}}) ...@@ -119,16 +118,16 @@ cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}})
------------ Manifest the stack pointer -------- ------------ Manifest the stack pointer --------
g <- run $ manifestSP spEntryMap areaMap entry_off g g <- run $ manifestSP spEntryMap areaMap entry_off g
dump Opt_D_dump_cmmz "after manifestSP" g dump Opt_D_dump_cmmz_sp "Post manifestSP" g
-- UGH... manifestSP can require updates to the procPointMap. -- UGH... manifestSP can require updates to the procPointMap.
-- We can probably do something quicker here for the update... -- We can probably do something quicker here for the update...
------------- Split into separate procedures ------------ ------------- Split into separate procedures ------------
procPointMap <- run $ procPointAnalysis procPoints g procPointMap <- run $ procPointAnalysis procPoints g
dump Opt_D_dump_cmmz "procpoint map" procPointMap dump Opt_D_dump_cmmz_procmap "procpoint map" procPointMap
gs <- run $ splitAtProcPoints l callPPs procPoints procPointMap gs <- run $ splitAtProcPoints l callPPs procPoints procPointMap
(CmmProc h l g) (CmmProc h l g)
mapM_ (dump Opt_D_dump_cmmz "after splitting") gs mapM_ (dump Opt_D_dump_cmmz_split "Post splitting") gs
------------- More CAFs and foreign calls ------------ ------------- More CAFs and foreign calls ------------
cafEnv <- run $ cafAnal g cafEnv <- run $ cafAnal g
...@@ -136,30 +135,29 @@ cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}}) ...@@ -136,30 +135,29 @@ cpsTop hsc_env (CmmProc h@(TopInfo {stack_info=StackInfo {arg_space=entry_off}})
mbpprTrace "localCAFs" (ppr localCAFs) $ return () mbpprTrace "localCAFs" (ppr localCAFs) $ return ()
gs <- run $ mapM (lowerSafeForeignCalls areaMap) gs gs <- run $ mapM (lowerSafeForeignCalls areaMap) gs
mapM_ (dump Opt_D_dump_cmmz "after lowerSafeForeignCalls") gs mapM_ (dump Opt_D_dump_cmmz_lower "Post lowerSafeForeignCalls") gs
-- NO MORE GRAPH TRANSFORMATION AFTER HERE -- JUST MAKING INFOTABLES -- NO MORE GRAPH TRANSFORMATION AFTER HERE -- JUST MAKING INFOTABLES
let gs' = map (setInfoTableStackMap slotEnv areaMap) gs gs <- return $ map (setInfoTableStackMap slotEnv areaMap) gs
mapM_ (dump Opt_D_dump_cmmz "after setInfoTableStackMap") gs' mapM_ (dump Opt_D_dump_cmmz_info "after setInfoTableStackMap") gs
let gs'' = map (bundleCAFs cafEnv) gs' gs <- return $ map (bundleCAFs cafEnv) gs
mapM_ (dump Opt_D_dump_cmmz "after bundleCAFs") gs'' mapM_ (dump Opt_D_dump_cmmz_cafs "after bundleCAFs") gs
return (localCAFs, gs'') return (localCAFs, gs)
where dflags = hsc_dflags hsc_env where dflags = hsc_dflags hsc_env
mbpprTrace x y z = if dopt Opt_D_dump_cmmz dflags then pprTrace x y z else z mbpprTrace x y z = if dopt Opt_D_dump_cmmz dflags then pprTrace x y z else z
dump f txt g = dumpIfSet_dyn dflags f txt (ppr g) dump f txt g = do
-- ToDo: No easy way of say "dump all the cmmz, *and* split
-- them into files." Also, -ddump-cmmz doesn't play nicely
-- with -ddump-to-file, since the headers get omitted.
dumpIfSet_dyn dflags f txt (ppr g)
when (not (dopt f dflags)) $
dumpIfSet_dyn dflags Opt_D_dump_cmmz txt (ppr g)
-- Runs a required transformation/analysis -- Runs a required transformation/analysis
run = runInfiniteFuelIO (hsc_OptFuel hsc_env) run = runInfiniteFuelIO (hsc_OptFuel hsc_env)
-- Runs an optional transformation/analysis (and should -- Runs an optional transformation/analysis (and should
-- thus be subject to optimization fuel) -- thus be subject to optimization fuel)
runOptimization = runFuelIO (hsc_OptFuel hsc_env) runOptimization = runFuelIO (hsc_OptFuel hsc_env)
-- pass 'run' or 'runOptimization' for 'r'
dual_rewrite r flag txt pass g =
do dump flag ("Pre " ++ txt) g
g <- r $ pass g
dump flag ("Post " ++ txt) $ g
return g
-- This probably belongs in CmmBuildInfoTables? -- This probably belongs in CmmBuildInfoTables?
-- We're just finishing the job here: once we know what CAFs are defined -- We're just finishing the job here: once we know what CAFs are defined
-- in non-static closures, we can build the SRTs. -- in non-static closures, we can build the SRTs.
......
...@@ -122,6 +122,21 @@ data DynFlag ...@@ -122,6 +122,21 @@ data DynFlag
| Opt_D_dump_raw_cmm | Opt_D_dump_raw_cmm
| Opt_D_dump_cmmz | Opt_D_dump_cmmz
| Opt_D_dump_cmmz_pretty | Opt_D_dump_cmmz_pretty
-- All of the cmmz subflags (there are a lot!) Automatically
-- enabled if you run -ddump-cmmz
| Opt_D_dump_cmmz_cbe
| Opt_D_dump_cmmz_proc
| Opt_D_dump_cmmz_spills
| Opt_D_dump_cmmz_rewrite
| Opt_D_dump_cmmz_dead
| Opt_D_dump_cmmz_stub
| Opt_D_dump_cmmz_sp
| Opt_D_dump_cmmz_procmap
| Opt_D_dump_cmmz_split
| Opt_D_dump_cmmz_lower
| Opt_D_dump_cmmz_info
| Opt_D_dump_cmmz_cafs
-- end cmmz subflags
| Opt_D_dump_cps_cmm | Opt_D_dump_cps_cmm
| Opt_D_dump_cvt_cmm | Opt_D_dump_cvt_cmm
| Opt_D_dump_asm | Opt_D_dump_asm
...@@ -1254,6 +1269,18 @@ dynamic_flags = [ ...@@ -1254,6 +1269,18 @@ dynamic_flags = [
, Flag "ddump-raw-cmm" (setDumpFlag Opt_D_dump_raw_cmm) , Flag "ddump-raw-cmm" (setDumpFlag Opt_D_dump_raw_cmm)
, Flag "ddump-cmmz" (setDumpFlag Opt_D_dump_cmmz) , Flag "ddump-cmmz" (setDumpFlag Opt_D_dump_cmmz)
, Flag "ddump-cmmz-pretty" (setDumpFlag Opt_D_dump_cmmz_pretty) , Flag "ddump-cmmz-pretty" (setDumpFlag Opt_D_dump_cmmz_pretty)
, Flag "ddump-cmmz-cbe" (setDumpFlag Opt_D_dump_cmmz_cbe)
, Flag "ddump-cmmz-spills" (setDumpFlag Opt_D_dump_cmmz_spills)
, Flag "ddump-cmmz-proc" (setDumpFlag Opt_D_dump_cmmz_proc)
, Flag "ddump-cmmz-rewrite" (setDumpFlag Opt_D_dump_cmmz_rewrite)
, Flag "ddump-cmmz-dead" (setDumpFlag Opt_D_dump_cmmz_dead)
, Flag "ddump-cmmz-stub" (setDumpFlag Opt_D_dump_cmmz_stub)
, Flag "ddump-cmmz-sp" (setDumpFlag Opt_D_dump_cmmz_sp)
, Flag "ddump-cmmz-procmap" (setDumpFlag Opt_D_dump_cmmz_procmap)
, Flag "ddump-cmmz-split" (setDumpFlag Opt_D_dump_cmmz_split)
, Flag "ddump-cmmz-lower" (setDumpFlag Opt_D_dump_cmmz_lower)
, Flag "ddump-cmmz-info" (setDumpFlag Opt_D_dump_cmmz_info)
, Flag "ddump-cmmz-cafs" (setDumpFlag Opt_D_dump_cmmz_cafs)
, Flag "ddump-core-stats" (setDumpFlag Opt_D_dump_core_stats) , Flag "ddump-core-stats" (setDumpFlag Opt_D_dump_core_stats)
, Flag "ddump-cps-cmm" (setDumpFlag Opt_D_dump_cps_cmm) , Flag "ddump-cps-cmm" (setDumpFlag Opt_D_dump_cps_cmm)
, Flag "ddump-cvt-cmm" (setDumpFlag Opt_D_dump_cvt_cmm) , Flag "ddump-cvt-cmm" (setDumpFlag Opt_D_dump_cvt_cmm)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment