Jaro Reinders pushed to branch wip/reduce-type-in-stg at Glasgow Haskell Compiler / GHC
Commits:
-
74459809
by Jaro Reinders at 2026-04-21T14:20:35+02:00
19 changed files:
- compiler/GHC/CoreToStg.hs
- compiler/GHC/Stg/CSE.hs
- compiler/GHC/Stg/Debug.hs
- compiler/GHC/Stg/EnforceEpt.hs
- compiler/GHC/Stg/EnforceEpt/Rewrite.hs
- compiler/GHC/Stg/FVs.hs
- compiler/GHC/Stg/Lift.hs
- compiler/GHC/Stg/Lift/Analysis.hs
- compiler/GHC/Stg/Lint.hs
- compiler/GHC/Stg/Stats.hs
- compiler/GHC/Stg/Syntax.hs
- compiler/GHC/Stg/Unarise.hs
- compiler/GHC/StgToByteCode.hs
- compiler/GHC/StgToCmm/Expr.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/StgToJS/Expr.hs
- compiler/GHC/StgToJS/Sinker/Collect.hs
- compiler/GHC/StgToJS/Sinker/StringsUnfloat.hs
- compiler/GHC/StgToJS/Utils.hs
Changes:
| ... | ... | @@ -552,24 +552,24 @@ mkStgApp f how_bound core_args stg_args res_ty |
| 552 | 552 | -- stores the type constructor information. See Note [tagToEnum# in STG]
|
| 553 | 553 | -- in GHC.Stg.Syntax.
|
| 554 | 554 | PrimOpId TagToEnumOp _ ->
|
| 555 | - StgOpApp (StgTagToEnumOp (tcTyConAppTyCon res_ty)) stg_args res_kind
|
|
| 555 | + StgOpApp (StgTagToEnumOp (tcTyConAppTyCon res_ty)) stg_args
|
|
| 556 | 556 | |
| 557 | 557 | -- Some primitive operator that might be implemented as a library call.
|
| 558 | 558 | -- As noted by Note [Eta expanding primops] in GHC.Builtin.PrimOps
|
| 559 | 559 | -- we require that primop applications be saturated.
|
| 560 | 560 | PrimOpId op _ -> -- assertPpr saturated (ppr f <+> ppr stg_args) $
|
| 561 | - StgOpApp (StgPrimOp op) stg_args res_kind
|
|
| 561 | + StgOpApp (StgPrimOp op) stg_args
|
|
| 562 | 562 | |
| 563 | 563 | -- A call to some primitive Cmm function.
|
| 564 | 564 | FCallId (CCall (CCallSpec
|
| 565 | 565 | (StaticTarget ext lbl ForeignFunction) PrimCallConv _))
|
| 566 | 566 | | TargetIsInThat unit <- staticTargetUnit ext
|
| 567 | 567 | -> assert exactly_saturated $
|
| 568 | - StgOpApp (StgPrimCallOp (PrimCall lbl unit)) stg_args res_kind
|
|
| 568 | + StgOpApp (StgPrimCallOp (PrimCall lbl unit) res_kind) stg_args
|
|
| 569 | 569 | |
| 570 | 570 | -- A regular foreign call.
|
| 571 | 571 | FCallId call -> assert exactly_saturated $
|
| 572 | - StgOpApp (StgFCallOp call (collectStgFArgTypes (idType f))) stg_args res_kind
|
|
| 572 | + StgOpApp (StgFCallOp call (collectStgFArgTypes (idType f)) res_kind) stg_args
|
|
| 573 | 573 | |
| 574 | 574 | TickBoxOpId {} -> pprPanic "coreToStg TickBox" $ ppr (f,stg_args)
|
| 575 | 575 |
| ... | ... | @@ -349,8 +349,8 @@ stgCseExpr env (StgApp fun args) |
| 349 | 349 | args' = substArgs env args
|
| 350 | 350 | stgCseExpr _ (StgLit lit)
|
| 351 | 351 | = StgLit lit
|
| 352 | -stgCseExpr env (StgOpApp op args tys)
|
|
| 353 | - = StgOpApp op args' tys
|
|
| 352 | +stgCseExpr env (StgOpApp op args)
|
|
| 353 | + = StgOpApp op args'
|
|
| 354 | 354 | where args' = substArgs env args
|
| 355 | 355 | stgCseExpr env (StgTick tick body)
|
| 356 | 356 | = let body' = stgCseExpr env body
|
| ... | ... | @@ -103,7 +103,7 @@ collectExpr = go |
| 103 | 103 | go (StgConApp dc _mn as tys) = do
|
| 104 | 104 | n' <- numberDataCon dc []
|
| 105 | 105 | return (StgConApp dc n' as tys)
|
| 106 | - go (StgOpApp op as ty) = return (StgOpApp op as ty)
|
|
| 106 | + go (StgOpApp op as) = return (StgOpApp op as)
|
|
| 107 | 107 | go (StgCase scrut bndr ty alts) =
|
| 108 | 108 | StgCase <$> collectExpr scrut <*> pure bndr <*> pure ty <*> mapM collectAlt alts
|
| 109 | 109 | go (StgLet ext bind body) = do
|
| ... | ... | @@ -419,11 +419,11 @@ inferTagExpr env (StgTick tick body) |
| 419 | 419 | where
|
| 420 | 420 | (info, body') = inferTagExpr env body
|
| 421 | 421 | |
| 422 | -inferTagExpr _ (StgOpApp op args ty)
|
|
| 422 | +inferTagExpr _ (StgOpApp op args)
|
|
| 423 | 423 | -- Which primops guarantee to return a properly tagged value?
|
| 424 | 424 | -- Probably none, and that is the conservative assumption anyway.
|
| 425 | 425 | -- (And foreign calls definitely need not make promises.)
|
| 426 | - = (TagDunno, StgOpApp op args ty)
|
|
| 426 | + = (TagDunno, StgOpApp op args)
|
|
| 427 | 427 | |
| 428 | 428 | inferTagExpr env (StgLet ext bind body)
|
| 429 | 429 | = (info, StgLet ext bind' body')
|
| ... | ... | @@ -396,7 +396,7 @@ rewriteExpr (StgTick t e) = StgTick t <$!> rewriteExpr e |
| 396 | 396 | rewriteExpr e@(StgConApp {}) = rewriteConApp e
|
| 397 | 397 | rewriteExpr e@(StgApp {}) = rewriteApp e
|
| 398 | 398 | rewriteExpr (StgLit lit) = return $! (StgLit lit)
|
| 399 | -rewriteExpr (StgOpApp op args res_ty) = (StgOpApp op) <$!> rewriteArgs args <*> pure res_ty
|
|
| 399 | +rewriteExpr (StgOpApp op args) = StgOpApp op <$!> rewriteArgs args
|
|
| 400 | 400 | |
| 401 | 401 | |
| 402 | 402 | rewriteCase :: InferStgExpr -> RM TgStgExpr
|
| ... | ... | @@ -496,12 +496,12 @@ So for these we should call `rewriteArgs`. |
| 496 | 496 | -}
|
| 497 | 497 | |
| 498 | 498 | rewriteOpApp :: InferStgExpr -> RM TgStgExpr
|
| 499 | -rewriteOpApp (StgOpApp op args res_ty) = case op of
|
|
| 499 | +rewriteOpApp (StgOpApp op args) = case op of
|
|
| 500 | 500 | op@(StgPrimOp primOp)
|
| 501 | 501 | | primOp == DataToTagSmallOp || primOp == DataToTagLargeOp
|
| 502 | 502 | -- see Note [Rewriting primop arguments]
|
| 503 | - -> (StgOpApp op) <$!> rewriteArgs args <*> pure res_ty
|
|
| 504 | - _ -> pure $! StgOpApp op args res_ty
|
|
| 503 | + -> StgOpApp op <$!> rewriteArgs args
|
|
| 504 | + _ -> pure $! StgOpApp op args
|
|
| 505 | 505 | rewriteOpApp _ = panic "Impossible"
|
| 506 | 506 | |
| 507 | 507 | -- `mkSeq` x x' e generates `case x of x' -> e`
|
| ... | ... | @@ -234,9 +234,9 @@ exprFVs env = go |
| 234 | 234 | | (imp_fvs, top_fvs, lcl_fvs) <- argsFVs env as
|
| 235 | 235 | = (StgConApp dc n as tys, imp_fvs, top_fvs, lcl_fvs)
|
| 236 | 236 | |
| 237 | - go (StgOpApp op as ty)
|
|
| 237 | + go (StgOpApp op as)
|
|
| 238 | 238 | | (imp_fvs, top_fvs, lcl_fvs) <- argsFVs env as
|
| 239 | - = (StgOpApp op as ty, imp_fvs, top_fvs, lcl_fvs)
|
|
| 239 | + = (StgOpApp op as, imp_fvs, top_fvs, lcl_fvs)
|
|
| 240 | 240 | |
| 241 | 241 | go (StgCase scrut bndr ty alts)
|
| 242 | 242 | | (scrut',scrut_imp_fvs,scrut_top_fvs,scrut_lcl_fvs) <- exprFVs env scrut
|
| ... | ... | @@ -229,7 +229,7 @@ liftExpr (StgApp f args) = do |
| 229 | 229 | let top_lvl_args = map StgVarArg fvs' ++ args'
|
| 230 | 230 | pure (StgApp f' top_lvl_args)
|
| 231 | 231 | liftExpr (StgConApp con mn args tys) = StgConApp con mn <$> traverse liftArgs args <*> pure tys
|
| 232 | -liftExpr (StgOpApp op args ty) = StgOpApp op <$> traverse liftArgs args <*> pure ty
|
|
| 232 | +liftExpr (StgOpApp op args) = StgOpApp op <$> traverse liftArgs args
|
|
| 233 | 233 | liftExpr (StgCase scrut info ty alts) = do
|
| 234 | 234 | scrut' <- liftExpr scrut
|
| 235 | 235 | withSubstBndr (binderInfoBndr info) $ \bndr' -> do
|
| ... | ... | @@ -138,8 +138,8 @@ tagSkeletonExpr (StgLit lit) |
| 138 | 138 | = (NilSk, emptyVarSet, StgLit lit)
|
| 139 | 139 | tagSkeletonExpr (StgConApp con mn args tys)
|
| 140 | 140 | = (NilSk, mkArgOccs args, StgConApp con mn args tys)
|
| 141 | -tagSkeletonExpr (StgOpApp op args ty)
|
|
| 142 | - = (NilSk, mkArgOccs args, StgOpApp op args ty)
|
|
| 141 | +tagSkeletonExpr (StgOpApp op args)
|
|
| 142 | + = (NilSk, mkArgOccs args, StgOpApp op args)
|
|
| 143 | 143 | tagSkeletonExpr (StgApp f args)
|
| 144 | 144 | = (NilSk, arg_occs, StgApp f args)
|
| 145 | 145 | where
|
| ... | ... | @@ -295,7 +295,7 @@ lintStgExpr app@(StgConApp con _n args _arg_tys) = do |
| 295 | 295 | opts <- getStgPprOpts
|
| 296 | 296 | lintConApp con args (pprStgExpr opts app)
|
| 297 | 297 | |
| 298 | -lintStgExpr (StgOpApp _ args _) =
|
|
| 298 | +lintStgExpr (StgOpApp _ args) =
|
|
| 299 | 299 | mapM_ lintStgFunArg args
|
| 300 | 300 | |
| 301 | 301 | lintStgExpr (StgLet _ binds body) = do
|
| ... | ... | @@ -150,7 +150,7 @@ statExpr :: StgExpr -> StatEnv |
| 150 | 150 | statExpr (StgApp _ _) = countOne Applications
|
| 151 | 151 | statExpr (StgLit _) = countOne Literals
|
| 152 | 152 | statExpr (StgConApp {}) = countOne ConstructorApps
|
| 153 | -statExpr (StgOpApp _ _ _) = countOne PrimitiveApps
|
|
| 153 | +statExpr (StgOpApp _ _) = countOne PrimitiveApps
|
|
| 154 | 154 | statExpr (StgTick _ e) = statExpr e
|
| 155 | 155 | |
| 156 | 156 | statExpr (StgLetNoEscape _ binds body)
|
| ... | ... | @@ -282,9 +282,6 @@ for the details of this transformation. |
| 282 | 282 | |
| 283 | 283 | | StgOpApp StgOp -- Primitive op or foreign call
|
| 284 | 284 | [StgArg] -- Saturated.
|
| 285 | - StgKind -- Result kind
|
|
| 286 | - -- We need to know this so that we can
|
|
| 287 | - -- assign result registers
|
|
| 288 | 285 | |
| 289 | 286 | {-
|
| 290 | 287 | ************************************************************************
|
| ... | ... | @@ -795,9 +792,9 @@ last moment that we still have access to the type information. |
| 795 | 792 | data StgOp
|
| 796 | 793 | = StgPrimOp PrimOp
|
| 797 | 794 | |
| 798 | - | StgPrimCallOp PrimCall
|
|
| 795 | + | StgPrimCallOp PrimCall StgKind
|
|
| 799 | 796 | |
| 800 | - | StgFCallOp ForeignCall [StgFArgType]
|
|
| 797 | + | StgFCallOp ForeignCall [StgFArgType] StgKind
|
|
| 801 | 798 | -- The foreign argument types, which are obtained from the foreign
|
| 802 | 799 | -- import declaration itself, areneeded by the stg-to-cmm pass to
|
| 803 | 800 | -- determine the offset to apply to unlifted boxed arguments in
|
| ... | ... | @@ -907,7 +904,7 @@ pprStgExpr opts e = case e of |
| 907 | 904 | -> ppr func <> ppr sig
|
| 908 | 905 | | otherwise -> hang (ppr func) 4 (interppSP args) -- TODO: Print taggedness
|
| 909 | 906 | StgConApp con n args _ -> hsep [ ppr con, ppr n, brackets (interppSP args) ]
|
| 910 | - StgOpApp op args _ -> hsep [ pprStgOp op, brackets (interppSP args)]
|
|
| 907 | + StgOpApp op args -> hsep [ pprStgOp op, brackets (interppSP args)]
|
|
| 911 | 908 | |
| 912 | 909 | -- special case: let v = <very specific thing>
|
| 913 | 910 | -- in
|
| ... | ... | @@ -994,8 +991,8 @@ pprStgAlt opts indent GenStgAlt{alt_con, alt_bndrs, alt_rhs} |
| 994 | 991 | |
| 995 | 992 | pprStgOp :: StgOp -> SDoc
|
| 996 | 993 | pprStgOp (StgPrimOp op) = ppr op
|
| 997 | -pprStgOp (StgPrimCallOp op)= ppr op
|
|
| 998 | -pprStgOp (StgFCallOp op _) = ppr op
|
|
| 994 | +pprStgOp (StgPrimCallOp op _)= ppr op
|
|
| 995 | +pprStgOp (StgFCallOp op _ _) = ppr op
|
|
| 999 | 996 | -- TODO: how do we want to pretty print this?
|
| 1000 | 997 | pprStgOp (StgTagToEnumOp tyc) = text "TagToEnumOp" <+> ppr tyc
|
| 1001 | 998 |
| ... | ... | @@ -574,8 +574,8 @@ unariseExpr rho (StgConApp dc n args ty_args) |
| 574 | 574 | let args' = unariseConArgs rho args in
|
| 575 | 575 | return $ (StgConApp dc n args' [])
|
| 576 | 576 | |
| 577 | -unariseExpr rho (StgOpApp op args ty)
|
|
| 578 | - = return (StgOpApp op (unariseFunArgs rho args) ty)
|
|
| 577 | +unariseExpr rho (StgOpApp op args)
|
|
| 578 | + = return (StgOpApp op (unariseFunArgs rho args))
|
|
| 579 | 579 | |
| 580 | 580 | unariseExpr rho (StgCase scrut bndr alt_ty alts)
|
| 581 | 581 | -- tuple/sum binders in the scrutinee can always be eliminated
|
| ... | ... | @@ -902,7 +902,7 @@ stgKindPrimRep1 (MkStgKind k) = case kindPrimRep_maybe k of |
| 902 | 902 | |
| 903 | 903 | mkCast :: StgArg -> PrimOp -> OutId -> StgKind -> StgExpr -> StgExpr
|
| 904 | 904 | mkCast arg_in cast_op out_id out_kind in_rhs =
|
| 905 | - let scrut = StgOpApp (StgPrimOp cast_op) [arg_in] out_kind
|
|
| 905 | + let scrut = StgOpApp (StgPrimOp cast_op) [arg_in]
|
|
| 906 | 906 | alt = GenStgAlt { alt_con = DEFAULT, alt_bndrs = [], alt_rhs = in_rhs}
|
| 907 | 907 | alt_ty = PrimAlt (stgKindPrimRep1 out_kind)
|
| 908 | 908 | in (StgCase scrut out_id alt_ty [alt])
|
| ... | ... | @@ -659,12 +659,12 @@ schemeT d s p app |
| 659 | 659 | = implement_tagToId d s p arg constr_names
|
| 660 | 660 | |
| 661 | 661 | -- Case 1
|
| 662 | -schemeT d s p (StgOpApp (StgFCallOp (CCall ccall_spec) _ty) args kind)
|
|
| 662 | +schemeT d s p (StgOpApp (StgFCallOp (CCall ccall_spec) _argtys kind) args)
|
|
| 663 | 663 | = if isSupportedCConv ccall_spec
|
| 664 | 664 | then generateCCall d s p ccall_spec kind args
|
| 665 | 665 | else unsupportedCConvException
|
| 666 | 666 | |
| 667 | -schemeT d s p (StgOpApp (StgPrimOp op) args _ty) = do
|
|
| 667 | +schemeT d s p (StgOpApp (StgPrimOp op) args) = do
|
|
| 668 | 668 | profile <- getProfile
|
| 669 | 669 | let platform = profilePlatform profile
|
| 670 | 670 | case doPrimOp platform op d s p args of
|
| ... | ... | @@ -673,7 +673,7 @@ schemeT d s p (StgOpApp (StgPrimOp op) args _ty) = do |
| 673 | 673 | -- Otherwise we have to do a call to the primop wrapper instead :(
|
| 674 | 674 | _ -> doTailCall d s p (primOpId op) (reverse args)
|
| 675 | 675 | |
| 676 | -schemeT d s p (StgOpApp (StgPrimCallOp (PrimCall label _)) args _reps)
|
|
| 676 | +schemeT d s p (StgOpApp (StgPrimCallOp (PrimCall label _) _) args)
|
|
| 677 | 677 | = generatePrimCall d s p label args
|
| 678 | 678 | |
| 679 | 679 | schemeT d s p (StgConApp con _cn args _tys)
|
| ... | ... | @@ -2170,7 +2170,7 @@ mkDummyLiteral platform pr |
| 2170 | 2170 | |
| 2171 | 2171 | maybe_is_tagToEnum_call :: CgStgExpr -> Maybe (StgArg, [Name])
|
| 2172 | 2172 | -- Detect and extract relevant info for the tagToEnum kludge.
|
| 2173 | -maybe_is_tagToEnum_call (StgOpApp (StgTagToEnumOp tyc) args _)
|
|
| 2173 | +maybe_is_tagToEnum_call (StgOpApp (StgTagToEnumOp tyc) args)
|
|
| 2174 | 2174 | | [v] <- args
|
| 2175 | 2175 | = Just (v, extract_constr_Names tyc)
|
| 2176 | 2176 | | otherwise
|
| ... | ... | @@ -69,7 +69,7 @@ cgExpr (StgApp fun args) = cgIdApp fun args |
| 69 | 69 | -- dataToTagSmall# :: a_levpoly -> Int#
|
| 70 | 70 | -- See Note [DataToTag overview] in GHC.Tc.Instance.Class,
|
| 71 | 71 | -- particularly wrinkles H3 and DTW4
|
| 72 | -cgExpr (StgOpApp (StgPrimOp DataToTagSmallOp) [StgVarArg a] _res_ty) = do
|
|
| 72 | +cgExpr (StgOpApp (StgPrimOp DataToTagSmallOp) [StgVarArg a]) = do
|
|
| 73 | 73 | platform <- getPlatform
|
| 74 | 74 | emitComment (mkFastString "dataToTagSmall#")
|
| 75 | 75 | |
| ... | ... | @@ -84,7 +84,7 @@ cgExpr (StgOpApp (StgPrimOp DataToTagSmallOp) [StgVarArg a] _res_ty) = do |
| 84 | 84 | -- dataToTagLarge# :: a_levpoly -> Int#
|
| 85 | 85 | -- See Note [DataToTag overview] in GHC.Tc.Instance.Class,
|
| 86 | 86 | -- particularly wrinkles H3 and DTW4
|
| 87 | -cgExpr (StgOpApp (StgPrimOp DataToTagLargeOp) [StgVarArg a] _res_ty) = do
|
|
| 87 | +cgExpr (StgOpApp (StgPrimOp DataToTagLargeOp) [StgVarArg a]) = do
|
|
| 88 | 88 | platform <- getPlatform
|
| 89 | 89 | emitComment (mkFastString "dataToTagLarge#")
|
| 90 | 90 | |
| ... | ... | @@ -114,7 +114,7 @@ cgExpr (StgOpApp (StgPrimOp DataToTagLargeOp) [StgVarArg a] _res_ty) = do |
| 114 | 114 | emitReturn [CmmReg $ CmmLocal result_reg]
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | -cgExpr (StgOpApp op args kind) = cgOpApp op args kind
|
|
| 117 | +cgExpr (StgOpApp op args) = cgOpApp op args
|
|
| 118 | 118 | cgExpr (StgConApp con mn args _) = cgConApp con mn args
|
| 119 | 119 | cgExpr (StgTick t e) = cgTick t >> cgExpr e
|
| 120 | 120 | cgExpr (StgLit lit) = do cmm_expr <- cgLit lit
|
| ... | ... | @@ -621,7 +621,7 @@ cgCase scrut bndr alt_type alts |
| 621 | 621 | ; cgAlts (gc_plan,ret_kind) (NonVoid bndr) alt_type alts
|
| 622 | 622 | }
|
| 623 | 623 | where
|
| 624 | - is_cmp_op (StgOpApp (StgPrimOp op) _ _) = isComparisonPrimOp op
|
|
| 624 | + is_cmp_op (StgOpApp (StgPrimOp op) _) = isComparisonPrimOp op
|
|
| 625 | 625 | is_cmp_op _ = False
|
| 626 | 626 | |
| 627 | 627 | |
| ... | ... | @@ -663,7 +663,7 @@ isSimpleScrut :: CgStgExpr -> AltType -> FCode Bool |
| 663 | 663 | -- heap usage from alternatives into the stuff before the case
|
| 664 | 664 | -- NB: if you get this wrong, and claim that the expression doesn't allocate
|
| 665 | 665 | -- when it does, you'll deeply mess up allocation
|
| 666 | -isSimpleScrut (StgOpApp op args _) _ = isSimpleOp op args
|
|
| 666 | +isSimpleScrut (StgOpApp op args) _ = isSimpleOp op args
|
|
| 667 | 667 | isSimpleScrut (StgLit _) _ = return True -- case 1# of { 0# -> ..; ... }
|
| 668 | 668 | isSimpleScrut (StgApp _ []) (PrimAlt _) = return True -- case x# of { 0# -> ..; ... }
|
| 669 | 669 | isSimpleScrut (StgApp f []) _
|
| ... | ... | @@ -677,7 +677,7 @@ isSimpleScrut _ _ = return False |
| 677 | 677 | |
| 678 | 678 | isSimpleOp :: StgOp -> [StgArg] -> FCode Bool
|
| 679 | 679 | -- True iff the op cannot block or allocate
|
| 680 | -isSimpleOp (StgFCallOp (CCall (CCallSpec _ _ safe)) _) _ = return $! not (playSafe safe)
|
|
| 680 | +isSimpleOp (StgFCallOp (CCall (CCallSpec _ _ safe)) _ _) _ = return $! not (playSafe safe)
|
|
| 681 | 681 | -- dataToTagSmall#/dataToTagLarge# evaluate an argument;
|
| 682 | 682 | -- see Note [DataToTag overview] in GHC.Tc.Instance.Class
|
| 683 | 683 | isSimpleOp (StgPrimOp DataToTagSmallOp) _ = return False
|
| ... | ... | @@ -687,7 +687,7 @@ isSimpleOp (StgPrimOp op) stg_args = do |
| 687 | 687 | cfg <- getStgToCmmConfig
|
| 688 | 688 | -- See Note [Inlining out-of-line primops and heap checks]
|
| 689 | 689 | return $! shouldInlinePrimOp cfg op arg_exprs
|
| 690 | -isSimpleOp (StgPrimCallOp _) _ = return False
|
|
| 690 | +isSimpleOp (StgPrimCallOp _ _) _ = return False
|
|
| 691 | 691 | isSimpleOp (StgTagToEnumOp _) _ = return True
|
| 692 | 692 | |
| 693 | 693 | -----------------
|
| ... | ... | @@ -68,27 +68,26 @@ might be a Haskell closure pointer, we don't want to evaluate it. -} |
| 68 | 68 | ----------------------------------
|
| 69 | 69 | cgOpApp :: StgOp -- The op
|
| 70 | 70 | -> [StgArg] -- Arguments
|
| 71 | - -> StgKind -- Kind (always unboxed tuple)
|
|
| 72 | 71 | -> FCode ReturnKind
|
| 73 | 72 | |
| 74 | 73 | -- Foreign calls
|
| 75 | -cgOpApp (StgFCallOp fcall ty) stg_args res_kind
|
|
| 74 | +cgOpApp (StgFCallOp fcall ty res_kind) stg_args
|
|
| 76 | 75 | = cgForeignCall fcall ty stg_args res_kind
|
| 77 | 76 | -- See Note [Foreign call results]
|
| 78 | 77 | |
| 79 | -cgOpApp (StgPrimOp primop) args kind = do
|
|
| 78 | +cgOpApp (StgPrimOp primop) args = do
|
|
| 80 | 79 | cfg <- getStgToCmmConfig
|
| 81 | 80 | cmm_args <- getNonVoidArgAmodes args
|
| 82 | - cmmPrimOpApp cfg primop cmm_args (Just kind)
|
|
| 81 | + cmmPrimOpApp cfg primop cmm_args
|
|
| 83 | 82 | |
| 84 | -cgOpApp (StgPrimCallOp primcall) args _res_ty
|
|
| 83 | +cgOpApp (StgPrimCallOp primcall _) args
|
|
| 85 | 84 | = do { cmm_args <- getNonVoidArgAmodes args
|
| 86 | 85 | ; let fun = CmmLit (CmmLabel (mkPrimCallLabel primcall))
|
| 87 | 86 | ; emitCall (NativeNodeCall, NativeReturn) fun cmm_args }
|
| 88 | 87 | |
| 89 | 88 | -- tagToEnum# is special: we need to pull the constructor
|
| 90 | 89 | -- out of the table, and perform an appropriate return.
|
| 91 | -cgOpApp (StgTagToEnumOp tyc) args _ = do
|
|
| 90 | +cgOpApp (StgTagToEnumOp tyc) args = do
|
|
| 92 | 91 | amodes <- getNonVoidArgAmodes args
|
| 93 | 92 | case amodes of
|
| 94 | 93 | [amode] -> do
|
| ... | ... | @@ -102,14 +101,12 @@ cgOpApp (StgTagToEnumOp tyc) args _ = do |
| 102 | 101 | emitReturn [tagToClosure platform tyc amode]
|
| 103 | 102 | _ -> pprPanic "cgOpApp: tagToEnum# should be applied to exactly one argument" (ppr args)
|
| 104 | 103 | |
| 105 | -cmmPrimOpApp :: StgToCmmConfig -> PrimOp -> [CmmExpr] -> Maybe StgKind -> FCode ReturnKind
|
|
| 106 | -cmmPrimOpApp cfg primop cmm_args mres_ty =
|
|
| 104 | +cmmPrimOpApp :: StgToCmmConfig -> PrimOp -> [CmmExpr] -> FCode ReturnKind
|
|
| 105 | +cmmPrimOpApp cfg primop cmm_args =
|
|
| 107 | 106 | case emitPrimOp cfg primop cmm_args of
|
| 108 | 107 | PrimopCmmEmit_Internal f ->
|
| 109 | 108 | let
|
| 110 | - -- if the result kind isn't explicitly given, we directly use the
|
|
| 111 | - -- result kind of the primop.
|
|
| 112 | - res_ty = fromMaybe (MkStgKind (typeKind (primOpResultType primop))) mres_ty
|
|
| 109 | + res_ty = MkStgKind (typeKind (primOpResultType primop))
|
|
| 113 | 110 | in emitReturn =<< f res_ty
|
| 114 | 111 | PrimopCmmEmit_External -> do
|
| 115 | 112 | let fun = CmmLit (CmmLabel (mkRtsPrimOpLabel primop))
|
| ... | ... | @@ -2322,7 +2319,7 @@ genericIntMul2Op [res_c, res_h, res_l] both_args@[arg_x, arg_y] |
| 2322 | 2319 | p <- newTemp t
|
| 2323 | 2320 | -- 1) compute the multiplication as if numbers were unsigned
|
| 2324 | 2321 | _ <- withSequel (AssignTo [p, res_l] False) $
|
| 2325 | - cmmPrimOpApp cfg WordMul2Op both_args Nothing
|
|
| 2322 | + cmmPrimOpApp cfg WordMul2Op both_args
|
|
| 2326 | 2323 | -- 2) correct the high bits of the unsigned result
|
| 2327 | 2324 | let carryFill x = CmmMachOp (MO_S_Shr ww) [x, wwm1]
|
| 2328 | 2325 | sub x y = CmmMachOp (MO_Sub ww) [x, y]
|
| ... | ... | @@ -3676,7 +3673,7 @@ emitRangeBoundsCheck idx len arrSizeExpr = do |
| 3676 | 3673 | rangeTooLargeReg <- newTemp (bWord platform)
|
| 3677 | 3674 | lastSafeIndexReg <- newTemp (bWord platform)
|
| 3678 | 3675 | _ <- withSequel (AssignTo [lastSafeIndexReg, rangeTooLargeReg] False) $
|
| 3679 | - cmmPrimOpApp config WordSubCOp [arrSize, len] Nothing
|
|
| 3676 | + cmmPrimOpApp config WordSubCOp [arrSize, len]
|
|
| 3680 | 3677 | boundsCheckFailed <- getCode $
|
| 3681 | 3678 | emitCCallNeverReturns [] (mkLblExpr mkOutOfBoundsAccessLabel) []
|
| 3682 | 3679 | let
|
| ... | ... | @@ -107,14 +107,14 @@ genExpr ctx stg = case stg of |
| 107 | 107 | as <- concatMapM genArg args
|
| 108 | 108 | c <- genCon ctx con as
|
| 109 | 109 | return (c, ExprInline)
|
| 110 | - StgOpApp (StgFCallOp f _) args k
|
|
| 110 | + StgOpApp (StgFCallOp f _ k) args
|
|
| 111 | 111 | -> genForeignCall ctx f k (concatMap typex_expr $ ctxTarget ctx) args
|
| 112 | - StgOpApp (StgPrimOp op) args _k
|
|
| 112 | + StgOpApp (StgPrimOp op) args
|
|
| 113 | 113 | -> genPrimOp ctx op args
|
| 114 | - StgOpApp (StgPrimCallOp c) args k
|
|
| 114 | + StgOpApp (StgPrimCallOp c k) args
|
|
| 115 | 115 | -> genPrimCall ctx c args k
|
| 116 | - StgOpApp (StgTagToEnumOp tyc) [arg] _k -> genTagToEnumOp ctx tyc arg
|
|
| 117 | - StgOpApp op@(StgTagToEnumOp _) args k -> pprPanic "genExpr: StgTagToEnumOp not applied to exactly one argument" (ppr op <+> ppr args <+> ppr (getStgKind k))
|
|
| 116 | + StgOpApp (StgTagToEnumOp tyc) [arg] -> genTagToEnumOp ctx tyc arg
|
|
| 117 | + StgOpApp op@(StgTagToEnumOp _) args -> pprPanic "genExpr: StgTagToEnumOp not applied to exactly one argument" (ppr op <+> ppr args)
|
|
| 118 | 118 | StgCase e b at alts
|
| 119 | 119 | -> genCase ctx b e at alts (liveVars $ stgExprLive False stg)
|
| 120 | 120 | StgLet _ b e -> do
|
| ... | ... | @@ -42,7 +42,7 @@ collectArgs = \case |
| 42 | 42 | -> x : concatMap collectArgsA args
|
| 43 | 43 | StgConApp _con _mn args _ts
|
| 44 | 44 | -> concatMap collectArgsA args
|
| 45 | - StgOpApp _x args _t
|
|
| 45 | + StgOpApp _x args
|
|
| 46 | 46 | -> concatMap collectArgsA args
|
| 47 | 47 | StgCase e _b _a alts
|
| 48 | 48 | -> collectArgsE e ++ concatMap collectArgsAlt alts
|
| ... | ... | @@ -103,7 +103,7 @@ unfloatStringLits' stringLits allBindings = (binderWithoutChanges ++ binderWithU |
| 103 | 103 | -- No args
|
| 104 | 104 | processStgExpr (StgApp _ []) = Nothing
|
| 105 | 105 | processStgExpr (StgConApp _ _ [] _) = Nothing
|
| 106 | - processStgExpr (StgOpApp _ [] _) = Nothing
|
|
| 106 | + processStgExpr (StgOpApp _ []) = Nothing
|
|
| 107 | 107 | |
| 108 | 108 | -- Main targets. Preserving the order of args is important
|
| 109 | 109 | processStgExpr (StgApp fn args@(_:_))
|
| ... | ... | @@ -116,9 +116,9 @@ unfloatStringLits' stringLits allBindings = (binderWithoutChanges ++ binderWithU |
| 116 | 116 | | otherwise = Just (StgConApp dc n unified tys, names)
|
| 117 | 117 | where
|
| 118 | 118 | (unified, names) = substituteArgWithNames args
|
| 119 | - processStgExpr (StgOpApp op args@(_:_) tys)
|
|
| 119 | + processStgExpr (StgOpApp op args@(_:_))
|
|
| 120 | 120 | | isEmptyUniqSet names = Nothing
|
| 121 | - | otherwise = Just (StgOpApp op unified tys, names)
|
|
| 121 | + | otherwise = Just (StgOpApp op unified, names)
|
|
| 122 | 122 | where
|
| 123 | 123 | (unified, names) = substituteArgWithNames args
|
| 124 | 124 |
| ... | ... | @@ -312,7 +312,7 @@ exprRefs :: UniqFM Id CgStgExpr -> CgStgExpr -> Set Id |
| 312 | 312 | exprRefs u = \case
|
| 313 | 313 | StgApp f args -> s f <> l (argRefs u) args
|
| 314 | 314 | StgConApp d _n args _ -> l s [ i | AnId i <- dataConImplicitTyThings d] <> l (argRefs u) args
|
| 315 | - StgOpApp _ args _ -> l (argRefs u) args
|
|
| 315 | + StgOpApp _ args -> l (argRefs u) args
|
|
| 316 | 316 | StgLit {} -> mempty
|
| 317 | 317 | StgCase expr _ _ alts -> exprRefs u expr <> mconcat (fmap (altRefs u) alts)
|
| 318 | 318 | StgLet _ bnd expr -> bindingRefs u bnd <> exprRefs u expr
|
| ... | ... | @@ -400,7 +400,7 @@ stgExprLive includeLHS = \case |
| 400 | 400 | StgApp occ args -> unionDVarSets (unitDVarSet occ : map stgArgLive args)
|
| 401 | 401 | StgLit {} -> emptyDVarSet
|
| 402 | 402 | StgConApp _dc _n args _tys -> unionDVarSets (map stgArgLive args)
|
| 403 | - StgOpApp _op args _ty -> unionDVarSets (map stgArgLive args)
|
|
| 403 | + StgOpApp _op args -> unionDVarSets (map stgArgLive args)
|
|
| 404 | 404 | StgCase e b _at alts
|
| 405 | 405 | | includeLHS -> el `unionDVarSet` delDVarSet al b
|
| 406 | 406 | | otherwise -> delDVarSet al b
|
| ... | ... | @@ -445,11 +445,13 @@ isInlineExpr = \case |
| 445 | 445 | -> True
|
| 446 | 446 | StgConApp{}
|
| 447 | 447 | -> True
|
| 448 | - StgOpApp (StgFCallOp f _) _ _
|
|
| 448 | + StgOpApp (StgFCallOp f _ _) _
|
|
| 449 | 449 | -> isInlineForeignCall f
|
| 450 | - StgOpApp (StgPrimOp op) _ _
|
|
| 450 | + StgOpApp (StgPrimOp op) _
|
|
| 451 | 451 | -> primOpIsReallyInline op
|
| 452 | - StgOpApp (StgPrimCallOp _c) _ _
|
|
| 452 | + StgOpApp (StgPrimCallOp _c _) _
|
|
| 453 | + -> True
|
|
| 454 | + StgOpApp (StgTagToEnumOp _) _c
|
|
| 453 | 455 | -> True
|
| 454 | 456 | StgCase e _ _ alts
|
| 455 | 457 | ->let ie = isInlineExpr e
|