{-# LANGUAGE LambdaCase, RecordWildCards, MagicHash, UnboxedTuples, PatternSynonyms, ExplicitNamespaces #-}
module GHC.Cmm.UniqueRenamer
  ( detRenameCmmGroup
  , detRenameIPEMap
  , MonadGetUnique(..)

  -- Careful! Not for general use!
  , DetUniqFM, emptyDetUFM

  , module GHC.Types.Unique.DSM
  )
  where

import GHC.Prelude
import GHC.Utils.Monad.State.Strict
import Data.Tuple (swap)
import GHC.Word
import GHC.Cmm
import GHC.Cmm.CLabel
import GHC.Cmm.Dataflow.Block
import GHC.Cmm.Dataflow.Graph
import GHC.Cmm.Dataflow.Label
import GHC.Cmm.Switch
import GHC.Types.Unique
import GHC.Types.Unique.FM
import GHC.Types.Unique.DFM
import GHC.Utils.Outputable as Outputable
import GHC.Types.Id
import GHC.Types.Unique.DSM
import GHC.Types.Name hiding (varName)
import GHC.Types.Var
import GHC.Types.IPE

{-
Note [Renaming uniques deterministically]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
As mentioned by Note [Object determinism], a key step in producing
deterministic objects is to rename all existing uniques deterministically.

An important observation is that GHC already produces code in a deterministic
order, both declarations (say, A_closure always comes before B_closure) and the
instructions and data within.

We can leverage this /deterministic order/ to
rename all uniques deterministically, by traversing, specifically, Cmm code
fresh off of StgToCmm and assigning a new unique from a deterministic supply
(an incrementing counter) to every non-external unique in the order they are found.

Since the order is deterministic across runs, so will the renamed uniques.

This Cmm renaming pass is guarded by -fobject-determinism because it means the
compiler must do more work. However, performance profiling has shown the impact
to be small enough that we should consider enabling -fobject-determinism by
default instead eventually.
-}

-- | A mapping from non-deterministic uniques to deterministic uniques, to
-- rename local symbols with the end goal of producing deterministic object files.
-- See Note [Renaming uniques deterministically]
data DetUniqFM = DetUniqFM
  { DetUniqFM -> UniqFM Unique Unique
mapping :: !(UniqFM Unique Unique)
  , DetUniqFM -> Word64
supply  :: !Word64
  }

instance Outputable DetUniqFM where
  ppr :: DetUniqFM -> SDoc
ppr DetUniqFM{UniqFM Unique Unique
mapping :: DetUniqFM -> UniqFM Unique Unique
mapping :: UniqFM Unique Unique
mapping, Word64
supply :: DetUniqFM -> Word64
supply :: Word64
supply} =
    UniqFM Unique Unique -> SDoc
forall a. Outputable a => a -> SDoc
ppr UniqFM Unique Unique
mapping SDoc -> SDoc -> SDoc
forall doc. IsDoc doc => doc -> doc -> doc
$$
    String -> SDoc
forall doc. IsLine doc => String -> doc
text String
"supply:" SDoc -> SDoc -> SDoc
forall doc. IsLine doc => doc -> doc -> doc
Outputable.<> Word64 -> SDoc
forall a. Outputable a => a -> SDoc
ppr Word64
supply

type DetRnM = State DetUniqFM

emptyDetUFM :: DetUniqFM
emptyDetUFM :: DetUniqFM
emptyDetUFM = DetUniqFM
  { mapping :: UniqFM Unique Unique
mapping = UniqFM Unique Unique
forall {k} (key :: k) elt. UniqFM key elt
emptyUFM
  -- NB: A lower initial value can get us label `Lsl` which is not parsed
  -- correctly in older versions of LLVM assembler (llvm-project#80571)
  -- So we use an `x` s.t. w64ToBase62 x > "R" > "L" > "r" > "l"
  , supply :: Word64
supply = Word64
54
  }

renameDetUniq :: Unique -> DetRnM Unique
renameDetUniq :: Unique -> DetRnM Unique
renameDetUniq Unique
uq = do
  m <- (DetUniqFM -> UniqFM Unique Unique)
-> State DetUniqFM (UniqFM Unique Unique)
forall s a. (s -> a) -> State s a
gets DetUniqFM -> UniqFM Unique Unique
mapping
  case lookupUFM m uq of
    Maybe Unique
Nothing -> do
      new_w <- (DetUniqFM -> Word64) -> State DetUniqFM Word64
forall s a. (s -> a) -> State s a
gets DetUniqFM -> Word64
supply -- New deterministic unique in this `DetRnM`
      let --(_tag, _) = unpkUnique uq
          det_uniq = Char -> Word64 -> Unique
mkUnique Char
'Q' Word64
new_w
      modify (\DetUniqFM{UniqFM Unique Unique
mapping :: DetUniqFM -> UniqFM Unique Unique
mapping :: UniqFM Unique Unique
mapping, Word64
supply :: DetUniqFM -> Word64
supply :: Word64
supply} ->
        -- Update supply and mapping
        DetUniqFM
          { mapping :: UniqFM Unique Unique
mapping = UniqFM Unique Unique -> Unique -> Unique -> UniqFM Unique Unique
forall key elt.
Uniquable key =>
UniqFM key elt -> key -> elt -> UniqFM key elt
addToUFM UniqFM Unique Unique
mapping Unique
uq Unique
det_uniq
          , supply :: Word64
supply = Word64
supply Word64 -> Word64 -> Word64
forall a. Num a => a -> a -> a
+ Word64
1
          })
      return det_uniq
    Just Unique
det_uniq ->
      Unique -> DetRnM Unique
forall a. a -> State DetUniqFM a
forall (m :: * -> *) a. Monad m => a -> m a
return Unique
det_uniq

-- The most important function here, which does the actual renaming.
detRenameCLabel :: CLabel -> DetRnM CLabel
detRenameCLabel :: CLabel -> DetRnM CLabel
detRenameCLabel = (Unique -> DetRnM Unique) -> CLabel -> DetRnM CLabel
forall (m :: * -> *).
Applicative m =>
(Unique -> m Unique) -> CLabel -> m CLabel
mapInternalNonDetUniques Unique -> DetRnM Unique
renameDetUniq

-- | We want to rename uniques in Ids, but ONLY internal ones.
detRenameId :: Id -> DetRnM Id
detRenameId :: Id -> DetRnM Id
detRenameId Id
i
  | Name -> Bool
isExternalName (Id -> Name
varName Id
i) = Id -> DetRnM Id
forall a. a -> State DetUniqFM a
forall (m :: * -> *) a. Monad m => a -> m a
return Id
i
  | Bool
otherwise = Id -> Unique -> Id
setIdUnique Id
i (Unique -> Id) -> DetRnM Unique -> DetRnM Id
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Unique -> DetRnM Unique
renameDetUniq (Id -> Unique
forall a. Uniquable a => a -> Unique
getUnique Id
i)

-- | Similar to `detRenameId`, but for `Name`.
detRenameName :: Name -> DetRnM Name
detRenameName :: Name -> DetRnM Name
detRenameName Name
n
  | Name -> Bool
isExternalName Name
n = Name -> DetRnM Name
forall a. a -> State DetUniqFM a
forall (m :: * -> *) a. Monad m => a -> m a
return Name
n
  | Bool
otherwise = Name -> Unique -> Name
setNameUnique Name
n (Unique -> Name) -> DetRnM Unique -> DetRnM Name
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Unique -> DetRnM Unique
renameDetUniq (Name -> Unique
forall a. Uniquable a => a -> Unique
getUnique Name
n)

detRenameCmmGroup :: DetUniqFM -> DCmmGroup -> (DetUniqFM, CmmGroup)
detRenameCmmGroup :: DetUniqFM -> DCmmGroup -> (DetUniqFM, CmmGroup)
detRenameCmmGroup DetUniqFM
dufm DCmmGroup
group = (CmmGroup, DetUniqFM) -> (DetUniqFM, CmmGroup)
forall a b. (a, b) -> (b, a)
swap (State DetUniqFM CmmGroup -> DetUniqFM -> (CmmGroup, DetUniqFM)
forall s a. State s a -> s -> (a, s)
runState ((DCmmDecl
 -> State DetUniqFM (GenCmmDecl CmmStatics CmmTopInfo CmmGraph))
-> DCmmGroup -> State DetUniqFM CmmGroup
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM DCmmDecl
-> State DetUniqFM (GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
detRenameCmmDecl DCmmGroup
group) DetUniqFM
dufm)
  where
    detRenameCmmDecl :: DCmmDecl -> DetRnM CmmDecl
    detRenameCmmDecl :: DCmmDecl
-> State DetUniqFM (GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
detRenameCmmDecl (CmmProc DCmmTopInfo
h CLabel
lbl [GlobalRegUse]
regs DCmmGraph
g)
      = do
        h' <- DCmmTopInfo -> DetRnM CmmTopInfo
detRenameCmmTop DCmmTopInfo
h
        lbl' <- detRenameCLabel lbl
        regs' <- mapM detRenameGlobalRegUse regs
        g' <- detRenameCmmGraph g
        return (CmmProc h' lbl' regs' g')
    detRenameCmmDecl (CmmData Section
sec CmmStatics
d)
      = Section -> CmmStatics -> GenCmmDecl CmmStatics CmmTopInfo CmmGraph
forall d h g. Section -> d -> GenCmmDecl d h g
CmmData (Section
 -> CmmStatics -> GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
-> State DetUniqFM Section
-> State
     DetUniqFM (CmmStatics -> GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Section -> State DetUniqFM Section
detRenameSection Section
sec State
  DetUniqFM (CmmStatics -> GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
-> State DetUniqFM CmmStatics
-> State DetUniqFM (GenCmmDecl CmmStatics CmmTopInfo CmmGraph)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmStatics -> State DetUniqFM CmmStatics
detRenameCmmStatics CmmStatics
d

    detRenameCmmTop :: DCmmTopInfo -> DetRnM CmmTopInfo
    detRenameCmmTop :: DCmmTopInfo -> DetRnM CmmTopInfo
detRenameCmmTop (TopInfo (DWrap [(Label, CmmInfoTable)]
i) CmmStackInfo
b)
      = LabelMap CmmInfoTable -> CmmStackInfo -> CmmTopInfo
forall (f :: * -> *).
f CmmInfoTable -> CmmStackInfo -> GenCmmTopInfo f
TopInfo (LabelMap CmmInfoTable -> CmmStackInfo -> CmmTopInfo)
-> ([(Label, CmmInfoTable)] -> LabelMap CmmInfoTable)
-> [(Label, CmmInfoTable)]
-> CmmStackInfo
-> CmmTopInfo
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Label, CmmInfoTable)] -> LabelMap CmmInfoTable
forall v. [(Label, v)] -> LabelMap v
mapFromList ([(Label, CmmInfoTable)] -> CmmStackInfo -> CmmTopInfo)
-> State DetUniqFM [(Label, CmmInfoTable)]
-> State DetUniqFM (CmmStackInfo -> CmmTopInfo)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Label, CmmInfoTable) -> State DetUniqFM (Label, CmmInfoTable))
-> [(Label, CmmInfoTable)]
-> State DetUniqFM [(Label, CmmInfoTable)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((Label -> State DetUniqFM Label)
-> (CmmInfoTable -> State DetUniqFM CmmInfoTable)
-> (Label, CmmInfoTable)
-> State DetUniqFM (Label, CmmInfoTable)
forall {f :: * -> *} {t} {a} {t} {a}.
Applicative f =>
(t -> f a) -> (t -> f a) -> (t, t) -> f (a, a)
detRenamePair Label -> State DetUniqFM Label
detRenameLabel CmmInfoTable -> State DetUniqFM CmmInfoTable
detRenameCmmInfoTable) [(Label, CmmInfoTable)]
i State DetUniqFM (CmmStackInfo -> CmmTopInfo)
-> State DetUniqFM CmmStackInfo -> DetRnM CmmTopInfo
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmStackInfo -> State DetUniqFM CmmStackInfo
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CmmStackInfo
b

    detRenameCmmGraph :: DCmmGraph -> DetRnM CmmGraph
    detRenameCmmGraph :: DCmmGraph -> DetRnM CmmGraph
detRenameCmmGraph (CmmGraph Label
entry Graph' DWrap Block CmmNode C C
bs)
      = Label -> Graph' LabelMap Block CmmNode C C -> CmmGraph
forall (s :: * -> *) (n :: Extensibility -> Extensibility -> *).
Label -> Graph' s Block n C C -> GenGenCmmGraph s n
CmmGraph (Label -> Graph' LabelMap Block CmmNode C C -> CmmGraph)
-> State DetUniqFM Label
-> State DetUniqFM (Graph' LabelMap Block CmmNode C C -> CmmGraph)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Label -> State DetUniqFM Label
detRenameLabel Label
entry State DetUniqFM (Graph' LabelMap Block CmmNode C C -> CmmGraph)
-> State DetUniqFM (Graph' LabelMap Block CmmNode C C)
-> DetRnM CmmGraph
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Graph' DWrap Block CmmNode C C
-> State DetUniqFM (Graph' LabelMap Block CmmNode C C)
forall {e :: Extensibility} {x :: Extensibility}.
Graph' DWrap Block CmmNode e x
-> State DetUniqFM (Graph' LabelMap Block CmmNode e x)
detRenameGraph Graph' DWrap Block CmmNode C C
bs

    detRenameGraph :: Graph' DWrap Block CmmNode e x
-> State DetUniqFM (Graph' LabelMap Block CmmNode e x)
detRenameGraph = \case
      Graph' DWrap Block CmmNode e x
GNil  -> Graph' LabelMap Block CmmNode 'Open 'Open
-> State DetUniqFM (Graph' LabelMap Block CmmNode 'Open 'Open)
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Graph' LabelMap Block CmmNode 'Open 'Open
forall (s :: * -> *)
       (block :: (Extensibility -> Extensibility -> *)
                 -> Extensibility -> Extensibility -> *)
       (n :: Extensibility -> Extensibility -> *).
Graph' s block n 'Open 'Open
GNil
      GUnit Block CmmNode 'Open 'Open
block -> Block CmmNode 'Open 'Open
-> Graph' LabelMap Block CmmNode 'Open 'Open
forall (block :: (Extensibility -> Extensibility -> *)
                 -> Extensibility -> Extensibility -> *)
       (n :: Extensibility -> Extensibility -> *) (s :: * -> *).
block n 'Open 'Open -> Graph' s block n 'Open 'Open
GUnit (Block CmmNode 'Open 'Open
 -> Graph' LabelMap Block CmmNode 'Open 'Open)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> State DetUniqFM (Graph' LabelMap Block CmmNode 'Open 'Open)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
block
      GMany MaybeO e (Block CmmNode 'Open C)
m1 Body' DWrap Block CmmNode
b MaybeO x (Block CmmNode C 'Open)
m2 -> MaybeO e (Block CmmNode 'Open C)
-> Body' LabelMap Block CmmNode
-> MaybeO x (Block CmmNode C 'Open)
-> Graph' LabelMap Block CmmNode e x
forall (e :: Extensibility)
       (block :: (Extensibility -> Extensibility -> *)
                 -> Extensibility -> Extensibility -> *)
       (n :: Extensibility -> Extensibility -> *) (s :: * -> *)
       (x :: Extensibility).
MaybeO e (block n 'Open C)
-> Body' s block n
-> MaybeO x (block n C 'Open)
-> Graph' s block n e x
GMany (MaybeO e (Block CmmNode 'Open C)
 -> Body' LabelMap Block CmmNode
 -> MaybeO x (Block CmmNode C 'Open)
 -> Graph' LabelMap Block CmmNode e x)
-> State DetUniqFM (MaybeO e (Block CmmNode 'Open C))
-> State
     DetUniqFM
     (Body' LabelMap Block CmmNode
      -> MaybeO x (Block CmmNode C 'Open)
      -> Graph' LabelMap Block CmmNode e x)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> MaybeO e (Block CmmNode 'Open C)
-> State DetUniqFM (MaybeO e (Block CmmNode 'Open C))
forall (n :: Extensibility) (a :: Extensibility)
       (b :: Extensibility).
MaybeO n (Block CmmNode a b)
-> DetRnM (MaybeO n (Block CmmNode a b))
detRenameMaybeBlock MaybeO e (Block CmmNode 'Open C)
m1 State
  DetUniqFM
  (Body' LabelMap Block CmmNode
   -> MaybeO x (Block CmmNode C 'Open)
   -> Graph' LabelMap Block CmmNode e x)
-> State DetUniqFM (Body' LabelMap Block CmmNode)
-> State
     DetUniqFM
     (MaybeO x (Block CmmNode C 'Open)
      -> Graph' LabelMap Block CmmNode e x)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Body' DWrap Block CmmNode
-> State DetUniqFM (Body' LabelMap Block CmmNode)
forall {n :: Extensibility} {m :: Extensibility}.
DWrap (Block CmmNode n m)
-> State DetUniqFM (LabelMap (Block CmmNode n m))
detRenameBody Body' DWrap Block CmmNode
b State
  DetUniqFM
  (MaybeO x (Block CmmNode C 'Open)
   -> Graph' LabelMap Block CmmNode e x)
-> State DetUniqFM (MaybeO x (Block CmmNode C 'Open))
-> State DetUniqFM (Graph' LabelMap Block CmmNode e x)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> MaybeO x (Block CmmNode C 'Open)
-> State DetUniqFM (MaybeO x (Block CmmNode C 'Open))
forall (n :: Extensibility) (a :: Extensibility)
       (b :: Extensibility).
MaybeO n (Block CmmNode a b)
-> DetRnM (MaybeO n (Block CmmNode a b))
detRenameMaybeBlock MaybeO x (Block CmmNode C 'Open)
m2

    detRenameBody :: DWrap (Block CmmNode n m)
-> State DetUniqFM (LabelMap (Block CmmNode n m))
detRenameBody (DWrap [(Label, Block CmmNode n m)]
b)
      = [(Label, Block CmmNode n m)] -> LabelMap (Block CmmNode n m)
forall v. [(Label, v)] -> LabelMap v
mapFromList ([(Label, Block CmmNode n m)] -> LabelMap (Block CmmNode n m))
-> State DetUniqFM [(Label, Block CmmNode n m)]
-> State DetUniqFM (LabelMap (Block CmmNode n m))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Label, Block CmmNode n m)
 -> State DetUniqFM (Label, Block CmmNode n m))
-> [(Label, Block CmmNode n m)]
-> State DetUniqFM [(Label, Block CmmNode n m)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((Label -> State DetUniqFM Label)
-> (Block CmmNode n m -> State DetUniqFM (Block CmmNode n m))
-> (Label, Block CmmNode n m)
-> State DetUniqFM (Label, Block CmmNode n m)
forall {f :: * -> *} {t} {a} {t} {a}.
Applicative f =>
(t -> f a) -> (t -> f a) -> (t, t) -> f (a, a)
detRenamePair Label -> State DetUniqFM Label
detRenameLabel Block CmmNode n m -> State DetUniqFM (Block CmmNode n m)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock) [(Label, Block CmmNode n m)]
b

    detRenameCmmStatics :: CmmStatics -> DetRnM CmmStatics
    detRenameCmmStatics :: CmmStatics -> State DetUniqFM CmmStatics
detRenameCmmStatics
      (CmmStatics CLabel
clbl CmmInfoTable
info CostCentreStack
ccs [CmmLit]
lits1 [CmmLit]
lits2)
        = CLabel
-> CmmInfoTable
-> CostCentreStack
-> [CmmLit]
-> [CmmLit]
-> CmmStatics
CmmStatics (CLabel
 -> CmmInfoTable
 -> CostCentreStack
 -> [CmmLit]
 -> [CmmLit]
 -> CmmStatics)
-> DetRnM CLabel
-> State
     DetUniqFM
     (CmmInfoTable
      -> CostCentreStack -> [CmmLit] -> [CmmLit] -> CmmStatics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
clbl State
  DetUniqFM
  (CmmInfoTable
   -> CostCentreStack -> [CmmLit] -> [CmmLit] -> CmmStatics)
-> State DetUniqFM CmmInfoTable
-> State
     DetUniqFM (CostCentreStack -> [CmmLit] -> [CmmLit] -> CmmStatics)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmInfoTable -> State DetUniqFM CmmInfoTable
detRenameCmmInfoTable CmmInfoTable
info State
  DetUniqFM (CostCentreStack -> [CmmLit] -> [CmmLit] -> CmmStatics)
-> State DetUniqFM CostCentreStack
-> State DetUniqFM ([CmmLit] -> [CmmLit] -> CmmStatics)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CostCentreStack -> State DetUniqFM CostCentreStack
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CostCentreStack
ccs State DetUniqFM ([CmmLit] -> [CmmLit] -> CmmStatics)
-> State DetUniqFM [CmmLit]
-> State DetUniqFM ([CmmLit] -> CmmStatics)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmLit -> State DetUniqFM CmmLit)
-> [CmmLit] -> State DetUniqFM [CmmLit]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit [CmmLit]
lits1 State DetUniqFM ([CmmLit] -> CmmStatics)
-> State DetUniqFM [CmmLit] -> State DetUniqFM CmmStatics
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmLit -> State DetUniqFM CmmLit)
-> [CmmLit] -> State DetUniqFM [CmmLit]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit [CmmLit]
lits2
    detRenameCmmStatics
      (CmmStaticsRaw CLabel
lbl [CmmStatic]
sts)
        = CLabel -> [CmmStatic] -> CmmStatics
forall (rawOnly :: Bool).
CLabel -> [CmmStatic] -> GenCmmStatics rawOnly
CmmStaticsRaw (CLabel -> [CmmStatic] -> CmmStatics)
-> DetRnM CLabel -> State DetUniqFM ([CmmStatic] -> CmmStatics)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl State DetUniqFM ([CmmStatic] -> CmmStatics)
-> State DetUniqFM [CmmStatic] -> State DetUniqFM CmmStatics
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmStatic -> State DetUniqFM CmmStatic)
-> [CmmStatic] -> State DetUniqFM [CmmStatic]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmStatic -> State DetUniqFM CmmStatic
detRenameCmmStatic [CmmStatic]
sts

    detRenameCmmInfoTable :: CmmInfoTable -> DetRnM CmmInfoTable
    detRenameCmmInfoTable :: CmmInfoTable -> State DetUniqFM CmmInfoTable
detRenameCmmInfoTable
      CmmInfoTable{CLabel
cit_lbl :: CLabel
cit_lbl :: CmmInfoTable -> CLabel
cit_lbl, SMRep
cit_rep :: SMRep
cit_rep :: CmmInfoTable -> SMRep
cit_rep, ProfilingInfo
cit_prof :: ProfilingInfo
cit_prof :: CmmInfoTable -> ProfilingInfo
cit_prof, Maybe CLabel
cit_srt :: Maybe CLabel
cit_srt :: CmmInfoTable -> Maybe CLabel
cit_srt, Maybe (Id, CostCentreStack)
cit_clo :: Maybe (Id, CostCentreStack)
cit_clo :: CmmInfoTable -> Maybe (Id, CostCentreStack)
cit_clo}
        = CLabel
-> SMRep
-> ProfilingInfo
-> Maybe CLabel
-> Maybe (Id, CostCentreStack)
-> CmmInfoTable
CmmInfoTable (CLabel
 -> SMRep
 -> ProfilingInfo
 -> Maybe CLabel
 -> Maybe (Id, CostCentreStack)
 -> CmmInfoTable)
-> DetRnM CLabel
-> State
     DetUniqFM
     (SMRep
      -> ProfilingInfo
      -> Maybe CLabel
      -> Maybe (Id, CostCentreStack)
      -> CmmInfoTable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
cit_lbl State
  DetUniqFM
  (SMRep
   -> ProfilingInfo
   -> Maybe CLabel
   -> Maybe (Id, CostCentreStack)
   -> CmmInfoTable)
-> State DetUniqFM SMRep
-> State
     DetUniqFM
     (ProfilingInfo
      -> Maybe CLabel -> Maybe (Id, CostCentreStack) -> CmmInfoTable)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> SMRep -> State DetUniqFM SMRep
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure SMRep
cit_rep State
  DetUniqFM
  (ProfilingInfo
   -> Maybe CLabel -> Maybe (Id, CostCentreStack) -> CmmInfoTable)
-> State DetUniqFM ProfilingInfo
-> State
     DetUniqFM
     (Maybe CLabel -> Maybe (Id, CostCentreStack) -> CmmInfoTable)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ProfilingInfo -> State DetUniqFM ProfilingInfo
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ProfilingInfo
cit_prof State
  DetUniqFM
  (Maybe CLabel -> Maybe (Id, CostCentreStack) -> CmmInfoTable)
-> State DetUniqFM (Maybe CLabel)
-> State DetUniqFM (Maybe (Id, CostCentreStack) -> CmmInfoTable)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CLabel -> DetRnM CLabel)
-> Maybe CLabel -> State DetUniqFM (Maybe CLabel)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(t -> f a) -> Maybe t -> f (Maybe a)
detRenameMaybe CLabel -> DetRnM CLabel
detRenameCLabel Maybe CLabel
cit_srt State DetUniqFM (Maybe (Id, CostCentreStack) -> CmmInfoTable)
-> State DetUniqFM (Maybe (Id, CostCentreStack))
-> State DetUniqFM CmmInfoTable
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*>
           (case Maybe (Id, CostCentreStack)
cit_clo of
              Maybe (Id, CostCentreStack)
Nothing -> Maybe (Id, CostCentreStack)
-> State DetUniqFM (Maybe (Id, CostCentreStack))
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe (Id, CostCentreStack)
forall a. Maybe a
Nothing
              Just (Id
an_id, CostCentreStack
ccs) -> (Id, CostCentreStack) -> Maybe (Id, CostCentreStack)
forall a. a -> Maybe a
Just ((Id, CostCentreStack) -> Maybe (Id, CostCentreStack))
-> (Id -> (Id, CostCentreStack))
-> Id
-> Maybe (Id, CostCentreStack)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (,CostCentreStack
ccs) (Id -> Maybe (Id, CostCentreStack))
-> DetRnM Id -> State DetUniqFM (Maybe (Id, CostCentreStack))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Id -> DetRnM Id
detRenameId Id
an_id)

    detRenameCmmStatic :: CmmStatic -> DetRnM CmmStatic
    detRenameCmmStatic :: CmmStatic -> State DetUniqFM CmmStatic
detRenameCmmStatic = \case
      CmmStaticLit CmmLit
l -> CmmLit -> CmmStatic
CmmStaticLit (CmmLit -> CmmStatic)
-> State DetUniqFM CmmLit -> State DetUniqFM CmmStatic
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit CmmLit
l
      CmmUninitialised Int
x -> CmmStatic -> State DetUniqFM CmmStatic
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmStatic -> State DetUniqFM CmmStatic)
-> CmmStatic -> State DetUniqFM CmmStatic
forall a b. (a -> b) -> a -> b
$ Int -> CmmStatic
CmmUninitialised Int
x
      CmmString ByteString
x -> CmmStatic -> State DetUniqFM CmmStatic
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmStatic -> State DetUniqFM CmmStatic)
-> CmmStatic -> State DetUniqFM CmmStatic
forall a b. (a -> b) -> a -> b
$ ByteString -> CmmStatic
CmmString ByteString
x
      CmmFileEmbed String
f Int
i -> CmmStatic -> State DetUniqFM CmmStatic
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmStatic -> State DetUniqFM CmmStatic)
-> CmmStatic -> State DetUniqFM CmmStatic
forall a b. (a -> b) -> a -> b
$ String -> Int -> CmmStatic
CmmFileEmbed String
f Int
i

    detRenameCmmLit :: CmmLit -> DetRnM CmmLit
    detRenameCmmLit :: CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit = \case
      CmmInt Integer
i Width
w -> CmmLit -> State DetUniqFM CmmLit
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmLit -> State DetUniqFM CmmLit)
-> CmmLit -> State DetUniqFM CmmLit
forall a b. (a -> b) -> a -> b
$ Integer -> Width -> CmmLit
CmmInt Integer
i Width
w
      CmmFloat Rational
r Width
w -> CmmLit -> State DetUniqFM CmmLit
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmLit -> State DetUniqFM CmmLit)
-> CmmLit -> State DetUniqFM CmmLit
forall a b. (a -> b) -> a -> b
$ Rational -> Width -> CmmLit
CmmFloat Rational
r Width
w
      CmmVec [CmmLit]
lits -> [CmmLit] -> CmmLit
CmmVec ([CmmLit] -> CmmLit)
-> State DetUniqFM [CmmLit] -> State DetUniqFM CmmLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CmmLit -> State DetUniqFM CmmLit)
-> [CmmLit] -> State DetUniqFM [CmmLit]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit [CmmLit]
lits
      CmmLabel CLabel
lbl -> CLabel -> CmmLit
CmmLabel (CLabel -> CmmLit) -> DetRnM CLabel -> State DetUniqFM CmmLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl
      CmmLabelOff CLabel
lbl Int
i -> CLabel -> Int -> CmmLit
CmmLabelOff (CLabel -> Int -> CmmLit)
-> DetRnM CLabel -> State DetUniqFM (Int -> CmmLit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl State DetUniqFM (Int -> CmmLit)
-> State DetUniqFM Int -> State DetUniqFM CmmLit
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i
      CmmLabelDiffOff CLabel
lbl1 CLabel
lbl2 Int
i Width
w ->
        CLabel -> CLabel -> Int -> Width -> CmmLit
CmmLabelDiffOff (CLabel -> CLabel -> Int -> Width -> CmmLit)
-> DetRnM CLabel
-> State DetUniqFM (CLabel -> Int -> Width -> CmmLit)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl1 State DetUniqFM (CLabel -> Int -> Width -> CmmLit)
-> DetRnM CLabel -> State DetUniqFM (Int -> Width -> CmmLit)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl2 State DetUniqFM (Int -> Width -> CmmLit)
-> State DetUniqFM Int -> State DetUniqFM (Width -> CmmLit)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i State DetUniqFM (Width -> CmmLit)
-> State DetUniqFM Width -> State DetUniqFM CmmLit
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Width -> State DetUniqFM Width
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Width
w
      CmmBlock Label
bid -> Label -> CmmLit
CmmBlock (Label -> CmmLit)
-> State DetUniqFM Label -> State DetUniqFM CmmLit
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Label -> State DetUniqFM Label
detRenameLabel Label
bid
      CmmLit
CmmHighStackMark -> CmmLit -> State DetUniqFM CmmLit
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CmmLit
CmmHighStackMark

    detRenameMaybeBlock :: MaybeO n (Block CmmNode a b) -> DetRnM (MaybeO n (Block CmmNode a b))
    detRenameMaybeBlock :: forall (n :: Extensibility) (a :: Extensibility)
       (b :: Extensibility).
MaybeO n (Block CmmNode a b)
-> DetRnM (MaybeO n (Block CmmNode a b))
detRenameMaybeBlock (JustO Block CmmNode a b
x) = Block CmmNode a b -> MaybeO n (Block CmmNode a b)
Block CmmNode a b -> MaybeO 'Open (Block CmmNode a b)
forall t. t -> MaybeO 'Open t
JustO (Block CmmNode a b -> MaybeO n (Block CmmNode a b))
-> State DetUniqFM (Block CmmNode a b)
-> State DetUniqFM (MaybeO n (Block CmmNode a b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Block CmmNode a b -> State DetUniqFM (Block CmmNode a b)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode a b
x
    detRenameMaybeBlock MaybeO n (Block CmmNode a b)
NothingO = MaybeO n (Block CmmNode a b)
-> State DetUniqFM (MaybeO n (Block CmmNode a b))
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure MaybeO n (Block CmmNode a b)
MaybeO C (Block CmmNode a b)
forall t. MaybeO C t
NothingO

    detRenameBlock :: Block CmmNode n m -> DetRnM (Block CmmNode n m)
    detRenameBlock :: forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock = \case
      BlockCO CmmNode C 'Open
n Block CmmNode 'Open 'Open
bn -> CmmNode C 'Open -> Block CmmNode 'Open 'Open -> Block CmmNode n m
CmmNode C 'Open
-> Block CmmNode 'Open 'Open -> Block CmmNode C 'Open
forall (n :: Extensibility -> Extensibility -> *).
n C 'Open -> Block n 'Open 'Open -> Block n C 'Open
BlockCO (CmmNode C 'Open -> Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (CmmNode C 'Open)
-> State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmNode C 'Open -> State DetUniqFM (CmmNode C 'Open)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode C 'Open
n State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
bn
      BlockCC CmmNode C 'Open
n1 Block CmmNode 'Open 'Open
bn CmmNode 'Open C
n2 -> CmmNode C 'Open
-> Block CmmNode 'Open 'Open
-> CmmNode 'Open C
-> Block CmmNode n m
CmmNode C 'Open
-> Block CmmNode 'Open 'Open
-> CmmNode 'Open C
-> Block CmmNode C C
forall (n :: Extensibility -> Extensibility -> *).
n C 'Open -> Block n 'Open 'Open -> n 'Open C -> Block n C C
BlockCC (CmmNode C 'Open
 -> Block CmmNode 'Open 'Open
 -> CmmNode 'Open C
 -> Block CmmNode n m)
-> State DetUniqFM (CmmNode C 'Open)
-> State
     DetUniqFM
     (Block CmmNode 'Open 'Open -> CmmNode 'Open C -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmNode C 'Open -> State DetUniqFM (CmmNode C 'Open)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode C 'Open
n1 State
  DetUniqFM
  (Block CmmNode 'Open 'Open -> CmmNode 'Open C -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> State DetUniqFM (CmmNode 'Open C -> Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
bn State DetUniqFM (CmmNode 'Open C -> Block CmmNode n m)
-> State DetUniqFM (CmmNode 'Open C) -> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmNode 'Open C -> State DetUniqFM (CmmNode 'Open C)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode 'Open C
n2
      BlockOC Block CmmNode 'Open 'Open
bn CmmNode 'Open C
n -> Block CmmNode 'Open 'Open -> CmmNode 'Open C -> Block CmmNode n m
Block CmmNode 'Open 'Open
-> CmmNode 'Open C -> Block CmmNode 'Open C
forall (n :: Extensibility -> Extensibility -> *).
Block n 'Open 'Open -> n 'Open C -> Block n 'Open C
BlockOC (Block CmmNode 'Open 'Open -> CmmNode 'Open C -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> State DetUniqFM (CmmNode 'Open C -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
bn State DetUniqFM (CmmNode 'Open C -> Block CmmNode n m)
-> State DetUniqFM (CmmNode 'Open C) -> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmNode 'Open C -> State DetUniqFM (CmmNode 'Open C)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode 'Open C
n
      Block CmmNode n m
BNil    -> Block CmmNode n m -> DetRnM (Block CmmNode n m)
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Block CmmNode n m
Block CmmNode 'Open 'Open
forall (n :: Extensibility -> Extensibility -> *).
Block n 'Open 'Open
BNil
      BMiddle CmmNode 'Open 'Open
n -> CmmNode 'Open 'Open -> Block CmmNode n m
CmmNode 'Open 'Open -> Block CmmNode 'Open 'Open
forall (n :: Extensibility -> Extensibility -> *).
n 'Open 'Open -> Block n 'Open 'Open
BMiddle (CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (CmmNode 'Open 'Open)
-> DetRnM (Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode 'Open 'Open
n
      BCat    Block CmmNode 'Open 'Open
b1 Block CmmNode 'Open 'Open
b2 -> Block CmmNode 'Open 'Open
-> Block CmmNode 'Open 'Open -> Block CmmNode n m
Block CmmNode 'Open 'Open
-> Block CmmNode 'Open 'Open -> Block CmmNode 'Open 'Open
forall (n :: Extensibility -> Extensibility -> *).
Block n 'Open 'Open -> Block n 'Open 'Open -> Block n 'Open 'Open
BCat (Block CmmNode 'Open 'Open
 -> Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
b1 State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
b2
      BSnoc   Block CmmNode 'Open 'Open
bn CmmNode 'Open 'Open
n -> Block CmmNode 'Open 'Open
-> CmmNode 'Open 'Open -> Block CmmNode n m
Block CmmNode 'Open 'Open
-> CmmNode 'Open 'Open -> Block CmmNode 'Open 'Open
forall (n :: Extensibility -> Extensibility -> *).
Block n 'Open 'Open -> n 'Open 'Open -> Block n 'Open 'Open
BSnoc (Block CmmNode 'Open 'Open
 -> CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> State DetUniqFM (CmmNode 'Open 'Open -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
bn State DetUniqFM (CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (CmmNode 'Open 'Open)
-> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode 'Open 'Open
n
      BCons   CmmNode 'Open 'Open
n Block CmmNode 'Open 'Open
bn -> CmmNode 'Open 'Open
-> Block CmmNode 'Open 'Open -> Block CmmNode n m
CmmNode 'Open 'Open
-> Block CmmNode 'Open 'Open -> Block CmmNode 'Open 'Open
forall (n :: Extensibility -> Extensibility -> *).
n 'Open 'Open -> Block n 'Open 'Open -> Block n 'Open 'Open
BCons (CmmNode 'Open 'Open
 -> Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (CmmNode 'Open 'Open)
-> State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode CmmNode 'Open 'Open
n State DetUniqFM (Block CmmNode 'Open 'Open -> Block CmmNode n m)
-> State DetUniqFM (Block CmmNode 'Open 'Open)
-> DetRnM (Block CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Block CmmNode 'Open 'Open
-> State DetUniqFM (Block CmmNode 'Open 'Open)
forall (n :: Extensibility) (m :: Extensibility).
Block CmmNode n m -> DetRnM (Block CmmNode n m)
detRenameBlock Block CmmNode 'Open 'Open
bn

    detRenameCmmNode :: CmmNode n m -> DetRnM (CmmNode n m)
    detRenameCmmNode :: forall (n :: Extensibility) (m :: Extensibility).
CmmNode n m -> DetRnM (CmmNode n m)
detRenameCmmNode = \case
      CmmEntry Label
l CmmTickScope
t -> Label -> CmmTickScope -> CmmNode n m
Label -> CmmTickScope -> CmmNode C 'Open
CmmEntry (Label -> CmmTickScope -> CmmNode n m)
-> State DetUniqFM Label
-> State DetUniqFM (CmmTickScope -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Label -> State DetUniqFM Label
detRenameLabel Label
l State DetUniqFM (CmmTickScope -> CmmNode n m)
-> State DetUniqFM CmmTickScope -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmTickScope -> State DetUniqFM CmmTickScope
detRenameCmmTick CmmTickScope
t
      CmmComment FastString
fs -> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open))
-> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall a b. (a -> b) -> a -> b
$ FastString -> CmmNode 'Open 'Open
CmmComment FastString
fs
      CmmTick CmmTickish
tickish -> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open))
-> CmmNode 'Open 'Open -> State DetUniqFM (CmmNode 'Open 'Open)
forall a b. (a -> b) -> a -> b
$ CmmTickish -> CmmNode 'Open 'Open
CmmTick CmmTickish
tickish
      CmmUnwind [(GlobalReg, Maybe CmmExpr)]
xs -> [(GlobalReg, Maybe CmmExpr)] -> CmmNode n m
[(GlobalReg, Maybe CmmExpr)] -> CmmNode 'Open 'Open
CmmUnwind ([(GlobalReg, Maybe CmmExpr)] -> CmmNode n m)
-> State DetUniqFM [(GlobalReg, Maybe CmmExpr)]
-> DetRnM (CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((GlobalReg, Maybe CmmExpr)
 -> State DetUniqFM (GlobalReg, Maybe CmmExpr))
-> [(GlobalReg, Maybe CmmExpr)]
-> State DetUniqFM [(GlobalReg, Maybe CmmExpr)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((GlobalReg -> State DetUniqFM GlobalReg)
-> (Maybe CmmExpr -> State DetUniqFM (Maybe CmmExpr))
-> (GlobalReg, Maybe CmmExpr)
-> State DetUniqFM (GlobalReg, Maybe CmmExpr)
forall {f :: * -> *} {t} {a} {t} {a}.
Applicative f =>
(t -> f a) -> (t -> f a) -> (t, t) -> f (a, a)
detRenamePair GlobalReg -> State DetUniqFM GlobalReg
detRenameGlobalReg ((CmmExpr -> State DetUniqFM CmmExpr)
-> Maybe CmmExpr -> State DetUniqFM (Maybe CmmExpr)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(t -> f a) -> Maybe t -> f (Maybe a)
detRenameMaybe CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr)) [(GlobalReg, Maybe CmmExpr)]
xs
      CmmAssign CmmReg
reg CmmExpr
e -> CmmReg -> CmmExpr -> CmmNode n m
CmmReg -> CmmExpr -> CmmNode 'Open 'Open
CmmAssign (CmmReg -> CmmExpr -> CmmNode n m)
-> State DetUniqFM CmmReg
-> State DetUniqFM (CmmExpr -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmReg -> State DetUniqFM CmmReg
detRenameCmmReg CmmReg
reg State DetUniqFM (CmmExpr -> CmmNode n m)
-> State DetUniqFM CmmExpr -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e
      CmmStore CmmExpr
e1 CmmExpr
e2 AlignmentSpec
align -> CmmExpr -> CmmExpr -> AlignmentSpec -> CmmNode n m
CmmExpr -> CmmExpr -> AlignmentSpec -> CmmNode 'Open 'Open
CmmStore (CmmExpr -> CmmExpr -> AlignmentSpec -> CmmNode n m)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (CmmExpr -> AlignmentSpec -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e1 State DetUniqFM (CmmExpr -> AlignmentSpec -> CmmNode n m)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (AlignmentSpec -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e2 State DetUniqFM (AlignmentSpec -> CmmNode n m)
-> State DetUniqFM AlignmentSpec -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AlignmentSpec -> State DetUniqFM AlignmentSpec
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AlignmentSpec
align
      CmmUnsafeForeignCall ForeignTarget
ftgt [CmmFormal]
cmmformal [CmmExpr]
cmmactual ->
        ForeignTarget -> [CmmFormal] -> [CmmExpr] -> CmmNode n m
ForeignTarget -> [CmmFormal] -> [CmmExpr] -> CmmNode 'Open 'Open
CmmUnsafeForeignCall (ForeignTarget -> [CmmFormal] -> [CmmExpr] -> CmmNode n m)
-> State DetUniqFM ForeignTarget
-> State DetUniqFM ([CmmFormal] -> [CmmExpr] -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ForeignTarget -> State DetUniqFM ForeignTarget
detRenameForeignTarget ForeignTarget
ftgt State DetUniqFM ([CmmFormal] -> [CmmExpr] -> CmmNode n m)
-> State DetUniqFM [CmmFormal]
-> State DetUniqFM ([CmmExpr] -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmFormal -> State DetUniqFM CmmFormal)
-> [CmmFormal] -> State DetUniqFM [CmmFormal]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmFormal -> State DetUniqFM CmmFormal
detRenameLocalReg [CmmFormal]
cmmformal State DetUniqFM ([CmmExpr] -> CmmNode n m)
-> State DetUniqFM [CmmExpr] -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmExpr -> State DetUniqFM CmmExpr)
-> [CmmExpr] -> State DetUniqFM [CmmExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr [CmmExpr]
cmmactual
      CmmBranch Label
l -> Label -> CmmNode n m
Label -> CmmNode 'Open C
CmmBranch (Label -> CmmNode n m)
-> State DetUniqFM Label -> DetRnM (CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Label -> State DetUniqFM Label
detRenameLabel Label
l
      CmmCondBranch CmmExpr
pred Label
t Label
f Maybe Bool
likely ->
        CmmExpr -> Label -> Label -> Maybe Bool -> CmmNode n m
CmmExpr -> Label -> Label -> Maybe Bool -> CmmNode 'Open C
CmmCondBranch (CmmExpr -> Label -> Label -> Maybe Bool -> CmmNode n m)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (Label -> Label -> Maybe Bool -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
pred State DetUniqFM (Label -> Label -> Maybe Bool -> CmmNode n m)
-> State DetUniqFM Label
-> State DetUniqFM (Label -> Maybe Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Label -> State DetUniqFM Label
detRenameLabel Label
t State DetUniqFM (Label -> Maybe Bool -> CmmNode n m)
-> State DetUniqFM Label
-> State DetUniqFM (Maybe Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Label -> State DetUniqFM Label
detRenameLabel Label
f State DetUniqFM (Maybe Bool -> CmmNode n m)
-> State DetUniqFM (Maybe Bool) -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Maybe Bool -> State DetUniqFM (Maybe Bool)
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Bool
likely
      CmmSwitch CmmExpr
e SwitchTargets
sts -> CmmExpr -> SwitchTargets -> CmmNode n m
CmmExpr -> SwitchTargets -> CmmNode 'Open C
CmmSwitch (CmmExpr -> SwitchTargets -> CmmNode n m)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (SwitchTargets -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e State DetUniqFM (SwitchTargets -> CmmNode n m)
-> State DetUniqFM SwitchTargets -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Label -> State DetUniqFM Label)
-> SwitchTargets -> State DetUniqFM SwitchTargets
forall (m :: * -> *).
Applicative m =>
(Label -> m Label) -> SwitchTargets -> m SwitchTargets
mapSwitchTargetsA Label -> State DetUniqFM Label
detRenameLabel SwitchTargets
sts
      CmmCall CmmExpr
tgt Maybe Label
cont [GlobalRegUse]
regs Int
args Int
retargs Int
retoff ->
        CmmExpr
-> Maybe Label
-> [GlobalRegUse]
-> Int
-> Int
-> Int
-> CmmNode n m
CmmExpr
-> Maybe Label
-> [GlobalRegUse]
-> Int
-> Int
-> Int
-> CmmNode 'Open C
CmmCall (CmmExpr
 -> Maybe Label
 -> [GlobalRegUse]
 -> Int
 -> Int
 -> Int
 -> CmmNode n m)
-> State DetUniqFM CmmExpr
-> State
     DetUniqFM
     (Maybe Label -> [GlobalRegUse] -> Int -> Int -> Int -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
tgt State
  DetUniqFM
  (Maybe Label -> [GlobalRegUse] -> Int -> Int -> Int -> CmmNode n m)
-> State DetUniqFM (Maybe Label)
-> State
     DetUniqFM ([GlobalRegUse] -> Int -> Int -> Int -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (Label -> State DetUniqFM Label)
-> Maybe Label -> State DetUniqFM (Maybe Label)
forall {f :: * -> *} {t} {a}.
Applicative f =>
(t -> f a) -> Maybe t -> f (Maybe a)
detRenameMaybe Label -> State DetUniqFM Label
detRenameLabel Maybe Label
cont State
  DetUniqFM ([GlobalRegUse] -> Int -> Int -> Int -> CmmNode n m)
-> State DetUniqFM [GlobalRegUse]
-> State DetUniqFM (Int -> Int -> Int -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (GlobalRegUse -> State DetUniqFM GlobalRegUse)
-> [GlobalRegUse] -> State DetUniqFM [GlobalRegUse]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM GlobalRegUse -> State DetUniqFM GlobalRegUse
detRenameGlobalRegUse [GlobalRegUse]
regs
                State DetUniqFM (Int -> Int -> Int -> CmmNode n m)
-> State DetUniqFM Int
-> State DetUniqFM (Int -> Int -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
args State DetUniqFM (Int -> Int -> CmmNode n m)
-> State DetUniqFM Int -> State DetUniqFM (Int -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
retargs State DetUniqFM (Int -> CmmNode n m)
-> State DetUniqFM Int -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
retoff
      CmmForeignCall ForeignTarget
tgt [CmmFormal]
res [CmmExpr]
args Label
succ Int
retargs Int
retoff Bool
intrbl ->
        ForeignTarget
-> [CmmFormal]
-> [CmmExpr]
-> Label
-> Int
-> Int
-> Bool
-> CmmNode n m
ForeignTarget
-> [CmmFormal]
-> [CmmExpr]
-> Label
-> Int
-> Int
-> Bool
-> CmmNode 'Open C
CmmForeignCall (ForeignTarget
 -> [CmmFormal]
 -> [CmmExpr]
 -> Label
 -> Int
 -> Int
 -> Bool
 -> CmmNode n m)
-> State DetUniqFM ForeignTarget
-> State
     DetUniqFM
     ([CmmFormal]
      -> [CmmExpr] -> Label -> Int -> Int -> Bool -> CmmNode n m)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ForeignTarget -> State DetUniqFM ForeignTarget
detRenameForeignTarget ForeignTarget
tgt State
  DetUniqFM
  ([CmmFormal]
   -> [CmmExpr] -> Label -> Int -> Int -> Bool -> CmmNode n m)
-> State DetUniqFM [CmmFormal]
-> State
     DetUniqFM ([CmmExpr] -> Label -> Int -> Int -> Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmFormal -> State DetUniqFM CmmFormal)
-> [CmmFormal] -> State DetUniqFM [CmmFormal]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmFormal -> State DetUniqFM CmmFormal
detRenameLocalReg [CmmFormal]
res State
  DetUniqFM ([CmmExpr] -> Label -> Int -> Int -> Bool -> CmmNode n m)
-> State DetUniqFM [CmmExpr]
-> State DetUniqFM (Label -> Int -> Int -> Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> (CmmExpr -> State DetUniqFM CmmExpr)
-> [CmmExpr] -> State DetUniqFM [CmmExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr [CmmExpr]
args
                       State DetUniqFM (Label -> Int -> Int -> Bool -> CmmNode n m)
-> State DetUniqFM Label
-> State DetUniqFM (Int -> Int -> Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Label -> State DetUniqFM Label
detRenameLabel Label
succ State DetUniqFM (Int -> Int -> Bool -> CmmNode n m)
-> State DetUniqFM Int
-> State DetUniqFM (Int -> Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
retargs State DetUniqFM (Int -> Bool -> CmmNode n m)
-> State DetUniqFM Int -> State DetUniqFM (Bool -> CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
retoff State DetUniqFM (Bool -> CmmNode n m)
-> State DetUniqFM Bool -> DetRnM (CmmNode n m)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Bool -> State DetUniqFM Bool
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Bool
intrbl

    detRenameCmmExpr :: CmmExpr -> DetRnM CmmExpr
    detRenameCmmExpr :: CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr = \case
      CmmLit CmmLit
l -> CmmLit -> CmmExpr
CmmLit (CmmLit -> CmmExpr)
-> State DetUniqFM CmmLit -> State DetUniqFM CmmExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmLit -> State DetUniqFM CmmLit
detRenameCmmLit CmmLit
l
      CmmLoad CmmExpr
e CmmType
t AlignmentSpec
a -> CmmExpr -> CmmType -> AlignmentSpec -> CmmExpr
CmmLoad (CmmExpr -> CmmType -> AlignmentSpec -> CmmExpr)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (CmmType -> AlignmentSpec -> CmmExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e State DetUniqFM (CmmType -> AlignmentSpec -> CmmExpr)
-> State DetUniqFM CmmType
-> State DetUniqFM (AlignmentSpec -> CmmExpr)
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmType -> State DetUniqFM CmmType
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CmmType
t State DetUniqFM (AlignmentSpec -> CmmExpr)
-> State DetUniqFM AlignmentSpec -> State DetUniqFM CmmExpr
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> AlignmentSpec -> State DetUniqFM AlignmentSpec
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure AlignmentSpec
a
      CmmReg CmmReg
r -> CmmReg -> CmmExpr
CmmReg (CmmReg -> CmmExpr)
-> State DetUniqFM CmmReg -> State DetUniqFM CmmExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmReg -> State DetUniqFM CmmReg
detRenameCmmReg CmmReg
r
      CmmMachOp MachOp
mop [CmmExpr]
es -> MachOp -> [CmmExpr] -> CmmExpr
CmmMachOp MachOp
mop ([CmmExpr] -> CmmExpr)
-> State DetUniqFM [CmmExpr] -> State DetUniqFM CmmExpr
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (CmmExpr -> State DetUniqFM CmmExpr)
-> [CmmExpr] -> State DetUniqFM [CmmExpr]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr [CmmExpr]
es
      CmmStackSlot Area
a Int
i -> Area -> Int -> CmmExpr
CmmStackSlot (Area -> Int -> CmmExpr)
-> State DetUniqFM Area -> State DetUniqFM (Int -> CmmExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Area -> State DetUniqFM Area
detRenameArea Area
a State DetUniqFM (Int -> CmmExpr)
-> State DetUniqFM Int -> State DetUniqFM CmmExpr
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i
      CmmRegOff CmmReg
r Int
i -> CmmReg -> Int -> CmmExpr
CmmRegOff (CmmReg -> Int -> CmmExpr)
-> State DetUniqFM CmmReg -> State DetUniqFM (Int -> CmmExpr)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmReg -> State DetUniqFM CmmReg
detRenameCmmReg CmmReg
r State DetUniqFM (Int -> CmmExpr)
-> State DetUniqFM Int -> State DetUniqFM CmmExpr
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Int -> State DetUniqFM Int
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Int
i

    detRenameForeignTarget :: ForeignTarget -> DetRnM ForeignTarget
    detRenameForeignTarget :: ForeignTarget -> State DetUniqFM ForeignTarget
detRenameForeignTarget = \case
        ForeignTarget CmmExpr
e ForeignConvention
fc -> CmmExpr -> ForeignConvention -> ForeignTarget
ForeignTarget (CmmExpr -> ForeignConvention -> ForeignTarget)
-> State DetUniqFM CmmExpr
-> State DetUniqFM (ForeignConvention -> ForeignTarget)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmExpr -> State DetUniqFM CmmExpr
detRenameCmmExpr CmmExpr
e State DetUniqFM (ForeignConvention -> ForeignTarget)
-> State DetUniqFM ForeignConvention
-> State DetUniqFM ForeignTarget
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> ForeignConvention -> State DetUniqFM ForeignConvention
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ForeignConvention
fc
        PrimTarget CallishMachOp
cmop -> ForeignTarget -> State DetUniqFM ForeignTarget
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (ForeignTarget -> State DetUniqFM ForeignTarget)
-> ForeignTarget -> State DetUniqFM ForeignTarget
forall a b. (a -> b) -> a -> b
$ CallishMachOp -> ForeignTarget
PrimTarget CallishMachOp
cmop

    detRenameArea :: Area -> DetRnM Area
    detRenameArea :: Area -> State DetUniqFM Area
detRenameArea Area
Old = Area -> State DetUniqFM Area
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Area
Old
    detRenameArea (Young Label
l) = Label -> Area
Young (Label -> Area) -> State DetUniqFM Label -> State DetUniqFM Area
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Label -> State DetUniqFM Label
detRenameLabel Label
l

    detRenameLabel :: Label -> DetRnM Label
    detRenameLabel :: Label -> State DetUniqFM Label
detRenameLabel Label
lbl
      = Word64 -> Label
mkHooplLabel (Word64 -> Label) -> (Unique -> Word64) -> Unique -> Label
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Unique -> Word64
getKey (Unique -> Label) -> DetRnM Unique -> State DetUniqFM Label
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Unique -> DetRnM Unique
renameDetUniq (Label -> Unique
forall a. Uniquable a => a -> Unique
getUnique Label
lbl)

    detRenameSection :: Section -> DetRnM Section
    detRenameSection :: Section -> State DetUniqFM Section
detRenameSection (Section SectionType
ty CLabel
lbl)
      = SectionType -> CLabel -> Section
Section SectionType
ty (CLabel -> Section) -> DetRnM CLabel -> State DetUniqFM Section
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CLabel -> DetRnM CLabel
detRenameCLabel CLabel
lbl

    detRenameCmmReg :: CmmReg -> DetRnM CmmReg
    detRenameCmmReg :: CmmReg -> State DetUniqFM CmmReg
detRenameCmmReg = \case
      CmmLocal CmmFormal
l -> CmmFormal -> CmmReg
CmmLocal (CmmFormal -> CmmReg)
-> State DetUniqFM CmmFormal -> State DetUniqFM CmmReg
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> CmmFormal -> State DetUniqFM CmmFormal
detRenameLocalReg CmmFormal
l
      CmmGlobal GlobalRegUse
x -> CmmReg -> State DetUniqFM CmmReg
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (CmmReg -> State DetUniqFM CmmReg)
-> CmmReg -> State DetUniqFM CmmReg
forall a b. (a -> b) -> a -> b
$ GlobalRegUse -> CmmReg
CmmGlobal GlobalRegUse
x

    detRenameLocalReg :: LocalReg -> DetRnM LocalReg
    detRenameLocalReg :: CmmFormal -> State DetUniqFM CmmFormal
detRenameLocalReg (LocalReg Unique
uq CmmType
t)
      = Unique -> CmmType -> CmmFormal
LocalReg (Unique -> CmmType -> CmmFormal)
-> DetRnM Unique -> State DetUniqFM (CmmType -> CmmFormal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Unique -> DetRnM Unique
renameDetUniq Unique
uq State DetUniqFM (CmmType -> CmmFormal)
-> State DetUniqFM CmmType -> State DetUniqFM CmmFormal
forall a b.
State DetUniqFM (a -> b) -> State DetUniqFM a -> State DetUniqFM b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> CmmType -> State DetUniqFM CmmType
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure CmmType
t

    -- Global registers don't need to be renamed.
    detRenameGlobalReg :: GlobalReg -> DetRnM GlobalReg
    detRenameGlobalReg :: GlobalReg -> State DetUniqFM GlobalReg
detRenameGlobalReg = GlobalReg -> State DetUniqFM GlobalReg
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    detRenameGlobalRegUse :: GlobalRegUse -> DetRnM GlobalRegUse
    detRenameGlobalRegUse :: GlobalRegUse -> State DetUniqFM GlobalRegUse
detRenameGlobalRegUse = GlobalRegUse -> State DetUniqFM GlobalRegUse
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

    -- todo: We may have to change this to get deterministic objects with ticks.
    detRenameCmmTick :: CmmTickScope -> DetRnM CmmTickScope
    detRenameCmmTick :: CmmTickScope -> State DetUniqFM CmmTickScope
detRenameCmmTick = CmmTickScope -> State DetUniqFM CmmTickScope
forall a. a -> State DetUniqFM a
forall (f :: * -> *) a. Applicative f => a -> f a
pure

    detRenameMaybe :: (t -> f a) -> Maybe t -> f (Maybe a)
detRenameMaybe t -> f a
_ Maybe t
Nothing = Maybe a -> f (Maybe a)
forall a. a -> f a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe a
forall a. Maybe a
Nothing
    detRenameMaybe t -> f a
f (Just t
x) = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> f a -> f (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> f a
f t
x

    detRenamePair :: (t -> f a) -> (t -> f a) -> (t, t) -> f (a, a)
detRenamePair t -> f a
f t -> f a
g (t
a, t
b) = (,) (a -> a -> (a, a)) -> f a -> f (a -> (a, a))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> t -> f a
f t
a f (a -> (a, a)) -> f a -> f (a, a)
forall a b. f (a -> b) -> f a -> f b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> t -> f a
g t
b

detRenameIPEMap :: DetUniqFM -> InfoTableProvMap -> (DetUniqFM, InfoTableProvMap)
detRenameIPEMap :: DetUniqFM -> InfoTableProvMap -> (DetUniqFM, InfoTableProvMap)
detRenameIPEMap DetUniqFM
dufm InfoTableProvMap{ DCMap
provDC :: DCMap
provDC :: InfoTableProvMap -> DCMap
provDC, ClosureMap
provClosure :: ClosureMap
provClosure :: InfoTableProvMap -> ClosureMap
provClosure, InfoTableToSourceLocationMap
provInfoTables :: InfoTableToSourceLocationMap
provInfoTables :: InfoTableProvMap -> InfoTableToSourceLocationMap
provInfoTables } =
    (DetUniqFM
dufm2, InfoTableProvMap { DCMap
provDC :: DCMap
provDC :: DCMap
provDC, provClosure :: ClosureMap
provClosure = ClosureMap
cm, InfoTableToSourceLocationMap
provInfoTables :: InfoTableToSourceLocationMap
provInfoTables :: InfoTableToSourceLocationMap
provInfoTables })
  where
    (ClosureMap
cm, DetUniqFM
dufm2) = State DetUniqFM ClosureMap -> DetUniqFM -> (ClosureMap, DetUniqFM)
forall s a. State s a -> s -> (a, s)
runState (ClosureMap -> State DetUniqFM ClosureMap
detRenameClosureMap ClosureMap
provClosure) DetUniqFM
dufm

    detRenameClosureMap :: ClosureMap -> DetRnM ClosureMap
    detRenameClosureMap :: ClosureMap -> State DetUniqFM ClosureMap
detRenameClosureMap ClosureMap
m =
      -- `eltsUDFM` preserves the deterministic order, but it doesn't matter
      -- since we will rename all uniques deterministically, thus the
      -- reconstructed map will necessarily be deterministic too.
      [(Name, (Name, (Type, Maybe IpeSourceLocation)))] -> ClosureMap
forall key elt. Uniquable key => [(key, elt)] -> UniqDFM key elt
listToUDFM ([(Name, (Name, (Type, Maybe IpeSourceLocation)))] -> ClosureMap)
-> State
     DetUniqFM [(Name, (Name, (Type, Maybe IpeSourceLocation)))]
-> State DetUniqFM ClosureMap
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Name, (Type, Maybe IpeSourceLocation))
 -> State DetUniqFM (Name, (Name, (Type, Maybe IpeSourceLocation))))
-> [(Name, (Type, Maybe IpeSourceLocation))]
-> State
     DetUniqFM [(Name, (Name, (Type, Maybe IpeSourceLocation)))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (\(Name
n,(Type, Maybe IpeSourceLocation)
r) -> do
        n' <- Name -> DetRnM Name
detRenameName Name
n
        return (n', (n', r))
        ) (ClosureMap -> [(Name, (Type, Maybe IpeSourceLocation))]
forall {k} (key :: k) elt. UniqDFM key elt -> [elt]
eltsUDFM ClosureMap
m)