mark more things as const in C codegen
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:
- as far as I see native codegens already put ot to .rodata,
thus it should be safe.
- 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!
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.8.2 |
| Type | FeatureRequest |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (CodeGen) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | simonmar |
| Operating system | |
| Architecture |