ghc-lib-parser-9.12.2.20250421: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Cmm.Node

Contents

- Tick scopes

Synopsis

- data CmmNode (e :: Extensibility) (x :: Extensibility) where
  - CmmEntry :: !Label -> CmmTickScope -> CmmNode 'Closed 'Open
  - CmmComment :: FastString -> CmmNode 'Open 'Open
  - CmmTick :: !CmmTickish -> CmmNode 'Open 'Open
  - CmmUnwind :: [(GlobalReg, Maybe CmmExpr)] -> CmmNode 'Open 'Open
  - CmmAssign :: !CmmReg -> !CmmExpr -> CmmNode 'Open 'Open
  - CmmStore :: !CmmExpr -> !CmmExpr -> !AlignmentSpec -> CmmNode 'Open 'Open
  - CmmUnsafeForeignCall :: ForeignTarget -> [CmmFormal] -> [CmmActual] -> CmmNode 'Open 'Open
  - CmmBranch :: !Label -> CmmNode 'Open 'Closed
  - CmmCondBranch :: {..} -> CmmNode 'Open 'Closed
  - CmmSwitch :: CmmExpr -> SwitchTargets -> CmmNode 'Open 'Closed
  - CmmCall :: {..} -> CmmNode 'Open 'Closed
  - CmmForeignCall :: {..} -> CmmNode 'Open 'Closed
- type CmmFormal = LocalReg
- type CmmActual = CmmExpr
- type CmmTickish = GenTickish 'TickishPassCmm
- type UpdFrameOffset = ByteOff
- data Convention
  - = NativeDirectCall
  - | NativeNodeCall
  - | NativeReturn
  - | Slow
  - | GC
- data ForeignConvention = ForeignConvention CCallConv [ForeignHint] [ForeignHint] CmmReturnInfo
- data ForeignTarget
  - = ForeignTarget CmmExpr ForeignConvention
  - | PrimTarget CallishMachOp
- foreignTargetHints :: ForeignTarget -> ([ForeignHint], [ForeignHint])
- data CmmReturnInfo
  - = CmmMayReturn
  - | CmmNeverReturns
- mapExp :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> CmmExpr) -> CmmNode e x -> CmmNode e x
- mapExpDeep :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> CmmExpr) -> CmmNode e x -> CmmNode e x
- wrapRecExp :: (CmmExpr -> CmmExpr) -> CmmExpr -> CmmExpr
- foldExp :: forall z (e :: Extensibility) (x :: Extensibility). (CmmExpr -> z -> z) -> CmmNode e x -> z -> z
- foldExpDeep :: forall z (e :: Extensibility) (x :: Extensibility). (CmmExpr -> z -> z) -> CmmNode e x -> z -> z
- wrapRecExpf :: (CmmExpr -> z -> z) -> CmmExpr -> z -> z
- mapExpM :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> Maybe CmmExpr) -> CmmNode e x -> Maybe (CmmNode e x)
- mapExpDeepM :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> Maybe CmmExpr) -> CmmNode e x -> Maybe (CmmNode e x)
- wrapRecExpM :: (CmmExpr -> Maybe CmmExpr) -> CmmExpr -> Maybe CmmExpr
- mapSuccessors :: (Label -> Label) -> CmmNode O C -> CmmNode O C
- mapCollectSuccessors :: (Label -> (Label, a)) -> CmmNode O C -> (CmmNode O C, [a])
- data CmmTickScope
  - = GlobalScope
  - | SubScope !Unique CmmTickScope
  - | CombinedScope CmmTickScope CmmTickScope
- isTickSubScope :: CmmTickScope -> CmmTickScope -> Bool
- combineTickScopes :: CmmTickScope -> CmmTickScope -> CmmTickScope

# Documentation

data CmmNode (e :: Extensibility) (x :: Extensibility) where Source #

Constructors

CmmEntry :: !Label -> CmmTickScope -> CmmNode 'Closed 'Open |
CmmComment :: FastString -> CmmNode 'Open 'Open |
CmmTick :: !CmmTickish -> CmmNode 'Open 'Open |
CmmUnwind :: [(GlobalReg, Maybe CmmExpr)] -> CmmNode 'Open 'Open |
CmmAssign :: !CmmReg -> !CmmExpr -> CmmNode 'Open 'Open |
CmmStore :: !CmmExpr -> !CmmExpr -> !AlignmentSpec -> CmmNode 'Open 'Open |
CmmUnsafeForeignCall :: ForeignTarget -> [CmmFormal] -> [CmmActual] -> CmmNode 'Open 'Open |
CmmBranch :: !Label -> CmmNode 'Open 'Closed |
CmmCondBranch |

Fields

- :: { cml_pred :: CmmExpr
- , cml_true :: !Label
- , cml_false :: !Label
- , cml_likely :: Maybe Bool
- } -> CmmNode 'Open 'Closed

CmmSwitch :: CmmExpr -> SwitchTargets -> CmmNode 'Open 'Closed |
CmmCall |

Fields

- :: { cml_target :: CmmExpr
- , cml_cont :: Maybe Label
- , cml_args_regs :: [GlobalRegUse]
- , cml_args :: ByteOff
- , cml_ret_args :: ByteOff
- , cml_ret_off :: ByteOff
- } -> CmmNode 'Open 'Closed

CmmForeignCall |

Fields

- :: { tgt :: ForeignTarget
- , res :: [CmmFormal]
- , args :: [CmmActual]
- , succ :: !Label
- , ret_args :: ByteOff
- , ret_off :: ByteOff
- , intrbl :: Bool
- } -> CmmNode 'Open 'Closed

#### Instances

Instances details

NonLocal CmmNode Source # |
Instance details Defined in GHC.Cmm.Node Methods entryLabel :: forall (x :: Extensibility). CmmNode C x -> Label Source # successors :: forall (e :: Extensibility). CmmNode e C -> [Label] Source #
OutputableP Platform CmmGraph Source # |
Instance details Defined in GHC.Cmm Methods pdoc :: Platform -> CmmGraph -> SDoc Source #
DefinerOfRegs GlobalRegUse (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods foldRegsDefd :: Platform -> (b -> GlobalRegUse -> b) -> b -> CmmNode e x -> b Source #
DefinerOfRegs LocalReg (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods foldRegsDefd :: Platform -> (b -> LocalReg -> b) -> b -> CmmNode e x -> b Source #
UserOfRegs GlobalRegUse (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods foldRegsUsed :: Platform -> (b -> GlobalRegUse -> b) -> b -> CmmNode e x -> b Source #
UserOfRegs LocalReg (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods foldRegsUsed :: Platform -> (b -> LocalReg -> b) -> b -> CmmNode e x -> b Source #
OutputableP Platform (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> CmmNode e x -> SDoc Source #
OutputableP Platform (Block CmmNode C C) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> Block CmmNode C C -> SDoc Source #
OutputableP Platform (Block CmmNode C O) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> Block CmmNode C O -> SDoc Source #
OutputableP Platform (Block CmmNode O C) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> Block CmmNode O C -> SDoc Source #
OutputableP Platform (Block CmmNode O O) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> Block CmmNode O O -> SDoc Source #
OutputableP Platform (Graph CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> Graph CmmNode e x -> SDoc Source #
Eq (CmmNode e x) Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: CmmNode e x -> CmmNode e x -> Bool Source # (/=) :: CmmNode e x -> CmmNode e x -> Bool Source #

type CmmFormal = LocalReg Source #

type CmmActual = CmmExpr Source #

type CmmTickish = GenTickish 'TickishPassCmm Source #

Tickish in Cmm context (annotations only)

type UpdFrameOffset = ByteOff Source #

data Convention Source #

A convention maps a list of values (function arguments or return values) to registers or stack locations.

Constructors

NativeDirectCall | top-level Haskell functions use `NativeDirectCall`, which maps arguments to registers starting with R2, according to how many registers are available on the platform. This convention ignores R1, because for a top-level function call the function closure is implicit, and doesn't need to be passed.
NativeNodeCall | non-top-level Haskell functions, which pass the address of the function closure in R1 (regardless of whether R1 is a real register or not), and the rest of the arguments in registers or on the stack.
NativeReturn | a native return. The convention for returns depends on how many values are returned: for just one value returned, the appropriate register is used (R1, F1, etc.). regardless of whether it is a real register or not. For multiple values returned, they are mapped to registers or the stack.
Slow | Slow entry points: all args pushed on the stack
GC | Entry to the garbage collector: uses the node reg! (TODO: I don't think we need this --SDM)

#### Instances

Instances details

Outputable Convention Source # |
Instance details Defined in GHC.Cmm.Node Methods ppr :: Convention -> SDoc Source #
Eq Convention Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: Convention -> Convention -> Bool Source # (/=) :: Convention -> Convention -> Bool Source #

data ForeignConvention Source #

Constructors

ForeignConvention CCallConv [ForeignHint] [ForeignHint] CmmReturnInfo |

#### Instances

Instances details

Outputable ForeignConvention Source # |
Instance details Defined in GHC.Cmm.Node Methods ppr :: ForeignConvention -> SDoc Source #
Eq ForeignConvention Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: ForeignConvention -> ForeignConvention -> Bool Source # (/=) :: ForeignConvention -> ForeignConvention -> Bool Source #

data ForeignTarget Source #

Constructors

ForeignTarget CmmExpr ForeignConvention |
PrimTarget CallishMachOp |

#### Instances

Instances details

Eq ForeignTarget Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: ForeignTarget -> ForeignTarget -> Bool Source # (/=) :: ForeignTarget -> ForeignTarget -> Bool Source #
(Ord r, UserOfRegs r CmmReg) => UserOfRegs r ForeignTarget Source # |
Instance details Defined in GHC.Cmm.Node Methods foldRegsUsed :: Platform -> (b -> r -> b) -> b -> ForeignTarget -> b Source #
OutputableP Platform ForeignTarget Source # |
Instance details Defined in GHC.Cmm.Node Methods pdoc :: Platform -> ForeignTarget -> SDoc Source #

foreignTargetHints :: ForeignTarget -> ([ForeignHint], [ForeignHint]) Source #

data CmmReturnInfo Source #

Constructors

CmmMayReturn |
CmmNeverReturns |

#### Instances

Instances details

Outputable CmmReturnInfo Source # |
Instance details Defined in GHC.Cmm.Node Methods ppr :: CmmReturnInfo -> SDoc Source #
Eq CmmReturnInfo Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: CmmReturnInfo -> CmmReturnInfo -> Bool Source # (/=) :: CmmReturnInfo -> CmmReturnInfo -> Bool Source #

mapExp :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> CmmExpr) -> CmmNode e x -> CmmNode e x Source #

mapExpDeep :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> CmmExpr) -> CmmNode e x -> CmmNode e x Source #

wrapRecExp :: (CmmExpr -> CmmExpr) -> CmmExpr -> CmmExpr Source #

foldExp :: forall z (e :: Extensibility) (x :: Extensibility). (CmmExpr -> z -> z) -> CmmNode e x -> z -> z Source #

foldExpDeep :: forall z (e :: Extensibility) (x :: Extensibility). (CmmExpr -> z -> z) -> CmmNode e x -> z -> z Source #

wrapRecExpf :: (CmmExpr -> z -> z) -> CmmExpr -> z -> z Source #

mapExpM :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> Maybe CmmExpr) -> CmmNode e x -> Maybe (CmmNode e x) Source #

mapExpDeepM :: forall (e :: Extensibility) (x :: Extensibility). (CmmExpr -> Maybe CmmExpr) -> CmmNode e x -> Maybe (CmmNode e x) Source #

wrapRecExpM :: (CmmExpr -> Maybe CmmExpr) -> CmmExpr -> Maybe CmmExpr Source #

mapSuccessors :: (Label -> Label) -> CmmNode O C -> CmmNode O C Source #

mapCollectSuccessors :: (Label -> (Label, a)) -> CmmNode O C -> (CmmNode O C, [a]) Source #

# Tick scopes

data CmmTickScope Source #

Tick scope identifier, allowing us to reason about what annotations in a Cmm block should scope over. We especially take care to allow optimisations to reorganise blocks without losing tick association in the process.

Constructors

GlobalScope | The global scope is the "root" of the scope graph. Every scope is a sub-scope of the global scope. It doesn't make sense to add ticks to this scope. On the other hand, this means that setting this scope on a block means no ticks apply to it.

SubScope !Unique CmmTickScope

Constructs a new sub-scope to an existing scope. This allows us to translate Core-style scoping rules (see `tickishScoped`) into the Cmm world. Suppose the following code:

tick1 case ... of A -> tick2 ... B -> tick3 ...

We want the top-level tick annotation to apply to blocks generated for the A and B alternatives. We can achieve that by generating tick1 into a block with scope a, while the code for alternatives A and B gets generated into sub-scopes a/b and a/c respectively.

CombinedScope CmmTickScope CmmTickScope

A combined scope scopes over everything that the two given scopes cover. It is therefore a sub-scope of either scope. This is required for optimisations. Consider common block elimination:

A -> tick2 case ... of C -> [common] B -> tick3 case ... of D -> [common]

We will generate code for the C and D alternatives, and figure out afterwards that it's actually common code. Scoping rules dictate that the resulting common block needs to be covered by both tick2 and tick3, therefore we need to construct a scope that is a child to *both* scope. Now we can do that - if we assign the scopes ac and bd to the common-ed up blocks, the new block could have a combined tick scope ac+bd, which both tick2 and tick3 apply to.

#### Instances

Instances details

Outputable CmmTickScope Source # |
Instance details Defined in GHC.Cmm.Node Methods ppr :: CmmTickScope -> SDoc Source #
Eq CmmTickScope Source # |
Instance details Defined in GHC.Cmm.Node Methods (==) :: CmmTickScope -> CmmTickScope -> Bool Source # (/=) :: CmmTickScope -> CmmTickScope -> Bool Source #
Ord CmmTickScope Source # |

Instance details

Defined in GHC.Cmm.Node

Methods

compare :: CmmTickScope -> CmmTickScope -> Ordering Source #

(<) :: CmmTickScope -> CmmTickScope -> Bool Source #

(<=) :: CmmTickScope -> CmmTickScope -> Bool Source #

(>) :: CmmTickScope -> CmmTickScope -> Bool Source #

(>=) :: CmmTickScope -> CmmTickScope -> Bool Source #

max :: CmmTickScope -> CmmTickScope -> CmmTickScope Source #

min :: CmmTickScope -> CmmTickScope -> CmmTickScope Source #

isTickSubScope :: CmmTickScope -> CmmTickScope -> Bool Source #

Checks whether two tick scopes are sub-scopes of each other. True if the two scopes are equal.

combineTickScopes :: CmmTickScope -> CmmTickScope -> CmmTickScope Source #

Combine two tick scopes. The new scope should be sub-scope of both parameters. We simplify automatically if one tick scope is a sub-scope of the other already.