Skip to content

[WIP] Generate single-entry (instead of updatable) thunks for string literals

Ömer Sinan Ağacan requested to merge osa1/ghc:reentrant_strings into master

Fixes #15113

Previously for a string like

hey :: String
hey = "hey"

We would generate this thunk:

hey_rgf :: GHC.Base.String
[LclId] = \u [] GHC.CString.unpackCString# "hey"#;

With this patch we now generate single-entry thunks for string literals:

hey_rgf :: GHC.Base.String
[GblId] = {} \s [] GHC.CString.unpackCString# "hey"#;

Cmm before:

[hey_r2_entry() { //  [R1]
         { info_tbls: [(c1rH,
                        label: hey_r2_info
                        rep: HeapRep static { Thunk }
                        srt: Nothing)]
           stack_info: arg_space: 8 updfr_space: Just 8
         }
     {offset
       c1rH: // global
           _r2::P64 = R1;
           if ((Sp + 8) - 24 < SpLim) (likely: False) goto c1rI; else goto c1rJ;
       c1rI: // global
           R1 = _r2::P64;
           call (stg_gc_enter_1)(R1) args: 8, res: 0, upd: 8;
       c1rJ: // global
           (_c1rE::I64) = call "ccall" arg hints:  [PtrHint,
                                                    PtrHint]  result hints:  [PtrHint] newCAF(BaseReg, _r2::P64);
           if (_c1rE::I64 == 0) goto c1rG; else goto c1rF;
       c1rG: // global
           call (I64[_r2::P64])() args: 8, res: 0, upd: 8;
       c1rF: // global
           I64[Sp - 16] = stg_bh_upd_frame_info;
           I64[Sp - 8] = _c1rE::I64;
           R2 = hey1_r1lh_bytes;
           Sp = Sp - 16;
           call GHC.CString.unpackCString#_info(R2) args: 24, res: 0, upd: 24;
     }
 },
 section ""data" . hey_r2_closure" {
     hey_r2_closure:
         const hey_r2_info;
         const 0;
         const 0;
         const 0;
 }]

After:

[hey_r2_entry() { //  []
         { info_tbls: [(c1rE,
                        label: hey_r2_info
                        rep: HeapRep static { Thunk }
                        srt: Nothing)]
           stack_info: arg_space: 8 updfr_space: Just 8
         }
     {offset
       c1rE: // global
           goto c1rG;
       c1rG: // global
           R2 = hey1_r1lh_bytes;
           call GHC.CString.unpackCString#_info(R2) args: 8, res: 0, upd: 8;
     }
 },
 section ""data" . hey_r2_closure" {
     hey_r2_closure:
         const hey_r2_info;
         const 0;
         const 0;
         const 0;
 }]

However we currently don't omit single-entry THUNKs in SRTs so references to this closure will still end up in SRTs. This is fixed in !2968.

NoFib:

--------------------------------------------------------------------------------
        Program           Size    Allocs    Instrs     Reads    Writes
--------------------------------------------------------------------------------
             CS          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
            CSD          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
             FS          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
              S          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
             VS          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
            VSD          -1.3%     -0.3%     -0.0%     -0.0%     -1.0%
            VSM          -1.3%     -0.0%     -0.0%     -0.0%     -0.0%
           anna          -1.4%    +20.8%     +4.9%     +2.9%     +7.4%
           ansi          -1.4%     +0.0%     -0.4%     -0.5%     -0.2%
           atom          -1.4%     +0.0%     +0.1%     +0.1%     +0.1%
         awards          -1.6%     +1.7%     +0.7%     +0.6%     +0.8%
         banner          -2.1%    +31.6%    +15.3%    +12.9%    +19.9%
     bernouilli          -1.4%     +0.3%     +0.1%     +0.1%     +0.1%
   binary-trees          -1.6%     +0.1%     +0.0%     +0.0%     +0.0%
          boyer          -1.4%     +0.0%     +0.1%     +0.1%     +0.1%
         boyer2          -2.3%     +1.4%     +0.2%     +0.2%     +0.2%
           bspt          -1.4%     +0.3%     +0.1%     +0.1%     +0.1%
      cacheprof          -2.8%    +11.5%     +5.8%     +5.6%     +6.9%
       calendar          -1.5%     +7.4%     +5.0%     +4.4%     +5.7%
       cichelli          -1.7%     +0.0%     -0.4%     -0.5%     -0.4%
        circsim          -1.4%     +0.1%     -0.0%     -0.0%     +0.0%
       clausify          -1.4%     +0.1%     -0.6%     -0.9%     -0.5%
  comp_lab_zift          -1.5%     +1.7%     +1.3%     +1.1%     +1.2%
       compress          -1.3%     +0.0%     +0.0%     +0.0%     +0.0%
      compress2          -1.2%     +0.0%     +0.0%     +0.0%     +0.0%
    constraints          -1.4%     +0.0%     +0.1%     +0.1%     +0.1%
   cryptarithm1          -1.4%     +0.0%     +0.0%     +0.0%     +0.0%
   cryptarithm2          -1.7%     +0.1%     +0.0%     +0.0%     +0.0%
            cse          -1.5%    +40.5%    +11.7%     +5.5%    +17.4%
   digits-of-e1          -1.4%     +0.1%     +0.0%     +0.0%     +0.0%
   digits-of-e2          -1.6%     +0.1%     +0.0%     +0.0%     +0.0%
         dom-lt          -1.4%     +2.3%     +1.4%     +1.6%     +1.5%
          eliza          -2.4%     +4.6%     +1.5%     +1.5%     +2.4%
          event          -1.5%     +0.1%     -0.5%     -0.8%     -0.5%
    exact-reals          -1.2%     +0.0%     -0.0%     -0.0%     -0.0%
         exp3_8          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
         expert          -1.5%    +20.6%     +4.6%     +3.0%     +6.8%
 fannkuch-redux          -1.4%     +3.4%     -0.0%     -0.0%     -0.0%
          fasta          -1.5%     +0.0%     -0.0%     -0.0%     -0.0%
            fem          -1.3%     +0.0%     +0.1%     +0.1%     +0.1%
            fft          -1.4%     +1.0%     +0.8%     +0.7%     +0.8%
           fft2          -1.5%     +0.1%     +0.3%     +0.4%     +0.2%
       fibheaps          -1.5%     +0.0%     +0.0%     +0.0%     +0.0%
           fish          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
          fluid          -1.1%    +16.4%     +5.9%     +5.3%     +7.7%
         fulsom          -1.3%     +0.2%     +0.1%     +0.1%     +0.1%
         gamteb          -1.4%     +0.8%     +0.4%     +0.4%     +0.5%
            gcd          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
    gen_regexps          -1.3%     +0.0%     +0.1%     +0.1%     +0.1%
         genfft          -1.6%    +14.0%    +10.1%     +8.5%    +10.7%
             gg          -1.8%     +4.9%     +3.5%     +3.5%     +3.6%
           grep          -1.5%     +0.0%     +0.1%     +0.2%     +0.1%
         hidden          -1.3%     +3.5%     +1.6%     +1.4%     +2.0%
            hpg          -1.6%     +7.2%     +4.0%     +3.5%     +4.8%
            ida          -1.4%     +1.1%     +0.6%     +0.5%     +0.7%
          infer          -1.4%     +4.6%     +1.1%     +0.6%     +1.6%
        integer          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
      integrate          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
   k-nucleotide          -1.6%     +1.3%     -0.0%     -0.0%     -0.0%
          kahan          -1.5%     +4.5%     -0.0%     -0.0%     -0.0%
        knights          -1.3%     +0.0%     -0.0%     -0.0%     -0.0%
         lambda          -1.7%    +82.7%    +24.9%    +18.6%    +33.8%
     last-piece          -1.3%     +0.0%     -0.0%     +0.0%     -0.0%
           lcss          -1.4%     +0.5%     +0.1%     +0.0%     +0.2%
           life          -1.4%     +2.7%     +1.5%     +1.0%     +1.6%
           lift          -1.4%    +14.8%     +5.8%     +3.9%     +7.7%
         linear          -1.4%     +0.1%     +0.1%     +0.1%     +0.1%
      listcompr          -1.7%     +4.5%     +3.5%     +2.7%     +3.6%
       listcopy          -1.7%     +4.1%     +3.2%     +2.4%     +3.3%
       maillist          -1.7%     +0.5%     +1.1%     +1.0%     +1.4%
         mandel          -1.4%     +0.6%     +0.1%     +0.1%     +0.2%
        mandel2          -1.5%     +0.0%     -0.0%     -0.0%     -0.0%
           mate          -1.4%     +0.0%     +0.0%     +0.0%     +0.0%
        minimax          -1.5%     +4.5%     +0.5%     +0.2%     +1.0%
        mkhprog          -1.6%     +6.6%     +4.0%     +3.5%     +4.7%
     multiplier          -1.4%     +0.3%     +0.2%     +0.2%     +0.2%
         n-body          -1.6%     +3.5%     -0.0%     -0.0%     -0.0%
       nucleic2          -1.3%     +0.0%     -0.1%     -0.0%     -0.0%
           para          -1.4%     +0.0%     -0.2%     -0.3%     -0.2%
      paraffins          -1.4%     +0.3%     -0.3%     -0.4%     -0.1%
         parser          -1.8%    +12.7%     +4.1%     +3.0%     +5.8%
        parstof          -1.6%    +39.5%    +12.5%    +12.0%    +13.9%
            pic          -1.4%     +0.1%     -1.2%     -1.3%     -0.9%
       pidigits          -1.4%     +0.0%     +0.0%     +0.0%     -0.0%
          power          -1.3%     +0.1%     +0.0%     +0.0%     +0.0%
         pretty          -1.2%    +12.4%     +0.4%     -0.2%     +2.0%
         primes          -1.5%     +0.0%     -0.0%     -0.0%     -0.0%
      primetest          -1.4%     +0.0%     +0.0%     +0.0%     +0.0%
         prolog          -1.3%    +22.7%     +8.7%     +7.5%    +10.7%
         puzzle          -1.5%     +0.1%     +0.1%     +0.1%     +0.1%
         queens          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
        reptile          -1.5%     +0.5%     +0.4%     +0.3%     +0.3%
reverse-complem          -1.4%     -0.0%     -0.0%     -0.0%     -0.0%
        rewrite          -1.4%    +80.2%    +15.7%    +14.6%    +22.5%
           rfib          -1.4%     +2.1%     -0.0%     -0.0%     -0.0%
            rsa          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
            scc          -1.3%     -0.2%     -0.8%     -0.8%     -1.0%
          sched          -1.4%     +0.1%     +0.0%     +0.0%     +0.0%
            scs          -1.4%     +0.0%     +0.0%     +0.1%     +0.0%
         simple          -1.3%     +0.0%     -0.0%     -0.0%     -0.0%
          solid          -1.4%     +0.1%     -0.0%     -0.0%     +0.0%
        sorting          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
  spectral-norm          -1.6%     +2.0%     -0.0%     -0.0%     -0.0%
         sphere          -1.3%     +0.1%     +0.0%     +0.0%     +0.0%
         symalg          -1.5%     +2.8%     +0.1%     -0.0%     +0.4%
            tak          -1.4%     +4.7%     -0.0%     -0.0%     -0.0%
      transform          -1.5%     +4.3%     +1.6%     +0.8%     +2.0%
       treejoin          -1.4%     +0.0%     +0.1%     +0.0%     -0.0%
      typecheck          -1.6%    +28.5%     +8.2%     +5.6%    +11.1%
        veritas          -2.2%    +11.2%    +13.2%    +12.1%    +10.2%
           wang          -1.4%     +4.6%     +3.2%     +2.0%     +3.1%
      wave4main          -1.4%     +0.6%     +0.2%     +0.1%     +0.2%
   wheel-sieve1          -1.5%     +0.4%     +0.2%     +0.4%     -0.0%
   wheel-sieve2          -1.4%     +0.0%     +0.1%     +0.1%     +0.1%
           x2n1          -1.4%     +0.0%     -0.0%     -0.0%     -0.0%
--------------------------------------------------------------------------------
            Min          -2.8%     -0.3%     -1.2%     -1.3%     -1.0%
            Max          -1.1%    +82.7%    +24.9%    +18.6%    +33.8%
 Geometric Mean          -1.5%     +4.3%     +1.6%     +1.3%     +2.0%
Edited by Ömer Sinan Ağacan

Merge request reports