summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Bolingbroke <batterseapower@hotmail.com>2011-07-06 16:18:09 +0100
committerMax Bolingbroke <batterseapower@hotmail.com>2011-07-06 16:41:20 +0100
commit41ca0b8dcb91cf02f389b3d099c33fbdf009312c (patch)
tree29b35ed3623b47ce36f25ede3abd79eedeb84e6d
parent43293b8c3210003c9e5b5b4a662f0fdb874353b7 (diff)
downloadhaskell-41ca0b8dcb91cf02f389b3d099c33fbdf009312c.tar.gz
Refactoring: explicitly mark whether we have an info table in RawCmm
I introduced this to support explicitly recording the info table label in RawCmm for another patch I am working on, but it turned out to lead to significant simplification in those parts of the compiler that consume RawCmm. Now, instead of lots of tests for null [CmmStatic] we have a simple test of a Maybe, and have reduced the number of guys that need to know how to convert entry->info labels by a TON. There are only 3 callers of that function now!
-rw-r--r--compiler/cmm/CmmDecl.hs2
-rw-r--r--compiler/cmm/CmmInfo.hs6
-rw-r--r--compiler/cmm/CmmOpt.hs11
-rw-r--r--compiler/cmm/OldCmm.hs9
-rw-r--r--compiler/cmm/PprC.hs10
-rw-r--r--compiler/llvmGen/LlvmCodeGen.hs7
-rw-r--r--compiler/llvmGen/LlvmCodeGen/Base.hs2
-rw-r--r--compiler/llvmGen/LlvmCodeGen/Ppr.hs20
-rw-r--r--compiler/nativeGen/AsmCodeGen.lhs2
-rw-r--r--compiler/nativeGen/Instruction.hs4
-rw-r--r--compiler/nativeGen/PPC/Ppr.hs30
-rw-r--r--compiler/nativeGen/RegAlloc/Liveness.hs6
-rw-r--r--compiler/nativeGen/SPARC/Ppr.hs30
-rw-r--r--compiler/nativeGen/X86/Ppr.hs33
14 files changed, 90 insertions, 82 deletions
diff --git a/compiler/cmm/CmmDecl.hs b/compiler/cmm/CmmDecl.hs
index a663b8483f..b154e5094b 100644
--- a/compiler/cmm/CmmDecl.hs
+++ b/compiler/cmm/CmmDecl.hs
@@ -55,7 +55,7 @@ newtype GenCmm d h g = Cmm [GenCmmTop d h g]
data GenCmmTop d h g
= CmmProc -- A procedure
h -- Extra header such as the info table
- CLabel -- Used to generate both info & entry labels
+ CLabel -- Used to generate both info & entry labels (though the info table label is in 'h' in RawCmmTop)
g -- Control-flow graph for the procedure's code
| CmmData -- Static data
diff --git a/compiler/cmm/CmmInfo.hs b/compiler/cmm/CmmInfo.hs
index a606da2aec..107e64f2d4 100644
--- a/compiler/cmm/CmmInfo.hs
+++ b/compiler/cmm/CmmInfo.hs
@@ -78,7 +78,7 @@ mkInfoTable _ (CmmData sec dat) = [CmmData sec dat]
mkInfoTable uniq (CmmProc (CmmInfo _ _ info) entry_label blocks) =
case info of
-- Code without an info table. Easy.
- CmmNonInfoTable -> [CmmProc [] entry_label blocks]
+ CmmNonInfoTable -> [CmmProc Nothing entry_label blocks]
CmmInfoTable _ (ProfilingInfo ty_prof cl_prof) type_tag type_info ->
let info_label = entryLblToInfoLbl entry_label
@@ -153,7 +153,7 @@ mkInfoTableAndCode :: CLabel
-> [RawCmmTop]
mkInfoTableAndCode info_lbl std_info extra_bits entry_lbl blocks
| tablesNextToCode -- Reverse the extra_bits; and emit the top-level proc
- = [CmmProc (map CmmStaticLit (reverse extra_bits ++ std_info))
+ = [CmmProc (Just (Statics info_lbl $ map CmmStaticLit (reverse extra_bits ++ std_info)))
entry_lbl blocks]
| ListGraph [] <- blocks -- No code; only the info table is significant
@@ -163,7 +163,7 @@ mkInfoTableAndCode info_lbl std_info extra_bits entry_lbl blocks
| otherwise -- Separately emit info table (with the function entry
= -- point as first entry) and the entry code
- [CmmProc [] entry_lbl blocks,
+ [CmmProc Nothing entry_lbl blocks,
mkDataLits info_lbl (CmmLabel entry_lbl : std_info ++ extra_bits)]
mkSRTLit :: CLabel
diff --git a/compiler/cmm/CmmOpt.hs b/compiler/cmm/CmmOpt.hs
index 28f21e21f3..5480d9c597 100644
--- a/compiler/cmm/CmmOpt.hs
+++ b/compiler/cmm/CmmOpt.hs
@@ -673,12 +673,11 @@ exactLog2 x_
-}
cmmLoopifyForC :: RawCmmTop -> RawCmmTop
-cmmLoopifyForC p@(CmmProc info entry_lbl
- (ListGraph blocks@(BasicBlock top_id _ : _)))
- | null info = p -- only if there's an info table, ignore case alts
- | otherwise =
+cmmLoopifyForC p@(CmmProc Nothing _ _) = p -- only if there's an info table, ignore case alts
+cmmLoopifyForC p@(CmmProc (Just info@(Statics info_lbl _)) entry_lbl
+ (ListGraph blocks@(BasicBlock top_id _ : _))) =
-- pprTrace "jump_lbl" (ppr jump_lbl <+> ppr entry_lbl) $
- CmmProc info entry_lbl (ListGraph blocks')
+ CmmProc (Just info) entry_lbl (ListGraph blocks')
where blocks' = [ BasicBlock id (map do_stmt stmts)
| BasicBlock id stmts <- blocks ]
@@ -686,7 +685,7 @@ cmmLoopifyForC p@(CmmProc info entry_lbl
= CmmBranch top_id
do_stmt stmt = stmt
- jump_lbl | tablesNextToCode = entryLblToInfoLbl entry_lbl
+ jump_lbl | tablesNextToCode = info_lbl
| otherwise = entry_lbl
cmmLoopifyForC top = top
diff --git a/compiler/cmm/OldCmm.hs b/compiler/cmm/OldCmm.hs
index 5ba78dcc7e..f691183038 100644
--- a/compiler/cmm/OldCmm.hs
+++ b/compiler/cmm/OldCmm.hs
@@ -76,9 +76,12 @@ newtype ListGraph i = ListGraph [GenBasicBlock i]
type Cmm = GenCmm CmmStatics CmmInfo (ListGraph CmmStmt)
type CmmTop = GenCmmTop CmmStatics CmmInfo (ListGraph CmmStmt)
--- | Cmm with the info tables converted to a list of 'CmmStatic'
-type RawCmm = GenCmm CmmStatics [CmmStatic] (ListGraph CmmStmt)
-type RawCmmTop = GenCmmTop CmmStatics [CmmStatic] (ListGraph CmmStmt)
+-- | Cmm with the info tables converted to a list of 'CmmStatic' along with the info
+-- table label. If we are building without tables-next-to-code there will be no statics
+--
+-- INVARIANT: if there is an info table, it has at least one CmmStatic
+type RawCmm = GenCmm CmmStatics (Maybe CmmStatics) (ListGraph CmmStmt)
+type RawCmmTop = GenCmmTop CmmStatics (Maybe CmmStatics) (ListGraph CmmStmt)
-- A basic block containing a single label, at the beginning.
diff --git a/compiler/cmm/PprC.hs b/compiler/cmm/PprC.hs
index fe29bc604d..b48d2de3c8 100644
--- a/compiler/cmm/PprC.hs
+++ b/compiler/cmm/PprC.hs
@@ -83,11 +83,11 @@ pprC (Cmm tops) = vcat $ intersperse blankLine $ map pprTop tops
-- top level procs
--
pprTop :: RawCmmTop -> SDoc
-pprTop (CmmProc info clbl (ListGraph blocks)) =
- (if not (null info)
- then pprDataExterns info $$
- pprWordArray (entryLblToInfoLbl clbl) info
- else empty) $$
+pprTop (CmmProc mb_info clbl (ListGraph blocks)) =
+ (case mb_info of
+ Nothing -> empty
+ Just (Statics info_clbl info_dat) -> pprDataExterns info_dat $$
+ pprWordArray info_clbl info_dat) $$
(vcat [
blankLine,
extern_decls,
diff --git a/compiler/llvmGen/LlvmCodeGen.hs b/compiler/llvmGen/LlvmCodeGen.hs
index 46f3f268a3..340a313561 100644
--- a/compiler/llvmGen/LlvmCodeGen.hs
+++ b/compiler/llvmGen/LlvmCodeGen.hs
@@ -13,7 +13,6 @@ import LlvmCodeGen.Data
import LlvmCodeGen.Ppr
import LlvmMangler
-import CLabel
import CgUtils ( fixStgRegisters )
import OldCmm
import OldPprCmm
@@ -40,9 +39,9 @@ llvmCodeGen dflags h us cmms
(cdata,env) = foldr split ([],initLlvmEnv) cmm
split (CmmData s d' ) (d,e) = ((s,d'):d,e)
split (CmmProc i l _) (d,e) =
- let lbl = strCLabel_llvm $ if not (null i)
- then entryLblToInfoLbl l
- else l
+ let lbl = strCLabel_llvm $ case i of
+ Nothing -> l
+ Just (Statics info_lbl _) -> info_lbl
env' = funInsert lbl llvmFunTy e
in (d,env')
in do
diff --git a/compiler/llvmGen/LlvmCodeGen/Base.hs b/compiler/llvmGen/LlvmCodeGen/Base.hs
index e73f41cde1..1c7592ad2d 100644
--- a/compiler/llvmGen/LlvmCodeGen/Base.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Base.hs
@@ -41,7 +41,7 @@ import Unique
-- * Some Data Types
--
-type LlvmCmmTop = GenCmmTop [LlvmData] [CmmStatic] (ListGraph LlvmStatement)
+type LlvmCmmTop = GenCmmTop [LlvmData] (Maybe CmmStatics) (ListGraph LlvmStatement)
type LlvmBasicBlock = GenBasicBlock LlvmStatement
-- | Unresolved code.
diff --git a/compiler/llvmGen/LlvmCodeGen/Ppr.hs b/compiler/llvmGen/LlvmCodeGen/Ppr.hs
index 48a0d6967c..40f7ce05f1 100644
--- a/compiler/llvmGen/LlvmCodeGen/Ppr.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Ppr.hs
@@ -82,16 +82,16 @@ pprLlvmCmmTop :: LlvmEnv -> Int -> LlvmCmmTop -> (Doc, [LlvmVar])
pprLlvmCmmTop _ _ (CmmData _ lmdata)
= (vcat $ map pprLlvmData lmdata, [])
-pprLlvmCmmTop env count (CmmProc info lbl (ListGraph blks))
- = let static = Statics lbl info
- (idoc, ivar) = if not (null info)
- then pprInfoTable env count lbl static
- else (empty, [])
+pprLlvmCmmTop env count (CmmProc mb_info entry_lbl (ListGraph blks))
+ = let (idoc, ivar) = case mb_info of
+ Nothing -> (empty, [])
+ Just (Statics info_lbl dat)
+ -> pprInfoTable env count info_lbl (Statics entry_lbl dat)
in (idoc $+$ (
let sec = mkLayoutSection (count + 1)
- (lbl',sec') = if not (null info)
- then (entryLblToInfoLbl lbl, sec)
- else (lbl, Nothing)
+ (lbl',sec') = case mb_info of
+ Nothing -> (entry_lbl, Nothing)
+ Just (Statics info_lbl _) -> (info_lbl, sec)
link = if externallyVisibleCLabel lbl'
then ExternallyVisible
else Internal
@@ -104,13 +104,13 @@ pprLlvmCmmTop env count (CmmProc info lbl (ListGraph blks))
-- | Pretty print CmmStatic
pprInfoTable :: LlvmEnv -> Int -> CLabel -> CmmStatics -> (Doc, [LlvmVar])
-pprInfoTable env count lbl stat
+pprInfoTable env count info_lbl stat
= let unres = genLlvmData (Text, stat)
(_, (ldata, ltypes)) = resolveLlvmData env unres
setSection ((LMGlobalVar _ ty l _ _ c), d)
= let sec = mkLayoutSection count
- ilabel = strCLabel_llvm (entryLblToInfoLbl lbl)
+ ilabel = strCLabel_llvm info_lbl
`appendFS` fsLit iTableSuf
gv = LMGlobalVar ilabel ty l sec llvmInfAlign c
v = if l == Internal then [gv] else []
diff --git a/compiler/nativeGen/AsmCodeGen.lhs b/compiler/nativeGen/AsmCodeGen.lhs
index bfeaf9e8e3..83082eaab8 100644
--- a/compiler/nativeGen/AsmCodeGen.lhs
+++ b/compiler/nativeGen/AsmCodeGen.lhs
@@ -267,7 +267,7 @@ nativeCodeGen' dflags ncgImpl h us cmms
| dopt Opt_SplitObjs dflags = split_marker : tops
| otherwise = tops
- split_marker = CmmProc [] mkSplitMarkerLabel (ListGraph [])
+ split_marker = CmmProc Nothing mkSplitMarkerLabel (ListGraph [])
-- | Do native code generation on all these cmms.
diff --git a/compiler/nativeGen/Instruction.hs b/compiler/nativeGen/Instruction.hs
index 5c85101e8e..7bcaa2b2a9 100644
--- a/compiler/nativeGen/Instruction.hs
+++ b/compiler/nativeGen/Instruction.hs
@@ -38,13 +38,13 @@ noUsage = RU [] []
type NatCmm instr
= GenCmm
CmmStatics
- [CmmStatic]
+ (Maybe CmmStatics)
(ListGraph instr)
type NatCmmTop statics instr
= GenCmmTop
statics
- [CmmStatic]
+ (Maybe CmmStatics)
(ListGraph instr)
diff --git a/compiler/nativeGen/PPC/Ppr.hs b/compiler/nativeGen/PPC/Ppr.hs
index 7d85b4c66b..3209e9981c 100644
--- a/compiler/nativeGen/PPC/Ppr.hs
+++ b/compiler/nativeGen/PPC/Ppr.hs
@@ -54,19 +54,23 @@ pprNatCmmTop (CmmData section dats) =
pprSectionHeader section $$ pprDatas dats
-- special case for split markers:
-pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel lbl
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph [])) = pprLabel lbl
-pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
+ -- special case for code without an info table:
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph blocks)) =
pprSectionHeader Text $$
- (if null info then -- blocks guaranteed not null, so label needed
- pprLabel lbl
- else
+ pprLabel lbl $$ -- blocks guaranteed not null, so label needed
+ vcat (map pprBasicBlock blocks)
+
+pprNatCmmTop (CmmProc (Just (Statics info_lbl info)) _entry_lbl (ListGraph blocks)) =
+ pprSectionHeader Text $$
+ (
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
- pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- <> char ':' $$
+ pprCLabel_asm (mkDeadStripPreventer info_lbl)
+ <> char ':' $$
#endif
vcat (map pprData info) $$
- pprLabel (entryLblToInfoLbl lbl)
+ pprLabel info_lbl
) $$
vcat (map pprBasicBlock blocks)
-- above: Even the first block gets a label, because with branch-chain
@@ -78,12 +82,10 @@ pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
-- from the entry code to a label on the _top_ of of the info table,
-- so that the linker will not think it is unreferenced and dead-strip
-- it. That's why the label is called a DeadStripPreventer (_dsp).
- $$ if not (null info)
- then text "\t.long "
- <+> pprCLabel_asm (entryLblToInfoLbl lbl)
- <+> char '-'
- <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- else empty
+ $$ text "\t.long "
+ <+> pprCLabel_asm info_lbl
+ <+> char '-'
+ <+> pprCLabel_asm (mkDeadStripPreventer info_lbl)
#endif
diff --git a/compiler/nativeGen/RegAlloc/Liveness.hs b/compiler/nativeGen/RegAlloc/Liveness.hs
index a6a3724bfa..0f9220de8f 100644
--- a/compiler/nativeGen/RegAlloc/Liveness.hs
+++ b/compiler/nativeGen/RegAlloc/Liveness.hs
@@ -158,7 +158,7 @@ data Liveness
-- | Stash regs live on entry to each basic block in the info part of the cmm code.
data LiveInfo
= LiveInfo
- [CmmStatic] -- cmm static stuff
+ (Maybe CmmStatics) -- cmm info table static stuff
(Maybe BlockId) -- id of the first block
(Maybe (BlockMap RegSet)) -- argument locals live on entry to this block
(Map BlockId (Set Int)) -- stack slots live on entry to this block
@@ -212,8 +212,8 @@ instance Outputable instr
| otherwise = name <> (hcat $ punctuate space $ map ppr $ uniqSetToList regs)
instance Outputable LiveInfo where
- ppr (LiveInfo static firstId liveVRegsOnEntry liveSlotsOnEntry)
- = (vcat $ map ppr static)
+ ppr (LiveInfo mb_static firstId liveVRegsOnEntry liveSlotsOnEntry)
+ = (maybe empty ppr mb_static)
$$ text "# firstId = " <> ppr firstId
$$ text "# liveVRegsOnEntry = " <> ppr liveVRegsOnEntry
$$ text "# liveSlotsOnEntry = " <> text (show liveSlotsOnEntry)
diff --git a/compiler/nativeGen/SPARC/Ppr.hs b/compiler/nativeGen/SPARC/Ppr.hs
index 7f3583f26c..aab700acc3 100644
--- a/compiler/nativeGen/SPARC/Ppr.hs
+++ b/compiler/nativeGen/SPARC/Ppr.hs
@@ -52,19 +52,23 @@ pprNatCmmTop (CmmData section dats) =
pprSectionHeader section $$ pprDatas dats
-- special case for split markers:
-pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel lbl
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph [])) = pprLabel lbl
-pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
+ -- special case for code without info table:
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph blocks)) =
pprSectionHeader Text $$
- (if null info then -- blocks guaranteed not null, so label needed
- pprLabel lbl
- else
+ pprLabel lbl $$ -- blocks guaranteed not null, so label needed
+ vcat (map pprBasicBlock blocks)
+
+pprNatCmmTop (CmmProc (Just (Statics info_lbl info)) _entry_lbl (ListGraph blocks)) =
+ pprSectionHeader Text $$
+ (
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
- pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- <> char ':' $$
+ pprCLabel_asm (mkDeadStripPreventer info_lbl)
+ <> char ':' $$
#endif
vcat (map pprData info) $$
- pprLabel (entryLblToInfoLbl lbl)
+ pprLabel info_lbl
) $$
vcat (map pprBasicBlock blocks)
-- above: Even the first block gets a label, because with branch-chain
@@ -76,12 +80,10 @@ pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
-- from the entry code to a label on the _top_ of of the info table,
-- so that the linker will not think it is unreferenced and dead-strip
-- it. That's why the label is called a DeadStripPreventer (_dsp).
- $$ if not (null info)
- then text "\t.long "
- <+> pprCLabel_asm (entryLblToInfoLbl lbl)
- <+> char '-'
- <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- else empty
+ $$ text "\t.long "
+ <+> pprCLabel_asm info_lbl
+ <+> char '-'
+ <+> pprCLabel_asm (mkDeadStripPreventer info_lbl)
#endif
diff --git a/compiler/nativeGen/X86/Ppr.hs b/compiler/nativeGen/X86/Ppr.hs
index 10af5ef8c1..5762cd93d5 100644
--- a/compiler/nativeGen/X86/Ppr.hs
+++ b/compiler/nativeGen/X86/Ppr.hs
@@ -54,19 +54,24 @@ pprNatCmmTop (CmmData section dats) =
pprSectionHeader section $$ pprDatas dats
-- special case for split markers:
-pprNatCmmTop (CmmProc [] lbl (ListGraph [])) = pprLabel lbl
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph [])) = pprLabel lbl
-pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
+ -- special case for code without info table:
+pprNatCmmTop (CmmProc Nothing lbl (ListGraph blocks)) =
pprSectionHeader Text $$
- (if null info then -- blocks guaranteed not null, so label needed
- pprLabel lbl
- else
+ pprLabel lbl $$ -- blocks guaranteed not null, so label needed
+ vcat (map pprBasicBlock blocks) $$
+ pprSizeDecl lbl
+
+pprNatCmmTop (CmmProc (Just (Statics info_lbl info)) _entry_lbl (ListGraph blocks)) =
+ pprSectionHeader Text $$
+ (
#if HAVE_SUBSECTIONS_VIA_SYMBOLS
- pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- <> char ':' $$
+ pprCLabel_asm (mkDeadStripPreventer info_lbl)
+ <> char ':' $$
#endif
vcat (map pprData info) $$
- pprLabel (entryLblToInfoLbl lbl)
+ pprLabel info_lbl
) $$
vcat (map pprBasicBlock blocks)
-- above: Even the first block gets a label, because with branch-chain
@@ -78,14 +83,12 @@ pprNatCmmTop (CmmProc info lbl (ListGraph blocks)) =
-- from the entry code to a label on the _top_ of of the info table,
-- so that the linker will not think it is unreferenced and dead-strip
-- it. That's why the label is called a DeadStripPreventer (_dsp).
- $$ if not (null info)
- then text "\t.long "
- <+> pprCLabel_asm (entryLblToInfoLbl lbl)
- <+> char '-'
- <+> pprCLabel_asm (mkDeadStripPreventer $ entryLblToInfoLbl lbl)
- else empty
+ $$ text "\t.long "
+ <+> pprCLabel_asm info_lbl
+ <+> char '-'
+ <+> pprCLabel_asm (mkDeadStripPreventer info_lbl)
#endif
- $$ pprSizeDecl (if null info then lbl else entryLblToInfoLbl lbl)
+ $$ pprSizeDecl info_lbl
-- | Output the ELF .size directive.
pprSizeDecl :: CLabel -> Doc