X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fcmm%2FCmmUtils.hs;h=1922ee05c4ce3616a44e743c7b559f47118825d4;hb=08652e67c4d5d9a40687f93c286021a867c1bca0;hp=0c5ab0f43ac109cf89bbcb780e6219c012169b4f;hpb=49c98d143c382a1341e1046f5ca00819a25691ba;p=ghc-hetmet.git diff --git a/compiler/cmm/CmmUtils.hs b/compiler/cmm/CmmUtils.hs index 0c5ab0f..1922ee0 100644 --- a/compiler/cmm/CmmUtils.hs +++ b/compiler/cmm/CmmUtils.hs @@ -1,3 +1,10 @@ +{-# OPTIONS -w #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + ----------------------------------------------------------------------------- -- -- Cmm utilities. @@ -18,6 +25,8 @@ module CmmUtils( mkIntCLit, zeroCLit, mkLblExpr, + + loadArgsIntoTemps, maybeAssignTemp, ) where #include "HsVersions.h" @@ -27,6 +36,7 @@ import Cmm import MachOp import OrdList import Outputable +import Unique --------------------------------------------------- -- @@ -118,6 +128,7 @@ cmmOffsetExpr e byte_off = CmmMachOp (MO_Add (cmmExprRep e)) [e, byte_off] -- a later optimisation step on Cmm). -- cmmOffset :: CmmExpr -> Int -> CmmExpr +cmmOffset e 0 = e cmmOffset (CmmReg reg) byte_off = cmmRegOff reg byte_off cmmOffset (CmmRegOff reg m) byte_off = cmmRegOff reg (m+byte_off) cmmOffset (CmmLit lit) byte_off = CmmLit (cmmOffsetLit lit byte_off) @@ -175,3 +186,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 ((CmmKinded e hint):args) = + (uniques'', + new_stmts ++ remaining_stmts, + (CmmKinded 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) GCKindNonPtr)