[GHC] #8590: Reduce code size of CAFs

GHC ghc-devs at haskell.org
Mon Dec 2 21:45:24 UTC 2013


#8590: Reduce code size of CAFs
-------------------------------------+------------------------------------
        Reporter:  parcs             |            Owner:  parcs
            Type:  feature request   |           Status:  patch
        Priority:  normal            |        Milestone:
       Component:  Compiler (NCG)    |          Version:  7.7
      Resolution:                    |         Keywords:
Operating System:  Unknown/Multiple  |     Architecture:  Unknown/Multiple
 Type of failure:  None/Unknown      |       Difficulty:  Unknown
       Test Case:                    |       Blocked By:
        Blocking:                    |  Related Tickets:
-------------------------------------+------------------------------------
Changes (by parcs):

 * status:  new => patch


Comment:

 Proposed patch attached.


 To illustrate the change in code generation, consider the module

 {{{
 #!haskell
 module CAF where

 a = "test"
 }}}

 Previously, the output Cmm looked like

 {{{
 #!c
  CAF.a_entry() //  [R1]
          { info_tbl: [(cCO,
                        label: CAF.a_info
                        rep:HeapRep static { Thunk })]
            stack_info: arg_space: 8 updfr_space: Just 8
          }
      {offset
        cCO:
            _rnT::P64 = R1;
            if ((Sp + -16) < SpLim) goto cCP; else goto cCQ;
        cCQ:
            Hp = Hp + 16;
            if (Hp > HpLim) goto cCS; else goto cCR;
        cCS:
            HpAlloc = 16;
            goto cCP;
        cCP:
            R1 = _rnT::P64;
            call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8;
        cCR:
            I64[Hp - 8] = stg_CAF_BLACKHOLE_info;
            I64[Hp] = CurrentTSO;
            (_cCK::I64) = call "ccall" arg hints:  [PtrHint, PtrHint,
                                                    PtrHint]  result hints:
 [] newCAF(BaseReg, _rnT::P64, Hp - 8);
            if (_cCK::I64 == 0) goto cCM; else goto cCL;
        cCM:
            call (I64[_rnT::P64])() args: 8, res: 0, upd: 8;
        cCL:
            I64[Sp - 16] = stg_bh_upd_frame_info;
            P64[Sp - 8] = Hp - 8;
            R2 = cCN_str;
            Sp = Sp - 16;
            call GHC.CString.unpackCString#_info(R2) args: 24, res: 0, upd:
 24;
      }
 }}}

 Now, the output Cmm looks like

 {{{
 #!c
  CAF.a_entry() //  [R1]
          { info_tbl: [(cCN,
                        label: CAF.a_info
                        rep:HeapRep static { Thunk })]
            stack_info: arg_space: 8 updfr_space: Just 8
          }
      {offset
        cCN:
            if ((Sp + -16) < SpLim) goto cCO; else goto cCP;
        cCO:
            R1 = R1;
            call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8;
        cCP:
            (_cCJ::I64) = call "ccall" arg hints:  [PtrHint,
                                                    PtrHint]  result hints:
 [PtrHint] newCAF(BaseReg, R1);
            if (_cCJ::I64 == 0) goto cCL; else goto cCK;
        cCL:
            call (I64[R1])() args: 8, res: 0, upd: 8;
        cCK:
            I64[Sp - 16] = stg_bh_upd_frame_info;
            I64[Sp - 8] = _cCJ::I64;
            R2 = cCM_str;
            Sp = Sp - 16;
            call GHC.CString.unpackCString#_info(R2) args: 24, res: 0, upd:
 24;
      }

 }}}

 Comparing object sizes:

 Before:
 {{{
    text    data     bss     dec     hex filename
     146      32       0     178      b2 caf.o
 }}}

 After:
 {{{
    text    data     bss     dec     hex filename
      92      32       0     124      7c caf.o
 }}}

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


More information about the ghc-tickets mailing list