diff options
author | Simon Brenner <olsner@gmail.com> | 2015-09-19 15:23:51 +0200 |
---|---|---|
committer | Thomas Miedema <thomasmiedema@gmail.com> | 2015-09-19 15:23:51 +0200 |
commit | bb0897f60abcce697a1038baba86923eb8baa971 (patch) | |
tree | 23e2b7e9ce92e0d8c6a641833264858aa0923862 /compiler/llvmGen/LlvmCodeGen/Data.hs | |
parent | c8d438fb027cbefa31941d8397539c481a03a74f (diff) | |
download | haskell-wip/D1242.tar.gz |
Implement function-sections for Haskell code, #8405wip/D1242
Summary:
This adds a flag -split-sections that does similar things to -split-objs, but
using sections in single object files instead of relying on the Satanic
Splitter and other abominations. This is very similar to the GCC flags
-ffunction-sections and -fdata-sections.
The --gc-sections linker flag, which allows unused sections to actually
be removed, is added to all link commands (if the linker supports it) so that
space savings from having base compiled with sections can be realized.
Supported both in LLVM and the native code-gen, in theory for all
architectures, but really tested on x86 only.
In the GHC build, a new SplitSections variable enables -split-sections for
relevant parts of the build.
Test Plan: validate with both settings of SplitSections
Reviewers: simonmar, austin, dterei, bgamari
Subscribers: erikd, kgardas, thomie
Differential Revision: https://phabricator.haskell.org/D1242
GHC Trac Issues: #8405
Diffstat (limited to 'compiler/llvmGen/LlvmCodeGen/Data.hs')
-rw-r--r-- | compiler/llvmGen/LlvmCodeGen/Data.hs | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/compiler/llvmGen/LlvmCodeGen/Data.hs b/compiler/llvmGen/LlvmCodeGen/Data.hs index b306748d23..ac93415b06 100644 --- a/compiler/llvmGen/LlvmCodeGen/Data.hs +++ b/compiler/llvmGen/LlvmCodeGen/Data.hs @@ -15,6 +15,7 @@ import LlvmCodeGen.Base import BlockId import CLabel import Cmm +import DynFlags import FastString import Outputable @@ -36,6 +37,7 @@ genLlvmData :: (Section, CmmStatics) -> LlvmM LlvmData genLlvmData (sec, Statics lbl xs) = do label <- strCLabel_llvm lbl static <- mapM genData xs + lmsec <- llvmSection sec let types = map getStatType static strucTy = LMStruct types @@ -45,21 +47,44 @@ genLlvmData (sec, Statics lbl xs) = do link = if (externallyVisibleCLabel lbl) then ExternallyVisible else Internal const = if isSecConstant sec then Constant else Global - varDef = LMGlobalVar label tyAlias link Nothing Nothing const + varDef = LMGlobalVar label tyAlias link lmsec Nothing const globDef = LMGlobal varDef struct return ([globDef], [tyAlias]) -- | Should a data in this section be considered constant isSecConstant :: Section -> Bool -isSecConstant Text = True -isSecConstant ReadOnlyData = True -isSecConstant RelocatableReadOnlyData = True -isSecConstant ReadOnlyData16 = True -isSecConstant Data = False -isSecConstant UninitialisedData = False -isSecConstant (OtherSection _) = False - +isSecConstant (Section t _) = case t of + Text -> True + ReadOnlyData -> True + RelocatableReadOnlyData -> True + ReadOnlyData16 -> True + Data -> False + UninitialisedData -> False + (OtherSection _) -> False + +-- Assumes that we only try to use section splitting on platforms with +-- compatible section naming and toolchain :) +llvmSectionType :: SectionType -> String +llvmSectionType t = case t of + Text -> ".text" + ReadOnlyData -> ".rodata" + RelocatableReadOnlyData -> ".data.rel.ro" + ReadOnlyData16 -> ".rodata.cst16" + Data -> ".data" + UninitialisedData -> ".bss" + (OtherSection _) -> panic "llvmSectionType: unknown section type" + +llvmSection :: Section -> LlvmM LMSection +llvmSection (Section t suffix) = do + dflags <- getDynFlags + let splitSect = gopt Opt_SplitSections dflags + if not splitSect + then return Nothing + else do + lmsuffix <- strCLabel_llvm suffix + let sectype = llvmSectionType t + return (Just (concatFS [fsLit sectype, fsLit ".", lmsuffix])) -- ---------------------------------------------------------------------------- -- * Generate static data |