1 -----------------------------------------------------------------------------
3 -- Old-style Cmm utilities.
5 -- (c) The University of Glasgow 2004-2006
7 -----------------------------------------------------------------------------
10 CmmStmts, noStmts, oneStmt, mkStmts, plusStmts, stmtList,
13 maybeAssignTemp, loadArgsIntoTemps,
18 #include "HsVersions.h"
25 ---------------------------------------------------
29 ---------------------------------------------------
31 type CmmStmts = OrdList CmmStmt
36 oneStmt :: CmmStmt -> CmmStmts
39 mkStmts :: [CmmStmt] -> CmmStmts
42 plusStmts :: CmmStmts -> CmmStmts -> CmmStmts
45 stmtList :: CmmStmts -> [CmmStmt]
49 ---------------------------------------------------
53 ---------------------------------------------------
55 isNopStmt :: CmmStmt -> Bool
56 -- If isNopStmt returns True, the stmt is definitely a no-op;
57 -- but it might be a no-op even if isNopStmt returns False
58 isNopStmt CmmNop = True
59 isNopStmt (CmmAssign r e) = cheapEqReg r e
60 isNopStmt (CmmStore e1 (CmmLoad e2 _)) = cheapEqExpr e1 e2
63 cheapEqExpr :: CmmExpr -> CmmExpr -> Bool
64 cheapEqExpr (CmmReg r) e = cheapEqReg r e
65 cheapEqExpr (CmmRegOff r 0) e = cheapEqReg r e
66 cheapEqExpr (CmmRegOff r n) (CmmRegOff r' n') = r==r' && n==n'
67 cheapEqExpr _ _ = False
69 cheapEqReg :: CmmReg -> CmmExpr -> Bool
70 cheapEqReg r (CmmReg r') = r==r'
71 cheapEqReg r (CmmRegOff r' 0) = r==r'
72 cheapEqReg _ _ = False
74 ---------------------------------------------------
76 -- Helpers for foreign call arguments
78 ---------------------------------------------------
80 loadArgsIntoTemps :: [Unique]
82 -> ([Unique], [CmmStmt], HintedCmmActuals)
83 loadArgsIntoTemps uniques [] = (uniques, [], [])
84 loadArgsIntoTemps uniques ((CmmHinted e hint):args) =
86 new_stmts ++ remaining_stmts,
87 (CmmHinted new_e hint) : remaining_e)
89 (uniques', new_stmts, new_e) = maybeAssignTemp uniques e
90 (uniques'', remaining_stmts, remaining_e) =
91 loadArgsIntoTemps uniques' args
94 maybeAssignTemp :: [Unique] -> CmmExpr -> ([Unique], [CmmStmt], CmmExpr)
95 maybeAssignTemp uniques e
96 | hasNoGlobalRegs e = (uniques, [], e)
97 | otherwise = (tail uniques, [CmmAssign local e], CmmReg local)
98 where local = CmmLocal (LocalReg (head uniques) (cmmExprType e))