{-# LANGUAGE GADTs, BangPatterns, RecordWildCards,
GeneralizedNewtypeDeriving, NondecreasingIndentation, TupleSections,
ScopedTypeVariables, OverloadedStrings, LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
module GHC.Cmm.Info.Build
( CAFSet, CAFEnv, cafAnal, cafAnalData
, doSRTs, ModuleSRTInfo (..), emptySRT
, SRTMap, srtMapNonCAFs
) where
import GHC.Prelude hiding (succ)
import GHC.Platform
import GHC.Platform.Profile
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Cmm.BlockId
import GHC.Cmm.Dataflow.Block
import GHC.Cmm.Dataflow.Graph
import GHC.Cmm.Dataflow.Label
import GHC.Cmm.Dataflow.Collections
import GHC.Cmm.Dataflow
import GHC.Unit.Module
import GHC.Data.Graph.Directed
import GHC.Cmm.CLabel
import GHC.Cmm
import GHC.Cmm.Utils
import GHC.Driver.Session
import GHC.Data.Maybe
import GHC.Utils.Outputable
import GHC.Utils.Panic
import GHC.Runtime.Heap.Layout
import GHC.Types.Unique.Supply
import GHC.Types.CostCentre
import GHC.StgToCmm.Heap
import GHC.CmmToAsm
import Control.Monad
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
import qualified Data.Set as Set
import Control.Monad.Trans.State
import Control.Monad.Trans.Class
import Data.List (unzip4)
import GHC.Types.Name.Set
newtype CAFLabel = CAFLabel CLabel
deriving (CAFLabel -> CAFLabel -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CAFLabel -> CAFLabel -> Bool
$c/= :: CAFLabel -> CAFLabel -> Bool
== :: CAFLabel -> CAFLabel -> Bool
$c== :: CAFLabel -> CAFLabel -> Bool
Eq,Eq CAFLabel
CAFLabel -> CAFLabel -> Bool
CAFLabel -> CAFLabel -> Ordering
CAFLabel -> CAFLabel -> CAFLabel
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: CAFLabel -> CAFLabel -> CAFLabel
$cmin :: CAFLabel -> CAFLabel -> CAFLabel
max :: CAFLabel -> CAFLabel -> CAFLabel
$cmax :: CAFLabel -> CAFLabel -> CAFLabel
>= :: CAFLabel -> CAFLabel -> Bool
$c>= :: CAFLabel -> CAFLabel -> Bool
> :: CAFLabel -> CAFLabel -> Bool
$c> :: CAFLabel -> CAFLabel -> Bool
<= :: CAFLabel -> CAFLabel -> Bool
$c<= :: CAFLabel -> CAFLabel -> Bool
< :: CAFLabel -> CAFLabel -> Bool
$c< :: CAFLabel -> CAFLabel -> Bool
compare :: CAFLabel -> CAFLabel -> Ordering
$ccompare :: CAFLabel -> CAFLabel -> Ordering
Ord)
deriving newtype instance OutputableP env CLabel => OutputableP env CAFLabel
type CAFSet = Set CAFLabel
type CAFEnv = LabelMap CAFSet
type DataCAFEnv = Map CLabel CAFSet
mkCAFLabel :: Platform -> CLabel -> CAFLabel
mkCAFLabel :: Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform CLabel
lbl = CLabel -> CAFLabel
CAFLabel (Platform -> CLabel -> CLabel
toClosureLbl Platform
platform CLabel
lbl)
newtype SRTEntry = SRTEntry CLabel
deriving (SRTEntry -> SRTEntry -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SRTEntry -> SRTEntry -> Bool
$c/= :: SRTEntry -> SRTEntry -> Bool
== :: SRTEntry -> SRTEntry -> Bool
$c== :: SRTEntry -> SRTEntry -> Bool
Eq, Eq SRTEntry
SRTEntry -> SRTEntry -> Bool
SRTEntry -> SRTEntry -> Ordering
SRTEntry -> SRTEntry -> SRTEntry
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SRTEntry -> SRTEntry -> SRTEntry
$cmin :: SRTEntry -> SRTEntry -> SRTEntry
max :: SRTEntry -> SRTEntry -> SRTEntry
$cmax :: SRTEntry -> SRTEntry -> SRTEntry
>= :: SRTEntry -> SRTEntry -> Bool
$c>= :: SRTEntry -> SRTEntry -> Bool
> :: SRTEntry -> SRTEntry -> Bool
$c> :: SRTEntry -> SRTEntry -> Bool
<= :: SRTEntry -> SRTEntry -> Bool
$c<= :: SRTEntry -> SRTEntry -> Bool
< :: SRTEntry -> SRTEntry -> Bool
$c< :: SRTEntry -> SRTEntry -> Bool
compare :: SRTEntry -> SRTEntry -> Ordering
$ccompare :: SRTEntry -> SRTEntry -> Ordering
Ord)
deriving newtype instance OutputableP env CLabel => OutputableP env SRTEntry
addCafLabel :: Platform -> CLabel -> CAFSet -> CAFSet
addCafLabel :: Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
l Set CAFLabel
s
| Just Name
_ <- CLabel -> Maybe Name
hasHaskellName CLabel
l
, let caf_label :: CAFLabel
caf_label = Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform CLabel
l
, CLabel -> Bool
hasCAF CLabel
l
= forall a. Ord a => a -> Set a -> Set a
Set.insert CAFLabel
caf_label Set CAFLabel
s
| Bool
otherwise
= Set CAFLabel
s
cafAnalData
:: Platform
-> CmmStatics
-> CAFSet
cafAnalData :: Platform -> GenCmmStatics 'False -> Set CAFLabel
cafAnalData Platform
platform GenCmmStatics 'False
st = case GenCmmStatics 'False
st of
CmmStaticsRaw CLabel
_lbl [CmmStatic]
_data -> forall a. Set a
Set.empty
CmmStatics CLabel
_lbl CmmInfoTable
_itbl CostCentreStack
_ccs [CmmLit]
payload ->
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' Set CAFLabel -> CmmLit -> Set CAFLabel
analyzeStatic forall a. Set a
Set.empty [CmmLit]
payload
where
analyzeStatic :: Set CAFLabel -> CmmLit -> Set CAFLabel
analyzeStatic Set CAFLabel
s CmmLit
lit =
case CmmLit
lit of
CmmLabel CLabel
c -> Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c Set CAFLabel
s
CmmLabelOff CLabel
c WordOff
_ -> Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c Set CAFLabel
s
CmmLabelDiffOff CLabel
c1 CLabel
c2 WordOff
_ Width
_ -> Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c1 forall a b. (a -> b) -> a -> b
$! Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c2 Set CAFLabel
s
CmmLit
_ -> Set CAFLabel
s
cafAnal
:: Platform
-> LabelSet
-> CLabel
-> CmmGraph
-> CAFEnv
cafAnal :: Platform -> LabelSet -> CLabel -> GenCmmGraph CmmNode -> CAFEnv
cafAnal Platform
platform LabelSet
contLbls CLabel
topLbl GenCmmGraph CmmNode
cmmGraph =
forall f.
DataflowLattice f
-> TransferFun f -> GenCmmGraph CmmNode -> FactBase f -> FactBase f
analyzeCmmBwd DataflowLattice (Set CAFLabel)
cafLattice
(Platform
-> LabelSet -> BlockId -> CLabel -> TransferFun (Set CAFLabel)
cafTransfers Platform
platform LabelSet
contLbls (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
cmmGraph) CLabel
topLbl) GenCmmGraph CmmNode
cmmGraph forall (map :: * -> *) a. IsMap map => map a
mapEmpty
cafLattice :: DataflowLattice CAFSet
cafLattice :: DataflowLattice (Set CAFLabel)
cafLattice = forall a. a -> JoinFun a -> DataflowLattice a
DataflowLattice forall a. Set a
Set.empty forall {a}.
Ord a =>
OldFact (Set a) -> NewFact (Set a) -> JoinedFact (Set a)
add
where
add :: OldFact (Set a) -> NewFact (Set a) -> JoinedFact (Set a)
add (OldFact Set a
old) (NewFact Set a
new) =
let !new' :: Set a
new' = Set a
old forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set a
new
in forall a. Bool -> a -> JoinedFact a
changedIf (forall a. Set a -> WordOff
Set.size Set a
new' forall a. Ord a => a -> a -> Bool
> forall a. Set a -> WordOff
Set.size Set a
old) Set a
new'
cafTransfers :: Platform -> LabelSet -> Label -> CLabel -> TransferFun CAFSet
cafTransfers :: Platform
-> LabelSet -> BlockId -> CLabel -> TransferFun (Set CAFLabel)
cafTransfers Platform
platform LabelSet
contLbls BlockId
entry CLabel
topLbl
block :: CmmBlock
block@(BlockCC CmmNode C O
eNode Block CmmNode O O
middle CmmNode O C
xNode) CAFEnv
fBase =
let joined :: CAFSet
joined :: Set CAFLabel
joined = forall (e :: Extensibility) (x :: Extensibility).
CmmNode e x -> Set CAFLabel -> Set CAFLabel
cafsInNode CmmNode O C
xNode forall a b. (a -> b) -> a -> b
$! Set CAFLabel
live'
result :: CAFSet
!result :: Set CAFLabel
result = forall f. (CmmNode O O -> f -> f) -> Block CmmNode O O -> f -> f
foldNodesBwdOO forall (e :: Extensibility) (x :: Extensibility).
CmmNode e x -> Set CAFLabel -> Set CAFLabel
cafsInNode Block CmmNode O O
middle Set CAFLabel
joined
facts :: [Set CAFLabel]
facts :: [Set CAFLabel]
facts = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe BlockId -> Maybe (Set CAFLabel)
successorFact (forall (thing :: Extensibility -> Extensibility -> *)
(e :: Extensibility).
NonLocal thing =>
thing e C -> [BlockId]
successors CmmNode O C
xNode)
live' :: CAFSet
live' :: Set CAFLabel
live' = forall f. DataflowLattice f -> [f] -> f
joinFacts DataflowLattice (Set CAFLabel)
cafLattice [Set CAFLabel]
facts
successorFact :: Label -> Maybe (Set CAFLabel)
successorFact :: BlockId -> Maybe (Set CAFLabel)
successorFact BlockId
s
| BlockId
s forall a. Eq a => a -> a -> Bool
== BlockId
entry = forall a. a -> Maybe a
Just (Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
topLbl forall a. Set a
Set.empty)
| BlockId
s forall set. IsSet set => ElemOf set -> set -> Bool
`setMember` LabelSet
contLbls
= forall a. a -> Maybe a
Just (forall a. a -> Set a
Set.singleton (Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform (BlockId -> CLabel
infoTblLbl BlockId
s)))
| Bool
otherwise
= forall f. BlockId -> FactBase f -> Maybe f
lookupFact BlockId
s CAFEnv
fBase
cafsInNode :: CmmNode e x -> CAFSet -> CAFSet
cafsInNode :: forall (e :: Extensibility) (x :: Extensibility).
CmmNode e x -> Set CAFLabel -> Set CAFLabel
cafsInNode CmmNode e x
node Set CAFLabel
set = forall z (e :: Extensibility) (x :: Extensibility).
(CmmExpr -> z -> z) -> CmmNode e x -> z -> z
foldExpDeep CmmExpr -> Set CAFLabel -> Set CAFLabel
addCafExpr CmmNode e x
node Set CAFLabel
set
addCafExpr :: CmmExpr -> Set CAFLabel -> Set CAFLabel
addCafExpr :: CmmExpr -> Set CAFLabel -> Set CAFLabel
addCafExpr CmmExpr
expr !Set CAFLabel
set =
case CmmExpr
expr of
CmmLit (CmmLabel CLabel
c) ->
Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c Set CAFLabel
set
CmmLit (CmmLabelOff CLabel
c WordOff
_) ->
Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c Set CAFLabel
set
CmmLit (CmmLabelDiffOff CLabel
c1 CLabel
c2 WordOff
_ Width
_) ->
Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c1 forall a b. (a -> b) -> a -> b
$! Platform -> CLabel -> Set CAFLabel -> Set CAFLabel
addCafLabel Platform
platform CLabel
c2 Set CAFLabel
set
CmmExpr
_ ->
Set CAFLabel
set
in
forall b. String -> SDoc -> b -> b
srtTrace String
"cafTransfers" (String -> SDoc
text String
"block:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CmmBlock
block SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"contLbls:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr LabelSet
contLbls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"entry:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr BlockId
entry SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"topLbl:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CLabel
topLbl SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"cafs in exit:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set CAFLabel
joined SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"result:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set CAFLabel
result) forall a b. (a -> b) -> a -> b
$
forall (map :: * -> *) a. IsMap map => KeyOf map -> a -> map a
mapSingleton (forall (thing :: Extensibility -> Extensibility -> *)
(x :: Extensibility).
NonLocal thing =>
thing C x -> BlockId
entryLabel CmmNode C O
eNode) Set CAFLabel
result
data ModuleSRTInfo = ModuleSRTInfo
{ ModuleSRTInfo -> Module
thisModule :: Module
, ModuleSRTInfo -> Map (Set SRTEntry) SRTEntry
dedupSRTs :: Map (Set SRTEntry) SRTEntry
, ModuleSRTInfo -> Map SRTEntry (Set SRTEntry)
flatSRTs :: Map SRTEntry (Set SRTEntry)
, ModuleSRTInfo -> SRTMap
moduleSRTMap :: SRTMap
}
instance OutputableP env CLabel => OutputableP env ModuleSRTInfo where
pdoc :: env -> ModuleSRTInfo -> SDoc
pdoc env
env ModuleSRTInfo{Map (Set SRTEntry) SRTEntry
SRTMap
Map SRTEntry (Set SRTEntry)
Module
moduleSRTMap :: SRTMap
flatSRTs :: Map SRTEntry (Set SRTEntry)
dedupSRTs :: Map (Set SRTEntry) SRTEntry
thisModule :: Module
moduleSRTMap :: ModuleSRTInfo -> SRTMap
flatSRTs :: ModuleSRTInfo -> Map SRTEntry (Set SRTEntry)
dedupSRTs :: ModuleSRTInfo -> Map (Set SRTEntry) SRTEntry
thisModule :: ModuleSRTInfo -> Module
..} =
String -> SDoc
text String
"ModuleSRTInfo {" SDoc -> SDoc -> SDoc
$$
(WordOff -> SDoc -> SDoc
nest WordOff
4 forall a b. (a -> b) -> a -> b
$ String -> SDoc
text String
"dedupSRTs =" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env Map (Set SRTEntry) SRTEntry
dedupSRTs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"flatSRTs =" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env Map SRTEntry (Set SRTEntry)
flatSRTs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"moduleSRTMap =" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env SRTMap
moduleSRTMap) SDoc -> SDoc -> SDoc
$$ Char -> SDoc
char Char
'}'
emptySRT :: Module -> ModuleSRTInfo
emptySRT :: Module -> ModuleSRTInfo
emptySRT Module
mod =
ModuleSRTInfo
{ thisModule :: Module
thisModule = Module
mod
, dedupSRTs :: Map (Set SRTEntry) SRTEntry
dedupSRTs = forall k a. Map k a
Map.empty
, flatSRTs :: Map SRTEntry (Set SRTEntry)
flatSRTs = forall k a. Map k a
Map.empty
, moduleSRTMap :: SRTMap
moduleSRTMap = forall k a. Map k a
Map.empty
}
data SomeLabel
= BlockLabel !Label
| DeclLabel CLabel
deriving (SomeLabel -> SomeLabel -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SomeLabel -> SomeLabel -> Bool
$c/= :: SomeLabel -> SomeLabel -> Bool
== :: SomeLabel -> SomeLabel -> Bool
$c== :: SomeLabel -> SomeLabel -> Bool
Eq, Eq SomeLabel
SomeLabel -> SomeLabel -> Bool
SomeLabel -> SomeLabel -> Ordering
SomeLabel -> SomeLabel -> SomeLabel
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: SomeLabel -> SomeLabel -> SomeLabel
$cmin :: SomeLabel -> SomeLabel -> SomeLabel
max :: SomeLabel -> SomeLabel -> SomeLabel
$cmax :: SomeLabel -> SomeLabel -> SomeLabel
>= :: SomeLabel -> SomeLabel -> Bool
$c>= :: SomeLabel -> SomeLabel -> Bool
> :: SomeLabel -> SomeLabel -> Bool
$c> :: SomeLabel -> SomeLabel -> Bool
<= :: SomeLabel -> SomeLabel -> Bool
$c<= :: SomeLabel -> SomeLabel -> Bool
< :: SomeLabel -> SomeLabel -> Bool
$c< :: SomeLabel -> SomeLabel -> Bool
compare :: SomeLabel -> SomeLabel -> Ordering
$ccompare :: SomeLabel -> SomeLabel -> Ordering
Ord)
instance OutputableP env CLabel => OutputableP env SomeLabel where
pdoc :: env -> SomeLabel -> SDoc
pdoc env
env = \case
BlockLabel BlockId
l -> String -> SDoc
text String
"b:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env BlockId
l
DeclLabel CLabel
l -> String -> SDoc
text String
"s:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc env
env CLabel
l
getBlockLabel :: SomeLabel -> Maybe Label
getBlockLabel :: SomeLabel -> Maybe BlockId
getBlockLabel (BlockLabel BlockId
l) = forall a. a -> Maybe a
Just BlockId
l
getBlockLabel (DeclLabel CLabel
_) = forall a. Maybe a
Nothing
getBlockLabels :: [SomeLabel] -> [Label]
getBlockLabels :: [SomeLabel] -> [BlockId]
getBlockLabels = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe SomeLabel -> Maybe BlockId
getBlockLabel
getLabelledBlocks :: Platform -> CmmDecl -> [(SomeLabel, CAFLabel)]
getLabelledBlocks :: Platform -> CmmDecl -> [(SomeLabel, CAFLabel)]
getLabelledBlocks Platform
platform CmmDecl
decl = case CmmDecl
decl of
CmmData Section
_ (CmmStaticsRaw CLabel
_ [CmmStatic]
_) -> []
CmmData Section
_ (CmmStatics CLabel
lbl CmmInfoTable
_ CostCentreStack
_ [CmmLit]
_) -> [ (CLabel -> SomeLabel
DeclLabel CLabel
lbl, Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform CLabel
lbl) ]
CmmProc CmmTopInfo
top_info CLabel
_ [GlobalReg]
_ GenCmmGraph CmmNode
_ -> [ (BlockId -> SomeLabel
BlockLabel BlockId
blockId, CAFLabel
caf_lbl)
| (BlockId
blockId, CmmInfoTable
info) <- forall (map :: * -> *) a. IsMap map => map a -> [(KeyOf map, a)]
mapToList (CmmTopInfo -> LabelMap CmmInfoTable
info_tbls CmmTopInfo
top_info)
, let rep :: SMRep
rep = CmmInfoTable -> SMRep
cit_rep CmmInfoTable
info
, Bool -> Bool
not (SMRep -> Bool
isStaticRep SMRep
rep) Bool -> Bool -> Bool
|| Bool -> Bool
not (SMRep -> Bool
isThunkRep SMRep
rep)
, let !caf_lbl :: CAFLabel
caf_lbl = Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform (CmmInfoTable -> CLabel
cit_lbl CmmInfoTable
info)
]
depAnalSRTs
:: Platform
-> CAFEnv
-> Map CLabel CAFSet
-> [CmmDecl]
-> [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
depAnalSRTs :: Platform
-> CAFEnv
-> DataCAFEnv
-> [CmmDecl]
-> [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
depAnalSRTs Platform
platform CAFEnv
cafEnv DataCAFEnv
cafEnv_static [CmmDecl]
decls =
forall b. String -> SDoc -> b -> b
srtTrace String
"depAnalSRTs" (String -> SDoc
text String
"decls:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CmmDecl]
decls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"nodes:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform (forall a b. (a -> b) -> [a] -> [b]
map forall key payload. Node key payload -> payload
node_payload [Node SomeLabel (SomeLabel, CAFLabel, Set CAFLabel)]
nodes) SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"graph:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
graph) [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
graph
where
labelledBlocks :: [(SomeLabel, CAFLabel)]
labelledBlocks :: [(SomeLabel, CAFLabel)]
labelledBlocks = forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Platform -> CmmDecl -> [(SomeLabel, CAFLabel)]
getLabelledBlocks Platform
platform) [CmmDecl]
decls
labelToBlock :: Map CAFLabel SomeLabel
labelToBlock :: Map CAFLabel SomeLabel
labelToBlock = forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Map CAFLabel SomeLabel
m (SomeLabel
v,CAFLabel
k) -> forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert CAFLabel
k SomeLabel
v Map CAFLabel SomeLabel
m) forall k a. Map k a
Map.empty [(SomeLabel, CAFLabel)]
labelledBlocks
nodes :: [Node SomeLabel (SomeLabel, CAFLabel, Set CAFLabel)]
nodes :: [Node SomeLabel (SomeLabel, CAFLabel, Set CAFLabel)]
nodes = [ forall key payload. payload -> key -> [key] -> Node key payload
DigraphNode (SomeLabel
l,CAFLabel
lbl,Set CAFLabel
cafs') SomeLabel
l
(forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (forall a b c. (a -> b -> c) -> b -> a -> c
flip forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Map CAFLabel SomeLabel
labelToBlock) (forall a. Set a -> [a]
Set.toList Set CAFLabel
cafs'))
| (SomeLabel
l, CAFLabel
lbl) <- [(SomeLabel, CAFLabel)]
labelledBlocks
, Just (Set CAFLabel
cafs :: Set CAFLabel) <-
[case SomeLabel
l of
BlockLabel BlockId
l -> forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup BlockId
l CAFEnv
cafEnv
DeclLabel CLabel
cl -> forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup CLabel
cl DataCAFEnv
cafEnv_static]
, let cafs' :: Set CAFLabel
cafs' = forall a. Ord a => a -> Set a -> Set a
Set.delete CAFLabel
lbl Set CAFLabel
cafs
]
graph :: [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
graph :: [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
graph = forall key payload. Ord key => [Node key payload] -> [SCC payload]
stronglyConnCompFromEdgedVerticesOrd [Node SomeLabel (SomeLabel, CAFLabel, Set CAFLabel)]
nodes
getCAFs :: Platform -> CAFEnv -> [CmmDecl] -> [(Label, CAFLabel, Set CAFLabel)]
getCAFs :: Platform
-> CAFEnv -> [CmmDecl] -> [(BlockId, CAFLabel, Set CAFLabel)]
getCAFs Platform
platform CAFEnv
cafEnv [CmmDecl]
decls =
[ (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g, Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform CLabel
topLbl, Set CAFLabel
cafs)
| CmmProc CmmTopInfo
top_info CLabel
topLbl [GlobalReg]
_ GenCmmGraph CmmNode
g <- [CmmDecl]
decls
, Just CmmInfoTable
info <- [forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) (CmmTopInfo -> LabelMap CmmInfoTable
info_tbls CmmTopInfo
top_info)]
, let rep :: SMRep
rep = CmmInfoTable -> SMRep
cit_rep CmmInfoTable
info
, SMRep -> Bool
isStaticRep SMRep
rep Bool -> Bool -> Bool
&& SMRep -> Bool
isThunkRep SMRep
rep
, Just Set CAFLabel
cafs <- [forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) CAFEnv
cafEnv]
]
getStaticFuns :: [CmmDecl] -> [(BlockId, CLabel)]
getStaticFuns :: [CmmDecl] -> [(BlockId, CLabel)]
getStaticFuns [CmmDecl]
decls =
[ (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g, CLabel
lbl)
| CmmProc CmmTopInfo
top_info CLabel
_ [GlobalReg]
_ GenCmmGraph CmmNode
g <- [CmmDecl]
decls
, Just CmmInfoTable
info <- [forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) (CmmTopInfo -> LabelMap CmmInfoTable
info_tbls CmmTopInfo
top_info)]
, Just (Id
id, CostCentreStack
_) <- [CmmInfoTable -> Maybe (Id, CostCentreStack)
cit_clo CmmInfoTable
info]
, let rep :: SMRep
rep = CmmInfoTable -> SMRep
cit_rep CmmInfoTable
info
, SMRep -> Bool
isStaticRep SMRep
rep Bool -> Bool -> Bool
&& SMRep -> Bool
isFunRep SMRep
rep
, let !lbl :: CLabel
lbl = Name -> CafInfo -> CLabel
mkLocalClosureLabel (Id -> Name
idName Id
id) (Id -> CafInfo
idCafInfo Id
id)
]
type SRTMap = Map CAFLabel (Maybe SRTEntry)
srtMapNonCAFs :: SRTMap -> NonCaffySet
srtMapNonCAFs :: SRTMap -> NonCaffySet
srtMapNonCAFs SRTMap
srtMap =
NameSet -> NonCaffySet
NonCaffySet forall a b. (a -> b) -> a -> b
$ [Name] -> NameSet
mkNameSet (forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall {a}. (CAFLabel, Maybe a) -> Maybe Name
get_name (forall k a. Map k a -> [(k, a)]
Map.toList SRTMap
srtMap))
where
get_name :: (CAFLabel, Maybe a) -> Maybe Name
get_name (CAFLabel CLabel
l, Maybe a
Nothing) = CLabel -> Maybe Name
hasHaskellName CLabel
l
get_name (CAFLabel
_l, Just a
_srt_entry) = forall a. Maybe a
Nothing
resolveCAF :: Platform -> SRTMap -> CAFLabel -> Maybe SRTEntry
resolveCAF :: Platform -> SRTMap -> CAFLabel -> Maybe SRTEntry
resolveCAF Platform
platform SRTMap
srtMap lbl :: CAFLabel
lbl@(CAFLabel CLabel
l) =
forall b. String -> SDoc -> b -> b
srtTrace String
"resolveCAF" (SDoc
"l:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CLabel
l SDoc -> SDoc -> SDoc
<+> SDoc
"resolved:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Maybe SRTEntry
ret) Maybe SRTEntry
ret
where
ret :: Maybe SRTEntry
ret = forall k a. Ord k => a -> k -> Map k a -> a
Map.findWithDefault (forall a. a -> Maybe a
Just (CLabel -> SRTEntry
SRTEntry (Platform -> CLabel -> CLabel
toClosureLbl Platform
platform CLabel
l))) CAFLabel
lbl SRTMap
srtMap
doSRTs
:: DynFlags
-> ModuleSRTInfo
-> [(CAFEnv, [CmmDecl])]
-> [(CAFSet, CmmDecl)]
-> IO (ModuleSRTInfo, [CmmDeclSRTs])
doSRTs :: DynFlags
-> ModuleSRTInfo
-> [(CAFEnv, [CmmDecl])]
-> [(Set CAFLabel, CmmDecl)]
-> IO (ModuleSRTInfo, [CmmDeclSRTs])
doSRTs DynFlags
dflags ModuleSRTInfo
moduleSRTInfo [(CAFEnv, [CmmDecl])]
procs [(Set CAFLabel, CmmDecl)]
data_ = do
UniqSupply
us <- Char -> IO UniqSupply
mkSplitUniqSupply Char
'u'
let profile :: Profile
profile = DynFlags -> Profile
targetProfile DynFlags
dflags
let static_data_env :: DataCAFEnv
static_data_env :: DataCAFEnv
static_data_env =
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList forall a b. (a -> b) -> a -> b
$
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a b. (a -> b) -> [a] -> [b]
map [(Set CAFLabel, CmmDecl)]
data_ forall a b. (a -> b) -> a -> b
$
\(Set CAFLabel
set, CmmDecl
decl) ->
case CmmDecl
decl of
CmmProc{} ->
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"doSRTs" (String -> SDoc
text String
"Proc in static data list:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CmmDecl
decl)
CmmData Section
_ GenCmmStatics 'False
static ->
case GenCmmStatics 'False
static of
CmmStatics CLabel
lbl CmmInfoTable
_ CostCentreStack
_ [CmmLit]
_ -> (CLabel
lbl, Set CAFLabel
set)
CmmStaticsRaw CLabel
lbl [CmmStatic]
_ -> (CLabel
lbl, Set CAFLabel
set)
([CAFEnv]
proc_envs, [[CmmDecl]]
procss) = forall a b. [(a, b)] -> ([a], [b])
unzip [(CAFEnv, [CmmDecl])]
procs
cafEnv :: CAFEnv
cafEnv = forall (map :: * -> *) a. IsMap map => [map a] -> map a
mapUnions [CAFEnv]
proc_envs
decls :: [CmmDecl]
decls = forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(Set CAFLabel, CmmDecl)]
data_ forall a. [a] -> [a] -> [a]
++ forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[CmmDecl]]
procss
staticFuns :: LabelMap CLabel
staticFuns = forall (map :: * -> *) a. IsMap map => [(KeyOf map, a)] -> map a
mapFromList ([CmmDecl] -> [(BlockId, CLabel)]
getStaticFuns [CmmDecl]
decls)
platform :: Platform
platform = DynFlags -> Platform
targetPlatform DynFlags
dflags
let
sccs :: [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
sccs :: [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
sccs = {-# SCC depAnalSRTs #-} Platform
-> CAFEnv
-> DataCAFEnv
-> [CmmDecl]
-> [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
depAnalSRTs Platform
platform CAFEnv
cafEnv DataCAFEnv
static_data_env [CmmDecl]
decls
cafsWithSRTs :: [(Label, CAFLabel, Set CAFLabel)]
cafsWithSRTs :: [(BlockId, CAFLabel, Set CAFLabel)]
cafsWithSRTs = Platform
-> CAFEnv -> [CmmDecl] -> [(BlockId, CAFLabel, Set CAFLabel)]
getCAFs Platform
platform CAFEnv
cafEnv [CmmDecl]
decls
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"doSRTs" (String -> SDoc
text String
"data:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [(Set CAFLabel, CmmDecl)]
data_ SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"procs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [(CAFEnv, [CmmDecl])]
procs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"static_data_env:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform DataCAFEnv
static_data_env SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"sccs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
sccs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"cafsWithSRTs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [(BlockId, CAFLabel, Set CAFLabel)]
cafsWithSRTs)
let result ::
[ ( [CmmDeclSRTs]
, [(Label, CLabel)]
, [(Label, [SRTEntry])]
, Bool
) ]
([([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
result, ModuleSRTInfo
moduleSRTInfo') =
forall a. UniqSupply -> UniqSM a -> a
initUs_ UniqSupply
us forall a b. (a -> b) -> a -> b
$
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall s (m :: * -> *) a. StateT s m a -> s -> m (a, s)
runStateT ModuleSRTInfo
moduleSRTInfo forall a b. (a -> b) -> a -> b
$ do
[([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
nonCAFs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (DynFlags
-> LabelMap CLabel
-> DataCAFEnv
-> SCC (SomeLabel, CAFLabel, Set CAFLabel)
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
doSCC DynFlags
dflags LabelMap CLabel
staticFuns DataCAFEnv
static_data_env) [SCC (SomeLabel, CAFLabel, Set CAFLabel)]
sccs
[([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
cAFs <- forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(BlockId, CAFLabel, Set CAFLabel)]
cafsWithSRTs forall a b. (a -> b) -> a -> b
$ \(BlockId
l, CAFLabel
cafLbl, Set CAFLabel
cafs) ->
DynFlags
-> LabelMap CLabel
-> [SomeLabel]
-> [CAFLabel]
-> Bool
-> Set CAFLabel
-> DataCAFEnv
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
oneSRT DynFlags
dflags LabelMap CLabel
staticFuns [BlockId -> SomeLabel
BlockLabel BlockId
l] [CAFLabel
cafLbl]
Bool
True Set CAFLabel
cafs DataCAFEnv
static_data_env
forall (m :: * -> *) a. Monad m => a -> m a
return ([([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
nonCAFs forall a. [a] -> [a] -> [a]
++ [([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
cAFs)
([[CmmDeclSRTs]]
srt_declss, [[(BlockId, CLabel)]]
pairs, [[(BlockId, [SRTEntry])]]
funSRTs, [Bool]
has_caf_refs) = forall a b c d. [(a, b, c, d)] -> ([a], [b], [c], [d])
unzip4 [([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])],
Bool)]
result
srt_decls :: [CmmDeclSRTs]
srt_decls = forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[CmmDeclSRTs]]
srt_declss
let
srtFieldMap :: LabelMap CLabel
srtFieldMap = forall (map :: * -> *) a. IsMap map => [(KeyOf map, a)] -> map a
mapFromList (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(BlockId, CLabel)]]
pairs)
funSRTMap :: LabelMap [SRTEntry]
funSRTMap = forall (map :: * -> *) a. IsMap map => [(KeyOf map, a)] -> map a
mapFromList (forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [[(BlockId, [SRTEntry])]]
funSRTs)
has_caf_refs' :: Bool
has_caf_refs' = forall (t :: * -> *). Foldable t => t Bool -> Bool
or [Bool]
has_caf_refs
decls' :: [CmmDeclSRTs]
decls' =
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Profile
-> LabelMap CLabel
-> LabelMap [SRTEntry]
-> Bool
-> CmmDecl
-> [CmmDeclSRTs]
updInfoSRTs Profile
profile LabelMap CLabel
srtFieldMap LabelMap [SRTEntry]
funSRTMap Bool
has_caf_refs') [CmmDecl]
decls
let srtMap_w_raws :: SRTMap
srtMap_w_raws =
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\(SRTMap
srtMap :: SRTMap) (Set CAFLabel
_, CmmDecl
decl) ->
case CmmDecl
decl of
CmmData Section
_ CmmStatics{} ->
SRTMap
srtMap
CmmData Section
_ (CmmStaticsRaw CLabel
lbl [CmmStatic]
_)
| CLabel -> Bool
isIdLabel CLabel
lbl Bool -> Bool -> Bool
&& Bool -> Bool
not (CLabel -> Bool
isTickyLabel CLabel
lbl) ->
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert (Platform -> CLabel -> CAFLabel
mkCAFLabel Platform
platform CLabel
lbl) forall a. Maybe a
Nothing SRTMap
srtMap
| Bool
otherwise ->
SRTMap
srtMap
CmmProc{} ->
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"doSRTs" (String -> SDoc
text String
"Found Proc in static data list:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CmmDecl
decl))
(ModuleSRTInfo -> SRTMap
moduleSRTMap ModuleSRTInfo
moduleSRTInfo') [(Set CAFLabel, CmmDecl)]
data_
forall (m :: * -> *) a. Monad m => a -> m a
return (ModuleSRTInfo
moduleSRTInfo'{ moduleSRTMap :: SRTMap
moduleSRTMap = SRTMap
srtMap_w_raws }, [CmmDeclSRTs]
srt_decls forall a. [a] -> [a] -> [a]
++ [CmmDeclSRTs]
decls')
doSCC
:: DynFlags
-> LabelMap CLabel
-> DataCAFEnv
-> SCC (SomeLabel, CAFLabel, Set CAFLabel)
-> StateT ModuleSRTInfo UniqSM
( [CmmDeclSRTs]
, [(Label, CLabel)]
, [(Label, [SRTEntry])]
, Bool
)
doSCC :: DynFlags
-> LabelMap CLabel
-> DataCAFEnv
-> SCC (SomeLabel, CAFLabel, Set CAFLabel)
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
doSCC DynFlags
dflags LabelMap CLabel
staticFuns DataCAFEnv
static_data_env (AcyclicSCC (SomeLabel
l, CAFLabel
cafLbl, Set CAFLabel
cafs)) =
DynFlags
-> LabelMap CLabel
-> [SomeLabel]
-> [CAFLabel]
-> Bool
-> Set CAFLabel
-> DataCAFEnv
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
oneSRT DynFlags
dflags LabelMap CLabel
staticFuns [SomeLabel
l] [CAFLabel
cafLbl] Bool
False Set CAFLabel
cafs DataCAFEnv
static_data_env
doSCC DynFlags
dflags LabelMap CLabel
staticFuns DataCAFEnv
static_data_env (CyclicSCC [(SomeLabel, CAFLabel, Set CAFLabel)]
nodes) = do
let ([SomeLabel]
lbls, [CAFLabel]
caf_lbls, [Set CAFLabel]
cafsets) = forall a b c. [(a, b, c)] -> ([a], [b], [c])
unzip3 [(SomeLabel, CAFLabel, Set CAFLabel)]
nodes
cafs :: Set CAFLabel
cafs = forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [Set CAFLabel]
cafsets
DynFlags
-> LabelMap CLabel
-> [SomeLabel]
-> [CAFLabel]
-> Bool
-> Set CAFLabel
-> DataCAFEnv
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
oneSRT DynFlags
dflags LabelMap CLabel
staticFuns [SomeLabel]
lbls [CAFLabel]
caf_lbls Bool
False Set CAFLabel
cafs DataCAFEnv
static_data_env
oneSRT
:: DynFlags
-> LabelMap CLabel
-> [SomeLabel]
-> [CAFLabel]
-> Bool
-> Set CAFLabel
-> DataCAFEnv
-> StateT ModuleSRTInfo UniqSM
( [CmmDeclSRTs]
, [(Label, CLabel)]
, [(Label, [SRTEntry])]
, Bool
)
oneSRT :: DynFlags
-> LabelMap CLabel
-> [SomeLabel]
-> [CAFLabel]
-> Bool
-> Set CAFLabel
-> DataCAFEnv
-> StateT
ModuleSRTInfo
UniqSM
([CmmDeclSRTs], [(BlockId, CLabel)], [(BlockId, [SRTEntry])], Bool)
oneSRT DynFlags
dflags LabelMap CLabel
staticFuns [SomeLabel]
lbls [CAFLabel]
caf_lbls Bool
isCAF Set CAFLabel
cafs DataCAFEnv
static_data_env = do
ModuleSRTInfo
topSRT <- forall (m :: * -> *) s. Monad m => StateT s m s
get
let
this_mod :: Module
this_mod = ModuleSRTInfo -> Module
thisModule ModuleSRTInfo
topSRT
config :: NCGConfig
config = DynFlags -> Module -> NCGConfig
initNCGConfig DynFlags
dflags Module
this_mod
profile :: Profile
profile = DynFlags -> Profile
targetProfile DynFlags
dflags
platform :: Platform
platform = Profile -> Platform
profilePlatform Profile
profile
srtMap :: SRTMap
srtMap = ModuleSRTInfo -> SRTMap
moduleSRTMap ModuleSRTInfo
topSRT
blockids :: [BlockId]
blockids = [SomeLabel] -> [BlockId]
getBlockLabels [SomeLabel]
lbls
maybeFunClosure :: Maybe (CLabel, Label)
otherFunLabels :: [CLabel]
(Maybe (CLabel, BlockId)
maybeFunClosure, [CLabel]
otherFunLabels) =
case [ (CLabel
l,BlockId
b) | BlockId
b <- [BlockId]
blockids, Just CLabel
l <- [forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup BlockId
b LabelMap CLabel
staticFuns] ] of
[] -> (forall a. Maybe a
Nothing, [])
((CLabel
l,BlockId
b):[(CLabel, BlockId)]
xs) -> (forall a. a -> Maybe a
Just (CLabel
l,BlockId
b), forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(CLabel, BlockId)]
xs)
nonRec :: Set CAFLabel
nonRec :: Set CAFLabel
nonRec = Set CAFLabel
cafs forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` forall a. Ord a => [a] -> Set a
Set.fromList [CAFLabel]
caf_lbls
resolved :: [SRTEntry]
resolved :: [SRTEntry]
resolved = forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (Platform -> SRTMap -> CAFLabel -> Maybe SRTEntry
resolveCAF Platform
platform SRTMap
srtMap) (forall a. Set a -> [a]
Set.toList Set CAFLabel
nonRec)
allBelow :: Set SRTEntry
allBelow =
forall (f :: * -> *) a. (Foldable f, Ord a) => f (Set a) -> Set a
Set.unions [ Set SRTEntry
lbls | SRTEntry
caf <- [SRTEntry]
resolved
, Just Set SRTEntry
lbls <- [forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup SRTEntry
caf (ModuleSRTInfo -> Map SRTEntry (Set SRTEntry)
flatSRTs ModuleSRTInfo
topSRT)] ]
filtered0 :: Set SRTEntry
filtered0 = forall a. Ord a => [a] -> Set a
Set.fromList [SRTEntry]
resolved forall a. Ord a => Set a -> Set a -> Set a
`Set.difference` Set SRTEntry
allBelow
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT:"
(String -> SDoc
text String
"srtMap:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform SRTMap
srtMap SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"nonRec:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set CAFLabel
nonRec SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"lbls:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [SomeLabel]
lbls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"caf_lbls:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CAFLabel]
caf_lbls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"static_data_env:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform DataCAFEnv
static_data_env SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"cafs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set CAFLabel
cafs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"blockids:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr [BlockId]
blockids SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"maybeFunClosure:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Maybe (CLabel, BlockId)
maybeFunClosure SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"otherFunLabels:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CLabel]
otherFunLabels SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"resolved:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [SRTEntry]
resolved SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"allBelow:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set SRTEntry
allBelow SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"filtered0:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set SRTEntry
filtered0)
let
isStaticFun :: Bool
isStaticFun = forall a. Maybe a -> Bool
isJust Maybe (CLabel, BlockId)
maybeFunClosure
updateSRTMap :: Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap :: Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap Maybe SRTEntry
srtEntry =
forall b. String -> SDoc -> b -> b
srtTrace String
"updateSRTMap"
(forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Maybe SRTEntry
srtEntry SDoc -> SDoc -> SDoc
<+> SDoc
"isCAF:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
isCAF SDoc -> SDoc -> SDoc
<+>
SDoc
"isStaticFun:" SDoc -> SDoc -> SDoc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
isStaticFun) forall a b. (a -> b) -> a -> b
$
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not Bool
isCAF Bool -> Bool -> Bool
&& (Bool -> Bool
not Bool
isStaticFun Bool -> Bool -> Bool
|| forall a. Maybe a -> Bool
isNothing Maybe SRTEntry
srtEntry)) forall a b. (a -> b) -> a -> b
$
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' forall a b. (a -> b) -> a -> b
$ \ModuleSRTInfo
state ->
let !srt_map :: SRTMap
srt_map =
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\SRTMap
srt_map cafLbl :: CAFLabel
cafLbl@(CAFLabel CLabel
clbl) ->
if Bool -> Bool
not (forall k a. Ord k => k -> Map k a -> Bool
Map.member CLabel
clbl DataCAFEnv
static_data_env) Bool -> Bool -> Bool
|| forall a. Maybe a -> Bool
isNothing Maybe SRTEntry
srtEntry then
forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert CAFLabel
cafLbl Maybe SRTEntry
srtEntry SRTMap
srt_map
else
SRTMap
srt_map)
(ModuleSRTInfo -> SRTMap
moduleSRTMap ModuleSRTInfo
state)
[CAFLabel]
caf_lbls
in
ModuleSRTInfo
state{ moduleSRTMap :: SRTMap
moduleSRTMap = SRTMap
srt_map }
allStaticData :: Bool
allStaticData =
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (\(CAFLabel CLabel
clbl) -> forall k a. Ord k => k -> Map k a -> Bool
Map.member CLabel
clbl DataCAFEnv
static_data_env) [CAFLabel]
caf_lbls
if forall a. Set a -> Bool
Set.null Set SRTEntry
filtered0 then do
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT: empty" (forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CAFLabel]
caf_lbls)
Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap forall a. Maybe a
Nothing
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [], [], Bool
False)
else do
let allBelow_funs :: Set SRTEntry
allBelow_funs =
forall a. Ord a => [a] -> Set a
Set.fromList (forall a b. (a -> b) -> [a] -> [b]
map (CLabel -> SRTEntry
SRTEntry forall b c a. (b -> c) -> (a -> b) -> a -> c
. Platform -> CLabel -> CLabel
toClosureLbl Platform
platform) [CLabel]
otherFunLabels)
let allBelow_data :: Set SRTEntry
allBelow_data =
forall a. Ord a => [a] -> Set a
Set.fromList
[ CLabel -> SRTEntry
SRTEntry forall a b. (a -> b) -> a -> b
$ Platform -> CLabel -> CLabel
toClosureLbl Platform
platform CLabel
lbl
| DeclLabel CLabel
lbl <- [SomeLabel]
lbls
, Just Set CAFLabel
refs <- forall (f :: * -> *) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup CLabel
lbl DataCAFEnv
static_data_env
, Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ forall a. Set a -> Bool
Set.null Set CAFLabel
refs
]
let filtered :: Set SRTEntry
filtered = Set SRTEntry
filtered0 forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set SRTEntry
allBelow_funs forall a. Ord a => Set a -> Set a -> Set a
`Set.union` Set SRTEntry
allBelow_data
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT" (String -> SDoc
text String
"filtered:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set SRTEntry
filtered SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"allBelow_funs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set SRTEntry
allBelow_funs)
case forall a. Set a -> [a]
Set.toList Set SRTEntry
filtered of
[] -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"oneSRT" SDoc
empty
[one :: SRTEntry
one@(SRTEntry CLabel
lbl)]
|
Bool -> Bool
not (NCGConfig -> CLabel -> Bool
labelDynamic NCGConfig
config CLabel
lbl)
Bool -> Bool -> Bool
&& (Bool -> Bool
not (OS -> Bool
osMachOTarget forall a b. (a -> b) -> a -> b
$ Platform -> OS
platformOS forall a b. (a -> b) -> a -> b
$ Profile -> Platform
profilePlatform Profile
profile)
Bool -> Bool -> Bool
|| Module -> CLabel -> Bool
isLocalCLabel Module
this_mod CLabel
lbl) -> do
case Maybe (CLabel, BlockId)
maybeFunClosure of
Just (CLabel
staticFunLbl,BlockId
staticFunBlock) ->
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [(BlockId, CLabel)]
withLabels, [], Bool
True)
where
withLabels :: [(BlockId, CLabel)]
withLabels =
[ (BlockId
b, if BlockId
b forall a. Eq a => a -> a -> Bool
== BlockId
staticFunBlock then CLabel
lbl else CLabel
staticFunLbl)
| BlockId
b <- [BlockId]
blockids ]
Maybe (CLabel, BlockId)
Nothing -> do
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT: one" (String -> SDoc
text String
"caf_lbls:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CAFLabel]
caf_lbls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"one:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform SRTEntry
one)
Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap (forall a. a -> Maybe a
Just SRTEntry
one)
forall (m :: * -> *) a. Monad m => a -> m a
return ([], forall a b. (a -> b) -> [a] -> [b]
map (,CLabel
lbl) [BlockId]
blockids, [], Bool
True)
[SRTEntry]
cafList | Bool
allStaticData ->
forall (m :: * -> *) a. Monad m => a -> m a
return ([], [], [], Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [SRTEntry]
cafList))
[SRTEntry]
cafList ->
case forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Set SRTEntry
filtered (ModuleSRTInfo -> Map (Set SRTEntry) SRTEntry
dedupSRTs ModuleSRTInfo
topSRT) of
Just srtEntry :: SRTEntry
srtEntry@(SRTEntry CLabel
srtLbl) -> do
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT [Common]" (forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CAFLabel]
caf_lbls SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform CLabel
srtLbl)
Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap (forall a. a -> Maybe a
Just SRTEntry
srtEntry)
forall (m :: * -> *) a. Monad m => a -> m a
return ([], forall a b. (a -> b) -> [a] -> [b]
map (,CLabel
srtLbl) [BlockId]
blockids, [], Bool
True)
Maybe SRTEntry
Nothing -> do
([CmmDeclSRTs]
decls, [(BlockId, [SRTEntry])]
funSRTs, SRTEntry
srtEntry) <-
case Maybe (CLabel, BlockId)
maybeFunClosure of
Just (CLabel
fun,BlockId
block) ->
forall (m :: * -> *) a. Monad m => a -> m a
return ( [], [(BlockId
block, [SRTEntry]
cafList)], CLabel -> SRTEntry
SRTEntry CLabel
fun )
Maybe (CLabel, BlockId)
Nothing -> do
([CmmDeclSRTs]
decls, SRTEntry
entry) <- forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift forall a b. (a -> b) -> a -> b
$ Profile -> [SRTEntry] -> UniqSM ([CmmDeclSRTs], SRTEntry)
buildSRTChain Profile
profile [SRTEntry]
cafList
forall (m :: * -> *) a. Monad m => a -> m a
return ([CmmDeclSRTs]
decls, [], SRTEntry
entry)
Maybe SRTEntry -> StateT ModuleSRTInfo UniqSM ()
updateSRTMap (forall a. a -> Maybe a
Just SRTEntry
srtEntry)
let allBelowThis :: Set SRTEntry
allBelowThis = forall a. Ord a => Set a -> Set a -> Set a
Set.union Set SRTEntry
allBelow Set SRTEntry
filtered
newFlatSRTs :: Map SRTEntry (Set SRTEntry)
newFlatSRTs = forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert SRTEntry
srtEntry Set SRTEntry
allBelowThis (ModuleSRTInfo -> Map SRTEntry (Set SRTEntry)
flatSRTs ModuleSRTInfo
topSRT)
newDedupSRTs :: Map (Set SRTEntry) SRTEntry
newDedupSRTs = forall k a. Ord k => k -> a -> Map k a -> Map k a
Map.insert Set SRTEntry
filtered SRTEntry
srtEntry (ModuleSRTInfo -> Map (Set SRTEntry) SRTEntry
dedupSRTs ModuleSRTInfo
topSRT)
forall (m :: * -> *) s. Monad m => (s -> s) -> StateT s m ()
modify' (\ModuleSRTInfo
state -> ModuleSRTInfo
state{ dedupSRTs :: Map (Set SRTEntry) SRTEntry
dedupSRTs = Map (Set SRTEntry) SRTEntry
newDedupSRTs,
flatSRTs :: Map SRTEntry (Set SRTEntry)
flatSRTs = Map SRTEntry (Set SRTEntry)
newFlatSRTs })
forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
"oneSRT: new" (String -> SDoc
text String
"caf_lbls:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform [CAFLabel]
caf_lbls SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"filtered:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Set SRTEntry
filtered SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"srtEntry:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform SRTEntry
srtEntry SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"newDedupSRTs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Map (Set SRTEntry) SRTEntry
newDedupSRTs SDoc -> SDoc -> SDoc
$$
String -> SDoc
text String
"newFlatSRTs:" SDoc -> SDoc -> SDoc
<+> forall env a. OutputableP env a => env -> a -> SDoc
pdoc Platform
platform Map SRTEntry (Set SRTEntry)
newFlatSRTs)
let SRTEntry CLabel
lbl = SRTEntry
srtEntry
forall (m :: * -> *) a. Monad m => a -> m a
return ([CmmDeclSRTs]
decls, forall a b. (a -> b) -> [a] -> [b]
map (,CLabel
lbl) [BlockId]
blockids, [(BlockId, [SRTEntry])]
funSRTs, Bool
True)
buildSRTChain
:: Profile
-> [SRTEntry]
-> UniqSM
( [CmmDeclSRTs]
, SRTEntry
)
buildSRTChain :: Profile -> [SRTEntry] -> UniqSM ([CmmDeclSRTs], SRTEntry)
buildSRTChain Profile
_ [] = forall a. String -> a
panic String
"buildSRT: empty"
buildSRTChain Profile
profile [SRTEntry]
cafSet =
case forall a. WordOff -> [a] -> ([a], [a])
splitAt WordOff
mAX_SRT_SIZE [SRTEntry]
cafSet of
([SRTEntry]
these, []) -> do
(CmmDeclSRTs
decl,SRTEntry
lbl) <- Profile -> [SRTEntry] -> UniqSM (CmmDeclSRTs, SRTEntry)
buildSRT Profile
profile [SRTEntry]
these
forall (m :: * -> *) a. Monad m => a -> m a
return ([CmmDeclSRTs
decl], SRTEntry
lbl)
([SRTEntry]
these,[SRTEntry]
those) -> do
([CmmDeclSRTs]
rest, SRTEntry
rest_lbl) <- Profile -> [SRTEntry] -> UniqSM ([CmmDeclSRTs], SRTEntry)
buildSRTChain Profile
profile (forall a. [a] -> a
head [SRTEntry]
these forall a. a -> [a] -> [a]
: [SRTEntry]
those)
(CmmDeclSRTs
decl,SRTEntry
lbl) <- Profile -> [SRTEntry] -> UniqSM (CmmDeclSRTs, SRTEntry)
buildSRT Profile
profile (SRTEntry
rest_lbl forall a. a -> [a] -> [a]
: forall a. [a] -> [a]
tail [SRTEntry]
these)
forall (m :: * -> *) a. Monad m => a -> m a
return (CmmDeclSRTs
declforall a. a -> [a] -> [a]
:[CmmDeclSRTs]
rest, SRTEntry
lbl)
where
mAX_SRT_SIZE :: WordOff
mAX_SRT_SIZE = WordOff
16
buildSRT :: Profile -> [SRTEntry] -> UniqSM (CmmDeclSRTs, SRTEntry)
buildSRT :: Profile -> [SRTEntry] -> UniqSM (CmmDeclSRTs, SRTEntry)
buildSRT Profile
profile [SRTEntry]
refs = do
Unique
id <- forall (m :: * -> *). MonadUnique m => m Unique
getUniqueM
let
lbl :: CLabel
lbl = Unique -> CLabel
mkSRTLabel Unique
id
platform :: Platform
platform = Profile -> Platform
profilePlatform Profile
profile
srt_n_info :: CLabel
srt_n_info = WordOff -> CLabel
mkSRTInfoLabel (forall (t :: * -> *) a. Foldable t => t a -> WordOff
length [SRTEntry]
refs)
fields :: [CmmLit]
fields =
Profile
-> CLabel
-> CostCentreStack
-> [CmmLit]
-> [CmmLit]
-> [CmmLit]
-> [CmmLit]
-> [CmmLit]
mkStaticClosure Profile
profile CLabel
srt_n_info CostCentreStack
dontCareCCS
[ CLabel -> CmmLit
CmmLabel CLabel
lbl | SRTEntry CLabel
lbl <- [SRTEntry]
refs ]
[]
[Platform -> WordOff -> CmmLit
mkIntCLit Platform
platform WordOff
0]
[]
forall (m :: * -> *) a. Monad m => a -> m a
return (forall (raw :: Bool) info stmt.
Section
-> CLabel -> [CmmLit] -> GenCmmDecl (GenCmmStatics raw) info stmt
mkDataLits (SectionType -> CLabel -> Section
Section SectionType
Data CLabel
lbl) CLabel
lbl [CmmLit]
fields, CLabel -> SRTEntry
SRTEntry CLabel
lbl)
updInfoSRTs
:: Profile
-> LabelMap CLabel
-> LabelMap [SRTEntry]
-> Bool
-> CmmDecl
-> [CmmDeclSRTs]
updInfoSRTs :: Profile
-> LabelMap CLabel
-> LabelMap [SRTEntry]
-> Bool
-> CmmDecl
-> [CmmDeclSRTs]
updInfoSRTs Profile
_ LabelMap CLabel
_ LabelMap [SRTEntry]
_ Bool
_ (CmmData Section
s (CmmStaticsRaw CLabel
lbl [CmmStatic]
statics))
= [forall d h g. Section -> d -> GenCmmDecl d h g
CmmData Section
s (forall (rawOnly :: Bool).
CLabel -> [CmmStatic] -> GenCmmStatics rawOnly
CmmStaticsRaw CLabel
lbl [CmmStatic]
statics)]
updInfoSRTs Profile
profile LabelMap CLabel
_ LabelMap [SRTEntry]
_ Bool
caffy (CmmData Section
s (CmmStatics CLabel
lbl CmmInfoTable
itbl CostCentreStack
ccs [CmmLit]
payload))
= [forall d h g. Section -> d -> GenCmmDecl d h g
CmmData Section
s (forall (rawOnly :: Bool).
CLabel -> [CmmStatic] -> GenCmmStatics rawOnly
CmmStaticsRaw CLabel
lbl (forall a b. (a -> b) -> [a] -> [b]
map CmmLit -> CmmStatic
CmmStaticLit [CmmLit]
field_lits))]
where
caf_info :: CafInfo
caf_info = if Bool
caffy then CafInfo
MayHaveCafRefs else CafInfo
NoCafRefs
field_lits :: [CmmLit]
field_lits = Profile
-> CmmInfoTable
-> CostCentreStack
-> CafInfo
-> [CmmLit]
-> [CmmLit]
mkStaticClosureFields Profile
profile CmmInfoTable
itbl CostCentreStack
ccs CafInfo
caf_info [CmmLit]
payload
updInfoSRTs Profile
profile LabelMap CLabel
srt_env LabelMap [SRTEntry]
funSRTEnv Bool
caffy (CmmProc CmmTopInfo
top_info CLabel
top_l [GlobalReg]
live GenCmmGraph CmmNode
g)
| Just (CmmInfoTable
_,CmmDeclSRTs
closure) <- Maybe (CmmInfoTable, CmmDeclSRTs)
maybeStaticClosure = [ CmmDeclSRTs
proc, CmmDeclSRTs
closure ]
| Bool
otherwise = [ CmmDeclSRTs
proc ]
where
caf_info :: CafInfo
caf_info = if Bool
caffy then CafInfo
MayHaveCafRefs else CafInfo
NoCafRefs
proc :: CmmDeclSRTs
proc = forall d h g. h -> CLabel -> [GlobalReg] -> g -> GenCmmDecl d h g
CmmProc CmmTopInfo
top_info { info_tbls :: LabelMap CmmInfoTable
info_tbls = LabelMap CmmInfoTable
newTopInfo } CLabel
top_l [GlobalReg]
live GenCmmGraph CmmNode
g
newTopInfo :: LabelMap CmmInfoTable
newTopInfo = forall (map :: * -> *) a b.
IsMap map =>
(KeyOf map -> a -> b) -> map a -> map b
mapMapWithKey BlockId -> CmmInfoTable -> CmmInfoTable
updInfoTbl (CmmTopInfo -> LabelMap CmmInfoTable
info_tbls CmmTopInfo
top_info)
updInfoTbl :: BlockId -> CmmInfoTable -> CmmInfoTable
updInfoTbl BlockId
l CmmInfoTable
info_tbl
| BlockId
l forall a. Eq a => a -> a -> Bool
== forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g, Just (CmmInfoTable
inf, CmmDeclSRTs
_) <- Maybe (CmmInfoTable, CmmDeclSRTs)
maybeStaticClosure = CmmInfoTable
inf
| Bool
otherwise = CmmInfoTable
info_tbl { cit_srt :: Maybe CLabel
cit_srt = forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup BlockId
l LabelMap CLabel
srt_env }
maybeStaticClosure :: Maybe (CmmInfoTable, CmmDeclSRTs)
maybeStaticClosure :: Maybe (CmmInfoTable, CmmDeclSRTs)
maybeStaticClosure
| Just info_tbl :: CmmInfoTable
info_tbl@CmmInfoTable{Maybe (Id, CostCentreStack)
Maybe CLabel
SMRep
CLabel
ProfilingInfo
cit_prof :: CmmInfoTable -> ProfilingInfo
cit_clo :: Maybe (Id, CostCentreStack)
cit_srt :: Maybe CLabel
cit_prof :: ProfilingInfo
cit_rep :: SMRep
cit_lbl :: CLabel
cit_srt :: CmmInfoTable -> Maybe CLabel
cit_clo :: CmmInfoTable -> Maybe (Id, CostCentreStack)
cit_lbl :: CmmInfoTable -> CLabel
cit_rep :: CmmInfoTable -> SMRep
..} <-
forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) (CmmTopInfo -> LabelMap CmmInfoTable
info_tbls CmmTopInfo
top_info)
, Just (Id
id, CostCentreStack
ccs) <- Maybe (Id, CostCentreStack)
cit_clo
, SMRep -> Bool
isStaticRep SMRep
cit_rep =
let
(CmmInfoTable
newInfo, [CmmLit]
srtEntries) = case forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) LabelMap [SRTEntry]
funSRTEnv of
Maybe [SRTEntry]
Nothing ->
(CmmInfoTable
info_tbl { cit_srt :: Maybe CLabel
cit_srt = forall (map :: * -> *) a.
IsMap map =>
KeyOf map -> map a -> Maybe a
mapLookup (forall (n :: Extensibility -> Extensibility -> *).
GenCmmGraph n -> BlockId
g_entry GenCmmGraph CmmNode
g) LabelMap CLabel
srt_env }, [])
Just [SRTEntry]
srtEntries -> forall b. String -> SDoc -> b -> b
srtTrace String
"maybeStaticFun" (forall env a. OutputableP env a => env -> a -> SDoc
pdoc (Profile -> Platform
profilePlatform Profile
profile) [CmmLit]
res)
(CmmInfoTable
info_tbl { cit_rep :: SMRep
cit_rep = SMRep
new_rep }, [CmmLit]
res)
where res :: [CmmLit]
res = [ CLabel -> CmmLit
CmmLabel CLabel
lbl | SRTEntry CLabel
lbl <- [SRTEntry]
srtEntries ]
fields :: [CmmLit]
fields = Profile
-> CmmInfoTable
-> CostCentreStack
-> CafInfo
-> [CmmLit]
-> [CmmLit]
mkStaticClosureFields Profile
profile CmmInfoTable
info_tbl CostCentreStack
ccs CafInfo
caf_info [CmmLit]
srtEntries
new_rep :: SMRep
new_rep = case SMRep
cit_rep of
HeapRep Bool
sta WordOff
ptrs WordOff
nptrs ClosureTypeInfo
ty ->
Bool -> WordOff -> WordOff -> ClosureTypeInfo -> SMRep
HeapRep Bool
sta (WordOff
ptrs forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. Foldable t => t a -> WordOff
length [CmmLit]
srtEntries) WordOff
nptrs ClosureTypeInfo
ty
SMRep
_other -> forall a. String -> a
panic String
"maybeStaticFun"
lbl :: CLabel
lbl = Name -> CafInfo -> CLabel
mkLocalClosureLabel (Id -> Name
idName Id
id) CafInfo
caf_info
in
forall a. a -> Maybe a
Just (CmmInfoTable
newInfo, forall (raw :: Bool) info stmt.
Section
-> CLabel -> [CmmLit] -> GenCmmDecl (GenCmmStatics raw) info stmt
mkDataLits (SectionType -> CLabel -> Section
Section SectionType
Data CLabel
lbl) CLabel
lbl [CmmLit]
fields)
| Bool
otherwise = forall a. Maybe a
Nothing
srtTrace :: String -> SDoc -> b -> b
srtTrace :: forall b. String -> SDoc -> b -> b
srtTrace String
_ SDoc
_ b
b = b
b
srtTraceM :: Applicative f => String -> SDoc -> f ()
srtTraceM :: forall (f :: * -> *). Applicative f => String -> SDoc -> f ()
srtTraceM String
str SDoc
doc = forall b. String -> SDoc -> b -> b
srtTrace String
str SDoc
doc (forall (f :: * -> *) a. Applicative f => a -> f a
pure ())