summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Klebinger <klebinger.andreas@gmx.at>2020-11-27 21:56:55 +0100
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-08 22:43:21 -0500
commit6e3da80055dd7b3fc3bdc576088fdd16129bdac7 (patch)
treee0c3b164c7a899b0be074bea23f9e9e7e3e7d37b
parent69ae10c39bfed1c4f90f34b42aa0630e0fda2b1b (diff)
downloadhaskell-6e3da80055dd7b3fc3bdc576088fdd16129bdac7.tar.gz
Cmm: Make a few types and utility function slightly stricter.
About 0.6% reduction in allocations for the code I was looking at. Not a huge difference but no need to throw away performance.
-rw-r--r--compiler/GHC/Cmm/Expr.hs12
-rw-r--r--compiler/GHC/Cmm/Utils.hs8
2 files changed, 11 insertions, 9 deletions
diff --git a/compiler/GHC/Cmm/Expr.hs b/compiler/GHC/Cmm/Expr.hs
index ab613192ba..574e8a4514 100644
--- a/compiler/GHC/Cmm/Expr.hs
+++ b/compiler/GHC/Cmm/Expr.hs
@@ -53,14 +53,14 @@ import GHC.Types.Basic (Alignment, mkAlignment, alignmentOf)
-----------------------------------------------------------------------------
data CmmExpr
- = CmmLit CmmLit -- Literal
+ = CmmLit !CmmLit -- Literal
| CmmLoad !CmmExpr !CmmType -- Read memory location
| CmmReg !CmmReg -- Contents of register
| CmmMachOp MachOp [CmmExpr] -- Machine operation (+, -, *, etc.)
| CmmStackSlot Area {-# UNPACK #-} !Int
-- addressing expression of a stack slot
-- See Note [CmmStackSlot aliasing]
- | CmmRegOff !CmmReg Int
+ | CmmRegOff !CmmReg !Int
-- CmmRegOff reg i
-- ** is shorthand only, meaning **
-- CmmMachOp (MO_Add rep) [x, CmmLit (CmmInt (fromIntegral i) rep)]
@@ -173,16 +173,16 @@ Now, the assignments of y go away,
-}
data CmmLit
- = CmmInt !Integer Width
+ = CmmInt !Integer !Width
-- Interpretation: the 2's complement representation of the value
-- is truncated to the specified size. This is easier than trying
-- to keep the value within range, because we don't know whether
-- it will be used as a signed or unsigned value (the CmmType doesn't
-- distinguish between signed & unsigned).
- | CmmFloat Rational Width
+ | CmmFloat Rational !Width
| CmmVec [CmmLit] -- Vector literal
| CmmLabel CLabel -- Address of label
- | CmmLabelOff CLabel Int -- Address of label + byte offset
+ | CmmLabelOff CLabel !Int -- Address of label + byte offset
-- Due to limitations in the C backend, the following
-- MUST ONLY be used inside the info table indicated by label2
@@ -191,7 +191,7 @@ data CmmLit
-- Don't use it at all unless tablesNextToCode.
-- It is also used inside the NCG during when generating
-- position-independent code.
- | CmmLabelDiffOff CLabel CLabel Int Width -- label1 - label2 + offset
+ | CmmLabelDiffOff CLabel CLabel !Int !Width -- label1 - label2 + offset
-- In an expression, the width just has the effect of MO_SS_Conv
-- from wordWidth to the desired width.
--
diff --git a/compiler/GHC/Cmm/Utils.hs b/compiler/GHC/Cmm/Utils.hs
index 356fb4e138..3ac8b3c3ac 100644
--- a/compiler/GHC/Cmm/Utils.hs
+++ b/compiler/GHC/Cmm/Utils.hs
@@ -264,9 +264,11 @@ cmmOffset platform e byte_off = case e of
CmmStackSlot area off -> CmmStackSlot area (off - byte_off)
-- note stack area offsets increase towards lower addresses
CmmMachOp (MO_Add rep) [expr, CmmLit (CmmInt byte_off1 _rep)]
- -> CmmMachOp (MO_Add rep) [expr, CmmLit (CmmInt (byte_off1 + toInteger byte_off) rep)]
- _ -> CmmMachOp (MO_Add width) [e, CmmLit (CmmInt (toInteger byte_off) width)]
- where width = cmmExprWidth platform e
+ -> let !lit_off = (byte_off1 + toInteger byte_off)
+ in CmmMachOp (MO_Add rep) [expr, CmmLit (CmmInt lit_off rep)]
+ _ -> let !width = cmmExprWidth platform e
+ in
+ CmmMachOp (MO_Add width) [e, CmmLit (CmmInt (toInteger byte_off) width)]
-- Smart constructor for CmmRegOff. Same caveats as cmmOffset above.
cmmRegOff :: CmmReg -> Int -> CmmExpr