Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed code dealing with references in static data

It's not needed anymore, as the streaming change now allows flexible
treatment of forward references.
  • Loading branch information...
commit 6f29107a0050cd3d597ba3d002f5f7312f4b7128 1 parent 7111249
@scpmw authored
View
28 compiler/llvmGen/LlvmCodeGen.hs
@@ -117,7 +117,7 @@ llvmGroupLlvmGens location (cmm, tick_map) = do
cdata <- fmap catMaybes $ mapM split cmm
{-# SCC "llvm_datas_gen" #-}
- cmmDataLlvmGens cdata []
+ cmmDataLlvmGens cdata
{-# SCC "llvm_procs_gen" #-}
cmmProcLlvmGens location cmm tick_map 1
return tick_map
@@ -125,19 +125,19 @@ llvmGroupLlvmGens location (cmm, tick_map) = do
-- -----------------------------------------------------------------------------
-- | Do LLVM code generation on all these Cmms data sections.
--
-cmmDataLlvmGens :: [(Section,CmmStatics)]
- -> [LlvmUnresData] -> LlvmM ()
-
-cmmDataLlvmGens [] lmdata
- = do lmdata' <- resolveLlvmDatas (reverse lmdata)
- let lmdoc = vcat $ map pprLlvmData lmdata'
- renderLlvm lmdoc
-
-cmmDataLlvmGens (cmm:cmms) lmdata
- = do lmdata'@(l, _, ty, _) <- genLlvmData cmm
- l' <- strCLabel_llvm l
- funInsert l' ty
- cmmDataLlvmGens cmms (lmdata' : lmdata)
+cmmDataLlvmGens :: [(Section,CmmStatics)] -> LlvmM ()
+
+cmmDataLlvmGens statics
+ = do lmdatas <- mapM genLlvmData statics
+
+ let (gss, tss) = unzip lmdatas
+
+ let regGlobal (LMGlobal (LMGlobalVar l ty _ _ _ _) _)
+ = funInsert l ty
+ regGlobal _ = return ()
+ mapM_ regGlobal (concat gss)
+
+ renderLlvm $ pprLlvmData (concat gss, concat tss)
-- -----------------------------------------------------------------------------
View
104 compiler/llvmGen/LlvmCodeGen/Data.hs
@@ -3,7 +3,7 @@
--
module LlvmCodeGen.Data (
- genLlvmData, resolveLlvmDatas, resolveLlvmData
+ genLlvmData
) where
#include "HsVersions.h"
@@ -30,37 +30,22 @@ structStr = fsLit "_struct"
-- * Top level
--
--- | Pass a CmmStatic section to an equivalent Llvm code. Can't
--- 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 :: (Section, CmmStatics) -> LlvmM LlvmUnresData
+-- | Pass a CmmStatic section to an equivalent Llvm code.
+genLlvmData :: (Section, CmmStatics) -> LlvmM LlvmData
genLlvmData (sec, Statics lbl xs) = do
label <- strCLabel_llvm lbl
- let static = map genData xs
-
- types = map getStatTypes static
- getStatTypes (Left x) = cmmToLlvmType $ cmmLitType x
- getStatTypes (Right x) = getStatType x
+ static <- mapM genData xs
+ let types = map getStatType static
strucTy = LMStruct types
alias = LMAlias ((label `appendFS` structStr), strucTy)
- return (lbl, sec, alias, static)
-
-
-resolveLlvmDatas :: [LlvmUnresData] -> LlvmM [LlvmData]
-resolveLlvmDatas = mapM resolveLlvmData
--- | Fix up CLabel references now that we should have passed all CmmData.
-resolveLlvmData :: LlvmUnresData -> LlvmM LlvmData
-resolveLlvmData (lbl, sec, alias, unres) = do
- label <- strCLabel_llvm lbl
- static <- resDatas unres
- let struct = Just $ LMStaticStruc static alias
+ struct = Just $ LMStaticStruc static alias
link = if (externallyVisibleCLabel lbl)
then ExternallyVisible else Internal
const = if isSecConstant sec then Constant else Global
glob = LMGlobalVar label alias link Nothing Nothing const
+
return ([LMGlobal glob struct], [alias])
-- | Should a data in this section be considered constant
@@ -75,58 +60,19 @@ isSecConstant (OtherSection _) = False
-- ----------------------------------------------------------------------------
--- ** Resolve Data/CLabel references
---
-
--- | Resolve data list
-resDatas :: [UnresStatic] -> LlvmM [LlvmStatic]
-
-resDatas cmms = mapM resData cmms
-
--- | Resolve an individual static label if it needs to be.
---
--- We check the 'LlvmEnv' to see if the reference has been defined in this
--- module. If it has we can retrieve its type and make a pointer, otherwise
--- we introduce a generic external definition for the referenced label and
--- then make a pointer (see @getCmmStatic@).
-resData :: UnresStatic -> LlvmM LlvmStatic
-
-resData (Right stat) = return stat
-
-resData (Left cmm@(CmmLabel l)) = do
- var <- getGlobalPtr =<< strCLabel_llvm l
- let ptr = LMStaticPointer var
- lmty = cmmToLlvmType $ cmmLitType cmm
- return $ LMPtoI ptr lmty
-
-resData (Left (CmmLabelOff label off)) = do
- var <- resData (Left (CmmLabel label))
- let offset = LMStaticLit $ LMIntLit (toInteger off) llvmWord
- return $ LMAdd var offset
-
-resData (Left (CmmLabelDiffOff l1 l2 off)) = do
- var1 <- resData (Left (CmmLabel l1))
- var2 <- resData (Left (CmmLabel l2))
- let var = LMSub var1 var2
- offset = LMStaticLit $ LMIntLit (toInteger off) llvmWord
- return $ LMAdd var offset
-
-resData _ = panic "resData: Non CLabel expr as left type!"
-
--- ----------------------------------------------------------------------------
-- * Generate static data
--
-- | Handle static data
-genData :: CmmStatic -> UnresStatic
+genData :: CmmStatic -> LlvmM LlvmStatic
-genData (CmmString str) =
+genData (CmmString str) = do
let v = map (\x -> LMStaticLit $ LMIntLit (fromIntegral x) i8) str
ve = v ++ [LMStaticLit $ LMIntLit 0 i8]
- in Right $ LMStaticArray ve (LMArray (length ve) i8)
+ return $ LMStaticArray ve (LMArray (length ve) i8)
genData (CmmUninitialised bytes)
- = Right $ LMUninitType (LMArray bytes i8)
+ = return $ LMUninitType (LMArray bytes i8)
genData (CmmStaticLit lit)
= genStaticLit lit
@@ -135,19 +81,33 @@ genData (CmmStaticLit lit)
--
-- Will either generate the code or leave it unresolved if it is a 'CLabel'
-- which isn't yet known.
-genStaticLit :: CmmLit -> UnresStatic
+genStaticLit :: CmmLit -> LlvmM LlvmStatic
genStaticLit (CmmInt i w)
- = Right $ LMStaticLit (LMIntLit i (LMInt $ widthInBits w))
+ = return $ LMStaticLit (LMIntLit i (LMInt $ widthInBits w))
genStaticLit (CmmFloat r w)
- = Right $ LMStaticLit (LMFloatLit (fromRational r) (widthToLlvmFloat w))
+ = return $ LMStaticLit (LMFloatLit (fromRational r) (widthToLlvmFloat w))
-- Leave unresolved, will fix later
-genStaticLit c@(CmmLabel _ ) = Left $ c
-genStaticLit c@(CmmLabelOff _ _) = Left $ c
-genStaticLit c@(CmmLabelDiffOff _ _ _) = Left $ c
+genStaticLit cmm@(CmmLabel l) = do
+ var <- getGlobalPtr =<< strCLabel_llvm l
+ let ptr = LMStaticPointer var
+ lmty = cmmToLlvmType $ cmmLitType cmm
+ return $ LMPtoI ptr lmty
+
+genStaticLit (CmmLabelOff label off) = do
+ var <- genStaticLit (CmmLabel label)
+ let offset = LMStaticLit $ LMIntLit (toInteger off) llvmWord
+ return $ LMAdd var offset
+
+genStaticLit (CmmLabelDiffOff l1 l2 off) = do
+ var1 <- genStaticLit (CmmLabel l1)
+ var2 <- genStaticLit (CmmLabel l2)
+ let var = LMSub var1 var2
+ offset = LMStaticLit $ LMIntLit (toInteger off) llvmWord
+ return $ LMAdd var offset
-genStaticLit (CmmBlock b) = Left $ CmmLabel $ infoTblLbl b
+genStaticLit (CmmBlock b) = genStaticLit $ CmmLabel $ infoTblLbl b
genStaticLit (CmmHighStackMark)
= panic "genStaticLit: CmmHighStackMark unsupported!"
View
4 compiler/llvmGen/LlvmCodeGen/Ppr.hs
@@ -108,8 +108,7 @@ pprLlvmCmmDecl count (CmmProc mb_info entry_lbl (ListGraph blks))
-- | Pretty print CmmStatic
pprInfoTable :: Int -> CLabel -> CmmStatics -> LlvmM (SDoc, [LlvmVar])
pprInfoTable count info_lbl stat
- = do unres <- genLlvmData (Text, stat)
- (ldata, ltypes) <- resolveLlvmData unres
+ = do (ldata, ltypes) <- genLlvmData (Text, stat)
let setSection (LMGlobal (LMGlobalVar _ ty l _ _ c) d) = do
lbl <- strCLabel_llvm info_lbl
@@ -117,6 +116,7 @@ pprInfoTable count info_lbl stat
ilabel = lbl `appendFS` fsLit iTableSuf
gv = LMGlobalVar ilabel ty l sec llvmInfAlign c
v = if l == Internal then [gv] else []
+ funInsert ilabel ty
return (LMGlobal gv d, v)
setSection v = return (v,[])
Please sign in to comment.
Something went wrong with that request. Please try again.