Is "cml_cont" of CmmCall used in practice?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is "cml_cont" of CmmCall used in practice?

Shao, Cheng
Hi all,

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.

Regards,
Shao Cheng

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Is "cml_cont" of CmmCall used in practice?

Ömer Sinan Ağacan
Hi Shao,

Perhaps not in the Cmm output generated for your programs, but it's definitely
used in the code generator. See e.g. `lowerSafeForeignCall` and `blockCode`
which set the field with `Just`. The former seems to be related with foreign
calls so perhaps try compiling a FFI package. `CmmLayoutStack` uses that field
for code generation (I don't understand the details yet).

Ömer

2018-03-18 8:38 GMT+03:00 Shao, Cheng <[hidden email]>:

> Hi all,
>
> 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.
>
> Regards,
> Shao Cheng
>
> _______________________________________________
> ghc-devs mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
>
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Is "cml_cont" of CmmCall used in practice?

Shao, Cheng
Hi Ömer,

See e.g. `lowerSafeForeignCall` and `blockCode`
which set the field with `Just`. The former seems to be related with foreign
calls so perhaps try compiling a FFI package.

I tried compiling a module with a `foreign import ccall safe` declaration, yet the output raw Cmm still doesn't use `cml_cont`.

`CmmLayoutStack` uses that field
for code generation (I don't understand the details yet).

Thanks for pointing that out, I'll check its implementation.

I also found another evidence of the field not used by codegens: in `PprC` which is used by unregisterised builds, only the `cml_target` field is used. So for now I assume that the assertion of `cml_cont = Nothing` holds for final Cmm output, and backend writers need not be concerned with it.

Regards,
Shao Cheng

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Is "cml_cont" of CmmCall used in practice?

Michal Terepeta
In reply to this post by Shao, Cheng
On Sun, Mar 18, 2018 at 6:38 AM Shao, Cheng <[hidden email]> wrote:
Hi all,

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.

Regards,
Shao Cheng


Hi,

I'm not a GHC expert, so please don't trust everything I say ;)

That being said, I think `cml_cont` is used a lot. If you look at the
`compiler/codeGen` directory (that's what turns STG to cmm), you'll
see that `MkGraph.mkCallReturnsTo` is called a few times. That's the
function that will construct a `CmmCall` with the continuation block.

When dumping cmm, you'll often see all those `returns to` notes. For
instance, compiling:

```
foo :: Int -> Int
foo x =
  case x of
    42 -> 111111
    _  -> 000000
```

results in:

```
       [...]
       c2cN: // global
           I64[Sp - 8] = c2cI;
           R1 = R2;
           Sp = Sp - 8;
           if (R1 & 7 != 0) goto c2cI; else goto c2cJ;

       // Evaluate the parameter.
       c2cJ: // global
           call (I64[R1])(R1) returns to c2cI, args: 8, res: 8, upd: 8;
           //                 ^^^^^^^^^^^^^^^
           //                 this specifies the continuation block
           //                 see also PprCmm.pprNode

       // Now check if it's 42.
       c2cI: // global
           if (I64[R1 + 7] == 42) goto c2cU; else goto c2cT;
       c2cU: // global
       [...]
```

As far as I understand it, this allows the code above to jump to the
`x` closure (to evalutae it), and have the closure jump back to the
continuation block (note that it's address is stored before we jump to
closure). AFAICS this particular code is created by
`StgCmmExpr.emitEnter`.

Hope this helps!

- Michal
 

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Is "cml_cont" of CmmCall used in practice?

Kavon Farvardin
Is the "cml_cont" field of the CmmCall variant is really used in practice?

Seconding what Michal has already said, yes, the `cml_cont` field is used quite a bit in Cmm.

Any non-tail call in the program will have this field populated with information about where control-flow continues after the call returns.

This field is used for some important steps, such as Proc Point analysis ( CmmProcPoint.callProcPoints ), the result of which is used to layout the stack. Stack layout uses the information about what values are live in the continuation block of a non-tail call to determine what values need to be saved to the stack.

Thus, the control-flow graph structure of a CmmProc is defined in part by the `cml_cont` field (see the Cmm specific instance of Hoopl's NonLocal class in CmmNode, where it is used to indicate successors of a block).

I traversed the output of raw Cmm produced by ghc compiling the whole base package, but the value of cml_cont is always Nothing.

Hrm, were you looking for "returns to" in that output?

~kavon


On Mar 18, 2018, at 8:52 AM, Michal Terepeta <[hidden email]> wrote:

On Sun, Mar 18, 2018 at 6:38 AM Shao, Cheng <[hidden email]> wrote:
Hi all,

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.

Regards,
Shao Cheng


Hi,

I'm not a GHC expert, so please don't trust everything I say ;)

That being said, I think `cml_cont` is used a lot. If you look at the
`compiler/codeGen` directory (that's what turns STG to cmm), you'll
see that `MkGraph.mkCallReturnsTo` is called a few times. That's the
function that will construct a `CmmCall` with the continuation block.

When dumping cmm, you'll often see all those `returns to` notes. For
instance, compiling:

```
foo :: Int -> Int
foo x =
  case x of
    42 -> 111111
    _  -> 000000
```

results in:

```
       [...]
       c2cN: // global
           I64[Sp - 8] = c2cI;
           R1 = R2;
           Sp = Sp - 8;
           if (R1 & 7 != 0) goto c2cI; else goto c2cJ;

       // Evaluate the parameter.
       c2cJ: // global
           call (I64[R1])(R1) returns to c2cI, args: 8, res: 8, upd: 8;
           //                 ^^^^^^^^^^^^^^^
           //                 this specifies the continuation block
           //                 see also PprCmm.pprNode

       // Now check if it's 42.
       c2cI: // global
           if (I64[R1 + 7] == 42) goto c2cU; else goto c2cT;
       c2cU: // global
       [...]
```

As far as I understand it, this allows the code above to jump to the
`x` closure (to evalutae it), and have the closure jump back to the
continuation block (note that it's address is stored before we jump to
closure). AFAICS this particular code is created by
`StgCmmExpr.emitEnter`.

Hope this helps!

- Michal
 
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Is "cml_cont" of CmmCall used in practice?

GHC - devs mailing list
In reply to this post by Ömer Sinan Ağacan
Adding Kavon.

It would be good to record the outcome of this discussion in a 'Note' with the cml_cont declaration, explaining what it is for.

Simon

|  -----Original Message-----
|  From: ghc-devs <[hidden email]> On Behalf Of Ömer Sinan
|  Agacan
|  Sent: 18 March 2018 07:32
|  To: Shao, Cheng <[hidden email]>
|  Cc: ghc-devs <[hidden email]>
|  Subject: Re: Is "cml_cont" of CmmCall used in practice?
|  
|  Hi Shao,
|  
|  Perhaps not in the Cmm output generated for your programs, but it's
|  definitely used in the code generator. See e.g. `lowerSafeForeignCall`
|  and `blockCode` which set the field with `Just`. The former seems to
|  be related with foreign calls so perhaps try compiling a FFI package.
|  `CmmLayoutStack` uses that field for code generation (I don't
|  understand the details yet).
|  
|  Ömer
|  
|  2018-03-18 8:38 GMT+03:00 Shao, Cheng <[hidden email]>:
|  > Hi all,
|  >
|  > 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.
|  >
|  > Regards,
|  > Shao Cheng
|  >
|  > _______________________________________________
|  > ghc-devs mailing list
|  > [hidden email]
|  >
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  > askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=04%7C01%7Csi
|  >
|  monpj%40microsoft.com%7Cb624f4ab25864a0a466d08d58ca28b07%7C72f988bf86f
|  >
|  141af91ab2d7cd011db47%7C1%7C0%7C636569552118955129%7CUnknown%7CTWFpbGZ
|  >
|  sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwifQ%3D%3D%7C-1
|  > &sdata=tdrRLRO6oORnAtTojQWMOXiL44hjVDJHFsORetboceM%3D&reserved=0
|  >
|  _______________________________________________
|  ghc-devs mailing list
|  [hidden email]
|  https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h
|  askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=04%7C01%7Csimonpj%40microsoft.com%7Cb624f4ab25864a0a466d08d5
|  8ca28b07%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6365695521189551
|  29%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI
|  6Ik1haWwifQ%3D%3D%7C-
|  1&sdata=tdrRLRO6oORnAtTojQWMOXiL44hjVDJHFsORetboceM%3D&reserved=0
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs