diff options
| author | Gabor Greif <ggreif@gmail.com> | 2018-01-29 14:34:25 +0100 |
|---|---|---|
| committer | Gabor Greif <ggreif@gmail.com> | 2019-04-15 17:19:03 -0400 |
| commit | be05bd8168b0ea65d63dc0093a5c8781a2528500 (patch) | |
| tree | d45ed24579c4d084c73884da9589da25b8dcf7d8 /compiler/llvmGen/LlvmCodeGen/Data.hs | |
| parent | ed94d3450cbb6ec7a31d9aa37efb7fe93d0559cf (diff) | |
| download | haskell-be05bd8168b0ea65d63dc0093a5c8781a2528500.tar.gz | |
asm-emit-time IND_STATIC elimination
When a new closure identifier is being established to a
local or exported closure already emitted into the same
module, refrain from adding an IND_STATIC closure, and
instead emit an assembly-language alias.
Inter-module IND_STATIC objects still remain, and need to be
addressed by other measures.
Binary-size savings on nofib are around 0.1%.
Diffstat (limited to 'compiler/llvmGen/LlvmCodeGen/Data.hs')
| -rw-r--r-- | compiler/llvmGen/LlvmCodeGen/Data.hs | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs index cabfe76762..3651a88cc6 100644 --- a/compiler/llvmGen/LlvmCodeGen/Data.hs +++ b/compiler/llvmGen/LlvmCodeGen/Data.hs @@ -32,12 +32,41 @@ import qualified Data.ByteString as BS structStr :: LMString structStr = fsLit "_struct" +-- | The LLVM visibility of the label +linkage :: CLabel -> LlvmLinkageType +linkage lbl = if externallyVisibleCLabel lbl + then ExternallyVisible else Internal + -- ---------------------------------------------------------------------------- -- * Top level -- -- | Pass a CmmStatic section to an equivalent Llvm code. genLlvmData :: (Section, CmmStatics) -> LlvmM LlvmData +-- See note [emit-time elimination of static indirections] in CLabel. +genLlvmData (_, Statics alias [CmmStaticLit (CmmLabel lbl), CmmStaticLit ind, _, _]) + | lbl == mkIndStaticInfoLabel + , let labelInd (CmmLabelOff l _) = Just l + labelInd (CmmLabel l) = Just l + labelInd _ = Nothing + , Just ind' <- labelInd ind + , alias `mayRedirectTo` ind' = do + label <- strCLabel_llvm alias + label' <- strCLabel_llvm ind' + let link = linkage alias + link' = linkage ind' + -- the LLVM type we give the alias is an empty struct type + -- but it doesn't really matter, as the pointer is only + -- used for (bit/int)casting. + tyAlias = LMAlias (label `appendFS` structStr, LMStructU []) + + aliasDef = LMGlobalVar label tyAlias link Nothing Nothing Alias + -- we don't know the type of the indirectee here + indType = panic "will be filled by 'aliasify', later" + orig = LMStaticPointer $ LMGlobalVar label' indType link' Nothing Nothing Alias + + pure ([LMGlobal aliasDef $ Just orig], [tyAlias]) + genLlvmData (sec, Statics lbl xs) = do label <- strCLabel_llvm lbl static <- mapM genData xs @@ -45,11 +74,10 @@ genLlvmData (sec, Statics lbl xs) = do let types = map getStatType static strucTy = LMStruct types - tyAlias = LMAlias ((label `appendFS` structStr), strucTy) + tyAlias = LMAlias (label `appendFS` structStr, strucTy) struct = Just $ LMStaticStruc static tyAlias - link = if (externallyVisibleCLabel lbl) - then ExternallyVisible else Internal + link = linkage lbl align = case sec of Section CString _ -> Just 1 _ -> Nothing |
