[GHC] #8996: mark more things as const in C codegen

GHC ghc-devs at haskell.org
Mon Apr 14 20:02:44 UTC 2014


#8996: mark more things as const in C codegen
-------------------------------------------+-------------------------------
       Reporter:  slyfox                   |             Owner:
           Type:  feature request          |            Status:  new
       Priority:  normal                   |         Milestone:
      Component:  Compiler (CodeGen)       |           Version:  7.8.2
       Keywords:                           |  Operating System:
   Architecture:  Unknown/Multiple         |  Unknown/Multiple
     Difficulty:  Easy (less than 1 hour)  |   Type of failure:
     Blocked By:                           |  None/Unknown
Related Tickets:                           |         Test Case:
                                           |          Blocking:
-------------------------------------------+-------------------------------
 Recently i've tried to build ghc-7.8.2 on ia64 and
 it overflows so called "short data" section.
 (it's where global 'static' variables live).

 I've looked at low-hanging fruits of squashing such global "variables".
 One source of them seems to be a string literal.

 Consider one-line module:
 {{{
     module B (v) where v = "hello"
 }}}
 in '''-fvia-C''' (or unreg) mode it generates code like
 {{{
     static char gibberish_str[] = "hello";
 }}}

 It uselessly eats data section.
 The patch switches generator to emit:
 {{{
     static const char gibberish_str[] = "hello";
 }}}

 Some notes:
 1. as far as I see native codegens already put ot to .rodata,
 thus it should be safe.
 2. I likely didn't cover more cases, like
   - RelocatableReadOnlyData
   - and mysterious '''pprTop (CmmData _section (Statics lbl
 [CmmUninitialised size]))'''

 Size of unreg-stage2 on amd64 before and after the patch:
 {{{
 $ size inplace/lib/bin/ghc-stage2 (unpatched)
    text    data     bss     dec     hex filename
 81986382        20776344          44096 102806822       620b526
 inplace/lib/bin/ghc-stage2
 $ size inplace/lib/bin/ghc-stage2 (patched)
    text    data     bss     dec     hex filename
 83648494        19062936          44096 102755526       61fecc6
 inplace/lib/bin/ghc-stage2
 }}}

 Text section increased for 1.6MBs (consts moved here, likely .rodata
 actually),
 data section decreased for 1.7MBs.

 I think with minor fiddling with linker flags we can merge equal constants
 later on.

 Thanks!

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8996>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list