X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fcmm%2FCmmUtils.hs;h=9f46217ba1df171df1596218f446d56971e7b013;hp=a04935b279e0da9b423b275e7192711ff4c2a2e3;hb=ad94d40948668032189ad22a0ad741ac1f645f50;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1 diff --git a/compiler/cmm/CmmUtils.hs b/compiler/cmm/CmmUtils.hs index a04935b..9f46217 100644 --- a/compiler/cmm/CmmUtils.hs +++ b/compiler/cmm/CmmUtils.hs @@ -2,10 +2,17 @@ -- -- Cmm utilities. -- --- (c) The University of Glasgow 2004 +-- (c) The University of Glasgow 2004-2006 -- ----------------------------------------------------------------------------- +{-# 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/CodingStyle#Warnings +-- for details + module CmmUtils( CmmStmts, noStmts, oneStmt, mkStmts, plusStmts, stmtList, isNopStmt, @@ -18,15 +25,18 @@ module CmmUtils( mkIntCLit, zeroCLit, mkLblExpr, + + loadArgsIntoTemps, maybeAssignTemp, ) where #include "HsVersions.h" -import CLabel ( CLabel ) +import CLabel import Cmm import MachOp import OrdList import Outputable +import Unique --------------------------------------------------- -- @@ -175,3 +185,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)