summaryrefslogtreecommitdiff
path: root/compiler/GHC/CmmToAsm/SPARC
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-03-09 19:59:01 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-03-19 12:16:49 -0400
commit64f207566931469648e791df4f0f0384d45cddd0 (patch)
tree58e8a6e27d192368b1ddbc47e9bb89046b2a24a4 /compiler/GHC/CmmToAsm/SPARC
parentb03fd3bcd4ff14aed2942275c3b0db5392dc913c (diff)
downloadhaskell-64f207566931469648e791df4f0f0384d45cddd0.tar.gz
Refactoring: use Platform instead of DynFlags when possible
Metric Decrease: ManyConstructors T12707 T13035 T1969
Diffstat (limited to 'compiler/GHC/CmmToAsm/SPARC')
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/CodeGen.hs54
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/CodeGen/Amode.hs4
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/CodeGen/Base.hs7
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/CodeGen/CondCode.hs6
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen32.hs16
-rw-r--r--compiler/GHC/CmmToAsm/SPARC/Ppr.hs19
6 files changed, 51 insertions, 55 deletions
diff --git a/compiler/GHC/CmmToAsm/SPARC/CodeGen.hs b/compiler/GHC/CmmToAsm/SPARC/CodeGen.hs
index 2580ea4014..67177ea0c6 100644
--- a/compiler/GHC/CmmToAsm/SPARC/CodeGen.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/CodeGen.hs
@@ -36,7 +36,8 @@ import GHC.CmmToAsm.SPARC.Regs
import GHC.CmmToAsm.SPARC.Stack
import GHC.CmmToAsm.Instr
import GHC.CmmToAsm.Format
-import GHC.CmmToAsm.Monad ( NatM, getNewRegNat, getNewLabelNat )
+import GHC.CmmToAsm.Monad ( NatM, getNewRegNat, getNewLabelNat, getPlatform, getConfig )
+import GHC.CmmToAsm.Config
-- Our intermediate code:
import GHC.Cmm.BlockId
@@ -123,7 +124,8 @@ stmtsToInstrs stmts
stmtToInstrs :: CmmNode e x -> NatM InstrBlock
stmtToInstrs stmt = do
- dflags <- getDynFlags
+ platform <- getPlatform
+ config <- getConfig
case stmt of
CmmComment s -> return (unitOL (COMMENT s))
CmmTick {} -> return nilOL
@@ -133,14 +135,14 @@ stmtToInstrs stmt = do
| isFloatType ty -> assignReg_FltCode format reg src
| isWord64 ty -> assignReg_I64Code reg src
| otherwise -> assignReg_IntCode format reg src
- where ty = cmmRegType dflags reg
+ where ty = cmmRegType platform reg
format = cmmTypeFormat ty
CmmStore addr src
| isFloatType ty -> assignMem_FltCode format addr src
| isWord64 ty -> assignMem_I64Code addr src
| otherwise -> assignMem_IntCode format addr src
- where ty = cmmExprType dflags src
+ where ty = cmmExprType platform src
format = cmmTypeFormat ty
CmmUnsafeForeignCall target result_regs args
@@ -151,8 +153,7 @@ stmtToInstrs stmt = do
b1 <- genCondJump true arg
b2 <- genBranch false
return (b1 `appOL` b2)
- CmmSwitch arg ids -> do dflags <- getDynFlags
- genSwitch dflags arg ids
+ CmmSwitch arg ids -> genSwitch config arg ids
CmmCall { cml_target = arg } -> genJump arg
_
@@ -180,8 +181,8 @@ temporary, then do the other computation, and then use the temporary:
-- | Convert a BlockId to some CmmStatic data
-jumpTableEntry :: DynFlags -> Maybe BlockId -> CmmStatic
-jumpTableEntry dflags Nothing = CmmStaticLit (CmmInt 0 (wordWidth dflags))
+jumpTableEntry :: Platform -> Maybe BlockId -> CmmStatic
+jumpTableEntry platform Nothing = CmmStaticLit (CmmInt 0 (wordWidth platform))
jumpTableEntry _ (Just blockid) = CmmStaticLit (CmmLabel blockLabel)
where blockLabel = blockLbl blockid
@@ -208,9 +209,9 @@ assignMem_IntCode pk addr src = do
assignReg_IntCode :: Format -> CmmReg -> CmmExpr -> NatM InstrBlock
assignReg_IntCode _ reg src = do
- dflags <- getDynFlags
+ platform <- getPlatform
r <- getRegister src
- let dst = getRegisterReg (targetPlatform dflags) reg
+ let dst = getRegisterReg platform reg
return $ case r of
Any _ code -> code dst
Fixed _ freg fcode -> fcode `snocOL` OR False g0 (RIReg freg) dst
@@ -220,12 +221,12 @@ assignReg_IntCode _ reg src = do
-- Floating point assignment to memory
assignMem_FltCode :: Format -> CmmExpr -> CmmExpr -> NatM InstrBlock
assignMem_FltCode pk addr src = do
- dflags <- getDynFlags
+ platform <- getPlatform
Amode dst__2 code1 <- getAmode addr
(src__2, code2) <- getSomeReg src
tmp1 <- getNewRegNat pk
let
- pk__2 = cmmExprType dflags src
+ pk__2 = cmmExprType platform src
code__2 = code1 `appOL` code2 `appOL`
if formatToWidth pk == typeWidth pk__2
then unitOL (ST pk src__2 dst__2)
@@ -236,8 +237,7 @@ assignMem_FltCode pk addr src = do
-- Floating point assignment to a register/temporary
assignReg_FltCode :: Format -> CmmReg -> CmmExpr -> NatM InstrBlock
assignReg_FltCode pk dstCmmReg srcCmmExpr = do
- dflags <- getDynFlags
- let platform = targetPlatform dflags
+ platform <- getPlatform
srcRegister <- getRegister srcCmmExpr
let dstReg = getRegisterReg platform dstCmmReg
@@ -309,13 +309,13 @@ genCondJump bid bool = do
-- -----------------------------------------------------------------------------
-- Generating a table-branch
-genSwitch :: DynFlags -> CmmExpr -> SwitchTargets -> NatM InstrBlock
-genSwitch dflags expr targets
- | positionIndependent dflags
+genSwitch :: NCGConfig -> CmmExpr -> SwitchTargets -> NatM InstrBlock
+genSwitch config expr targets
+ | ncgPIC config
= error "MachCodeGen: sparc genSwitch PIC not finished\n"
| otherwise
- = do (e_reg, e_code) <- getSomeReg (cmmOffset dflags expr offset)
+ = do (e_reg, e_code) <- getSomeReg (cmmOffset (ncgPlatform config) expr offset)
base_reg <- getNewRegNat II32
offset_reg <- getNewRegNat II32
@@ -338,10 +338,10 @@ genSwitch dflags expr targets
, NOP ]
where (offset, ids) = switchTargetsToTable targets
-generateJumpTableForInstr :: DynFlags -> Instr
+generateJumpTableForInstr :: Platform -> Instr
-> Maybe (NatCmmDecl RawCmmStatics Instr)
-generateJumpTableForInstr dflags (JMP_TBL _ ids label) =
- let jumpTable = map (jumpTableEntry dflags) ids
+generateJumpTableForInstr platform (JMP_TBL _ ids label) =
+ let jumpTable = map (jumpTableEntry platform) ids
in Just (CmmData (Section ReadOnlyData label) (RawCmmStatics label jumpTable))
generateJumpTableForInstr _ _ = Nothing
@@ -469,21 +469,21 @@ genCCall target dest_regs args
-- | Generate code to calculate an argument, and move it into one
-- or two integer vregs.
arg_to_int_vregs :: CmmExpr -> NatM (OrdList Instr, [Reg])
-arg_to_int_vregs arg = do dflags <- getDynFlags
- arg_to_int_vregs' dflags arg
+arg_to_int_vregs arg = do platform <- getPlatform
+ arg_to_int_vregs' platform arg
-arg_to_int_vregs' :: DynFlags -> CmmExpr -> NatM (OrdList Instr, [Reg])
-arg_to_int_vregs' dflags arg
+arg_to_int_vregs' :: Platform -> CmmExpr -> NatM (OrdList Instr, [Reg])
+arg_to_int_vregs' platform arg
-- If the expr produces a 64 bit int, then we can just use iselExpr64
- | isWord64 (cmmExprType dflags arg)
+ | isWord64 (cmmExprType platform arg)
= do (ChildCode64 code r_lo) <- iselExpr64 arg
let r_hi = getHiVRegFromLo r_lo
return (code, [r_hi, r_lo])
| otherwise
= do (src, code) <- getSomeReg arg
- let pk = cmmExprType dflags arg
+ let pk = cmmExprType platform arg
case cmmTypeFormat pk of
diff --git a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Amode.hs b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Amode.hs
index d6c9d7b360..75eba25023 100644
--- a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Amode.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Amode.hs
@@ -27,8 +27,8 @@ getAmode
-> NatM Amode
getAmode tree@(CmmRegOff _ _)
- = do dflags <- getDynFlags
- getAmode (mangleIndexTree dflags tree)
+ = do platform <- getPlatform
+ getAmode (mangleIndexTree platform tree)
getAmode (CmmMachOp (MO_Sub _) [x, CmmLit (CmmInt i _)])
| fits13Bits (-i)
diff --git a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Base.hs b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Base.hs
index cf249303e4..f00e60ca93 100644
--- a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Base.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Base.hs
@@ -23,7 +23,6 @@ import GHC.CmmToAsm.Format
import GHC.Platform.Reg
import GHC.Platform.Regs
-import GHC.Driver.Session
import GHC.Cmm
import GHC.Cmm.Ppr.Expr () -- For Outputable instances
import GHC.Platform
@@ -109,11 +108,11 @@ getRegisterReg platform (CmmGlobal mid)
-- Expand CmmRegOff. ToDo: should we do it this way around, or convert
-- CmmExprs into CmmRegOff?
-mangleIndexTree :: DynFlags -> CmmExpr -> CmmExpr
+mangleIndexTree :: Platform -> CmmExpr -> CmmExpr
-mangleIndexTree dflags (CmmRegOff reg off)
+mangleIndexTree platform (CmmRegOff reg off)
= CmmMachOp (MO_Add width) [CmmReg reg, CmmLit (CmmInt (fromIntegral off) width)]
- where width = typeWidth (cmmRegType dflags reg)
+ where width = typeWidth (cmmRegType platform reg)
mangleIndexTree _ _
= panic "SPARC.CodeGen.Base.mangleIndexTree: no match"
diff --git a/compiler/GHC/CmmToAsm/SPARC/CodeGen/CondCode.hs b/compiler/GHC/CmmToAsm/SPARC/CodeGen/CondCode.hs
index e501d799f2..3f8912a9c4 100644
--- a/compiler/GHC/CmmToAsm/SPARC/CodeGen/CondCode.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/CodeGen/CondCode.hs
@@ -87,15 +87,15 @@ condIntCode cond x y = do
condFltCode :: Cond -> CmmExpr -> CmmExpr -> NatM CondCode
condFltCode cond x y = do
- dflags <- getDynFlags
+ platform <- getPlatform
(src1, code1) <- getSomeReg x
(src2, code2) <- getSomeReg y
tmp <- getNewRegNat FF64
let
promote x = FxTOy FF32 FF64 x tmp
- pk1 = cmmExprType dflags x
- pk2 = cmmExprType dflags y
+ pk1 = cmmExprType platform x
+ pk2 = cmmExprType platform y
code__2 =
if pk1 `cmmEqType` pk2 then
diff --git a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen32.hs b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen32.hs
index ee67bd4a9d..8d2c6c33f6 100644
--- a/compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen32.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/CodeGen/Gen32.hs
@@ -26,7 +26,6 @@ import GHC.Platform.Reg
import GHC.Cmm
import Control.Monad (liftM)
-import GHC.Driver.Session
import OrdList
import Outputable
@@ -49,14 +48,13 @@ getSomeReg expr = do
getRegister :: CmmExpr -> NatM Register
getRegister (CmmReg reg)
- = do dflags <- getDynFlags
- let platform = targetPlatform dflags
- return (Fixed (cmmTypeFormat (cmmRegType dflags reg))
+ = do platform <- getPlatform
+ return (Fixed (cmmTypeFormat (cmmRegType platform reg))
(getRegisterReg platform reg) nilOL)
getRegister tree@(CmmRegOff _ _)
- = do dflags <- getDynFlags
- getRegister (mangleIndexTree dflags tree)
+ = do platform <- getPlatform
+ getRegister (mangleIndexTree platform tree)
getRegister (CmmMachOp (MO_UU_Conv W64 W32)
[CmmMachOp (MO_U_Shr W64) [x,CmmLit (CmmInt 32 _)]]) = do
@@ -483,15 +481,15 @@ trivialFCode
-> NatM Register
trivialFCode pk instr x y = do
- dflags <- getDynFlags
+ platform <- getPlatform
(src1, code1) <- getSomeReg x
(src2, code2) <- getSomeReg y
tmp <- getNewRegNat FF64
let
promote x = FxTOy FF32 FF64 x tmp
- pk1 = cmmExprType dflags x
- pk2 = cmmExprType dflags y
+ pk1 = cmmExprType platform x
+ pk2 = cmmExprType platform y
code__2 dst =
if pk1 `cmmEqType` pk2 then
diff --git a/compiler/GHC/CmmToAsm/SPARC/Ppr.hs b/compiler/GHC/CmmToAsm/SPARC/Ppr.hs
index fc382a5c10..566b23c1d6 100644
--- a/compiler/GHC/CmmToAsm/SPARC/Ppr.hs
+++ b/compiler/GHC/CmmToAsm/SPARC/Ppr.hs
@@ -98,7 +98,7 @@ pprBasicBlock platform info_env (BasicBlock blockid instrs)
Nothing -> empty
Just (RawCmmStatics info_lbl info) ->
pprAlignForSection Text $$
- vcat (map pprData info) $$
+ vcat (map (pprData platform) info) $$
pprLabel platform info_lbl
@@ -113,12 +113,12 @@ pprDatas _platform (RawCmmStatics alias [CmmStaticLit (CmmLabel lbl), CmmStaticL
, alias `mayRedirectTo` ind'
= pprGloblDecl alias
$$ text ".equiv" <+> ppr alias <> comma <> ppr (CmmLabel ind')
-pprDatas platform (RawCmmStatics lbl dats) = vcat (pprLabel platform lbl : map pprData dats)
+pprDatas platform (RawCmmStatics lbl dats) = vcat (pprLabel platform lbl : map (pprData platform) dats)
-pprData :: CmmStatic -> SDoc
-pprData (CmmString str) = pprBytes str
-pprData (CmmUninitialised bytes) = text ".skip " <> int bytes
-pprData (CmmStaticLit lit) = pprDataItem lit
+pprData :: Platform -> CmmStatic -> SDoc
+pprData _ (CmmString str) = pprBytes str
+pprData _ (CmmUninitialised bytes) = text ".skip " <> int bytes
+pprData platform (CmmStaticLit lit) = pprDataItem platform lit
pprGloblDecl :: CLabel -> SDoc
pprGloblDecl lbl
@@ -345,10 +345,9 @@ pprAlignForSection seg =
OtherSection _ -> panic "PprMach.pprSectionHeader: unknown section")
-- | Pretty print a data item.
-pprDataItem :: CmmLit -> SDoc
-pprDataItem lit
- = sdocWithDynFlags $ \dflags ->
- vcat (ppr_item (cmmTypeFormat $ cmmLitType dflags lit) lit)
+pprDataItem :: Platform -> CmmLit -> SDoc
+pprDataItem platform lit
+ = vcat (ppr_item (cmmTypeFormat $ cmmLitType platform lit) lit)
where
imm = litToImm lit