X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FllvmGen%2FLlvmCodeGen%2FBase.hs;h=408a553fd208afb0757f6eef77588d30ce8a20d6;hb=615d88d1912a81ca3bef44010285424f6c454449;hp=5e0df3ef866b0d166e59673152418254460f17b4;hpb=3aadff5e31bf6b665cf7ae7606c94cdab85624d2;p=ghc-hetmet.git diff --git a/compiler/llvmGen/LlvmCodeGen/Base.hs b/compiler/llvmGen/LlvmCodeGen/Base.hs index 5e0df3e..408a553 100644 --- a/compiler/llvmGen/LlvmCodeGen/Base.hs +++ b/compiler/llvmGen/LlvmCodeGen/Base.hs @@ -14,7 +14,7 @@ module LlvmCodeGen.Base ( cmmToLlvmType, widthToLlvmFloat, widthToLlvmInt, llvmFunTy, llvmFunSig, llvmStdFunAttrs, llvmFunAlign, llvmInfAlign, - llvmPtrBits, llvmGhcCC, + llvmPtrBits, mkLlvmFunc, tysToParams, strCLabel_llvm, genCmmLabelRef, genStringLabelRef @@ -25,14 +25,14 @@ module LlvmCodeGen.Base ( import Llvm import LlvmCodeGen.Regs -import CgUtils ( activeStgRegs ) import CLabel +import CgUtils ( activeStgRegs ) import Cmm - +import Constants import FastString import qualified Outputable as Outp -import Unique import UniqFM +import Unique -- ---------------------------------------------------------------------------- -- * Some Data Types @@ -42,7 +42,7 @@ type LlvmCmmTop = GenCmmTop LlvmData [CmmStatic] (ListGraph LlvmStatement) type LlvmBasicBlock = GenBasicBlock LlvmStatement -- | Unresolved code. --- Of the form: (data label, data type, unresovled data) +-- Of the form: (data label, data type, unresolved data) type LlvmUnresData = (CLabel, Section, LlvmType, [UnresStatic]) -- | Top level LLVM Data (globals and type aliases) @@ -82,25 +82,34 @@ llvmGhcCC = CC_Ncc 10 -- | Llvm Function type for Cmm function llvmFunTy :: LlvmType -llvmFunTy - = LMFunction $ - LlvmFunctionDecl (fsLit "a") ExternallyVisible llvmGhcCC LMVoid FixedArgs - (Left $ map getVarType llvmFunArgs) llvmFunAlign +llvmFunTy = LMFunction $ llvmFunSig' (fsLit "a") ExternallyVisible -- | Llvm Function signature llvmFunSig :: CLabel -> LlvmLinkageType -> LlvmFunctionDecl -llvmFunSig lbl link - = let n = strCLabel_llvm lbl - in LlvmFunctionDecl n link llvmGhcCC LMVoid FixedArgs - (Right llvmFunArgs) llvmFunAlign +llvmFunSig lbl link = llvmFunSig' (strCLabel_llvm lbl) link + +llvmFunSig' :: LMString -> LlvmLinkageType -> LlvmFunctionDecl +llvmFunSig' lbl link + = let toParams x | isPointer x = (x, [NoAlias, NoCapture]) + | otherwise = (x, []) + in LlvmFunctionDecl lbl link llvmGhcCC LMVoid FixedArgs + (map (toParams . getVarType) llvmFunArgs) llvmFunAlign + +-- | Create a Haskell function in LLVM. +mkLlvmFunc :: CLabel -> LlvmLinkageType -> LMSection -> LlvmBlocks + -> LlvmFunction +mkLlvmFunc lbl link sec blks + = let funDec = llvmFunSig lbl link + funArgs = map (fsLit . getPlainName) llvmFunArgs + in LlvmFunction funDec funArgs llvmStdFunAttrs sec blks -- | Alignment to use for functions llvmFunAlign :: LMAlign -llvmFunAlign = Just 4 +llvmFunAlign = Just wORD_SIZE -- | Alignment to use for into tables llvmInfAlign :: LMAlign -llvmInfAlign = Just 4 +llvmInfAlign = Just wORD_SIZE -- | A Function's arguments llvmFunArgs :: [LlvmVar] @@ -110,6 +119,11 @@ llvmFunArgs = map lmGlobalRegArg activeStgRegs llvmStdFunAttrs :: [LlvmFuncAttr] llvmStdFunAttrs = [NoUnwind] +-- | Convert a list of types to a list of function parameters +-- (each with no parameter attributes) +tysToParams :: [LlvmType] -> [LlvmParameter] +tysToParams = map (\ty -> (ty, [])) + -- | Pointer width llvmPtrBits :: Int llvmPtrBits = widthInBits $ typeWidth gcWord