<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Sun, Mar 18, 2018 at 6:38 AM Shao, Cheng <<a href="mailto:cheng.shao@tweag.io">cheng.shao@tweag.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi all,</div><div><br></div><div>Is the "cml_cont" field of the CmmCall variant is really used in practice? I traversed the output of raw Cmm produced by ghc compiling the whole base package, but the value of cml_cont is always Nothing.<br></div><div><br></div><div>Regards,</div><div>Shao Cheng</div></div></blockquote><div><br></div><div><br></div><div>Hi,</div><div><br></div><div>I'm not a GHC expert, so please don't trust everything I say ;)</div><div><br></div><div>That being said, I think `cml_cont` is used a lot. If you look at the</div><div>`compiler/codeGen` directory (that's what turns STG to cmm), you'll</div><div>see that `MkGraph.mkCallReturnsTo` is called a few times. That's the</div><div>function that will construct a `CmmCall` with the continuation block.</div><div><br></div><div>When dumping cmm, you'll often see all those `returns to` notes. For</div><div>instance, compiling:</div><div><br></div><div>```</div><div>foo :: Int -> Int</div><div>foo x =</div><div>  case x of</div><div>    42 -> 111111</div><div>    _  -> 000000</div><div>```</div><div><br></div><div>results in:</div><div><br></div><div>```</div><div>       [...]</div><div>       c2cN: // global</div><div>           I64[Sp - 8] = c2cI;</div><div>           R1 = R2;</div><div>           Sp = Sp - 8;</div><div>           if (R1 & 7 != 0) goto c2cI; else goto c2cJ;</div><div><br></div><div>       // Evaluate the parameter.</div><div>       c2cJ: // global</div><div>           call (I64[R1])(R1) returns to c2cI, args: 8, res: 8, upd: 8;</div><div>           //                 ^^^^^^^^^^^^^^^</div><div>           //                 this specifies the continuation block</div><div>           //                 see also PprCmm.pprNode</div><div><br></div><div>       // Now check if it's 42.</div><div>       c2cI: // global</div><div>           if (I64[R1 + 7] == 42) goto c2cU; else goto c2cT;</div><div>       c2cU: // global</div><div>       [...]</div><div>```</div><div><br></div><div>As far as I understand it, this allows the code above to jump to the</div><div>`x` closure (to evalutae it), and have the closure jump back to the</div><div>continuation block (note that it's address is stored before we jump to</div><div>closure). AFAICS this particular code is created by</div><div>`StgCmmExpr.emitEnter`.</div><div><br></div><div>Hope this helps!</div><div><br></div><div>- Michal</div><div> </div></div></div>