summaryrefslogtreecommitdiff
path: root/compiler/llvmGen/LlvmCodeGen/Data.hs
diff options
context:
space:
mode:
authorDavid Terei <davidterei@gmail.com>2010-06-21 17:49:54 +0000
committerDavid Terei <davidterei@gmail.com>2010-06-21 17:49:54 +0000
commit3aadff5e31bf6b665cf7ae7606c94cdab85624d2 (patch)
tree2fd6f5899646e6d7ed2150fff594f6e7fefdd75b /compiler/llvmGen/LlvmCodeGen/Data.hs
parent09e6aba8000ccf52943ada4fb9ac76e0d93a202f (diff)
downloadhaskell-3aadff5e31bf6b665cf7ae7606c94cdab85624d2.tar.gz
Declare some top level globals to be constant when appropriate
This involved removing the old constant handling mechanism which was fairly hard to use. Now being constant or not is simply a property of a global variable instead of a separate type.
Diffstat (limited to 'compiler/llvmGen/LlvmCodeGen/Data.hs')
-rw-r--r--compiler/llvmGen/LlvmCodeGen/Data.hs25
1 files changed, 19 insertions, 6 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs
index 13da03b840..3cf6cdac85 100644
--- a/compiler/llvmGen/LlvmCodeGen/Data.hs
+++ b/compiler/llvmGen/LlvmCodeGen/Data.hs
@@ -37,8 +37,8 @@ structStr = fsLit "_struct"
-- complete this completely though as we need to pass all CmmStatic
-- sections before all references can be resolved. This last step is
-- done by 'resolveLlvmData'.
-genLlvmData :: [CmmStatic] -> LlvmUnresData
-genLlvmData (CmmDataLabel lbl:xs) =
+genLlvmData :: (Section, [CmmStatic]) -> LlvmUnresData
+genLlvmData (sec, CmmDataLabel lbl:xs) =
let static = map genData xs
label = strCLabel_llvm lbl
@@ -48,10 +48,11 @@ genLlvmData (CmmDataLabel lbl:xs) =
strucTy = LMStruct types
alias = LMAlias (label `appendFS` structStr) strucTy
- in (lbl, alias, static)
+ in (lbl, sec, alias, static)
genLlvmData _ = panic "genLlvmData: CmmData section doesn't start with label!"
+
resolveLlvmDatas :: LlvmEnv -> [LlvmUnresData] -> [LlvmData]
-> (LlvmEnv, [LlvmData])
resolveLlvmDatas env [] ldata
@@ -63,17 +64,29 @@ resolveLlvmDatas env (udata : rest) ldata
-- | Fix up CLabel references now that we should have passed all CmmData.
resolveLlvmData :: LlvmEnv -> LlvmUnresData -> (LlvmEnv, LlvmData)
-resolveLlvmData env (lbl, alias, unres) =
+resolveLlvmData env (lbl, sec, alias, unres) =
let (env', static, refs) = resDatas env unres ([], [])
refs' = catMaybes refs
struct = Just $ LMStaticStruc static alias
label = strCLabel_llvm lbl
link = if (externallyVisibleCLabel lbl)
then ExternallyVisible else Internal
- glob = LMGlobalVar label alias link Nothing Nothing
+ const = isSecConstant sec
+ glob = LMGlobalVar label alias link Nothing Nothing const
in (env', (refs' ++ [(glob, struct)], [alias]))
+-- | Should a data in this section be considered constant
+isSecConstant :: Section -> Bool
+isSecConstant Text = True
+isSecConstant Data = False
+isSecConstant ReadOnlyData = True
+isSecConstant RelocatableReadOnlyData = True
+isSecConstant UninitialisedData = False
+isSecConstant ReadOnlyData16 = True
+isSecConstant (OtherSection _) = False
+
+
-- ----------------------------------------------------------------------------
-- ** Resolve Data/CLabel references
--
@@ -114,7 +127,7 @@ resData env (Left cmm@(CmmLabel l)) =
-- pointer to it.
Just ty' ->
let var = LMGlobalVar label (LMPointer ty')
- ExternallyVisible Nothing Nothing
+ ExternallyVisible Nothing Nothing False
ptr = LMStaticPointer var
in (env, LMPtoI ptr lmty, [Nothing])