X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmUtils.hs;h=a2a2711b550a8990c8dcc91e41bf829bb0b89c13;hb=af452780391355f7008fe97e556ced25a3dd2d21;hp=0c5ab0f43ac109cf89bbcb780e6219c012169b4f;hpb=49c98d143c382a1341e1046f5ca00819a25691ba;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmUtils.hs b/compiler/cmm/CmmUtils.hs index 0c5ab0f..a2a2711 100644 --- a/compiler/cmm/CmmUtils.hs +++ b/compiler/cmm/CmmUtils.hs @@ -18,6 +18,8 @@ module CmmUtils( mkIntCLit, zeroCLit, mkLblExpr, + + loadArgsIntoTemps, maybeAssignTemp, ) where #include "HsVersions.h" @@ -27,6 +29,7 @@ import Cmm import MachOp import OrdList import Outputable +import Unique --------------------------------------------------- -- @@ -175,3 +178,28 @@ zeroCLit = CmmInt 0 wordRep mkLblExpr :: CLabel -> CmmExpr mkLblExpr lbl = CmmLit (CmmLabel lbl) + +--------------------------------------------------- +-- +-- Helpers for foreign call arguments +-- +--------------------------------------------------- + +loadArgsIntoTemps :: [Unique] + -> CmmActuals + -> ([Unique], [CmmStmt], CmmActuals) +loadArgsIntoTemps uniques [] = (uniques, [], []) +loadArgsIntoTemps uniques ((e, hint):args) = + (uniques'', + new_stmts ++ remaining_stmts, + (new_e, hint) : remaining_e) + where + (uniques', new_stmts, new_e) = maybeAssignTemp uniques e + (uniques'', remaining_stmts, remaining_e) = + loadArgsIntoTemps uniques' args + +maybeAssignTemp :: [Unique] -> CmmExpr -> ([Unique], [CmmStmt], CmmExpr) +maybeAssignTemp uniques e + | hasNoGlobalRegs e = (uniques, [], e) + | otherwise = (tail uniques, [CmmAssign local e], CmmReg local) + where local = CmmLocal (LocalReg (head uniques) (cmmExprRep e) KindNonPtr)