Commentary Cmm page (Observations and Areas for Improvement)

Simon Peyton-Jones simonpj at microsoft.com
Tue Nov 21 11:31:37 EST 2006


| Very interesting!  I was referring to the C-- Spec.(the Reference
| Manual), where "addc" and "carry" are listed as operators (see, e.g.,
| revision 1.128, p. 43) and I could not find a corresponding operator
| in Cmm.  (That does not mean C-- or Cmm do not support it, but going
| from the C-- Spec., statements may not produce side-effects, so the
| bulk of my comment related to the lack of support the mnemonic dot
| suffix, "add.", while I suggested the "addc" because it might be a
| nice introduction to Cmm.)

Right.
 * Expressions in C-- and Cmm (a) have one result, (b) have no effects.
 * There may well be operators in official C-- that aren't implemented in Cmm.  That should be fixable, simply by adding new primops
  * There is provision in C-- for primops that (a) may have more than one result, (b) have effects.  This is done by the %% syntax, described at the end of Section 6.3 of the C-- spec.
  * However this feature is ill-specified by the C-- spec; indeed no %% operators are described at all
  * Some of what you have in mind is described in Section 4.3 of
        http://cminusminus.org/abstracts/c--pldi-00.html

| I confess that I was too lazy to pull the CmmCall (target::CmmPrim)
| out of the code in nativeGen/MachCodeGen.hs, nativeGen/AsmCodeGen.hs
| or cmm/PprCmm.hs because CmmCall seemed primarily used for foreign
| calls--the comment for the CmmCall constructor in cmm/Cmm.hs refers
| to it as "a foreign call."

CmmCall is indeed primarily for foreign calls, but if the CmmTarget is a CmmPrim, then in principle that CCallishMachOp can have effects and multiple results; and they are certainly not reqd to make a foreign call.  Indeed, one already does have effects: MO_WriteBarrier.

So if you want to add primitive ops to Cmm that return multiple result, this is where you should do it.

| Now you have me wondering about Cmm operators--would they be able to
| support side-effects?  The point is not to turn all things under the
| hood imperative but to give Cmm a way to express such things as more
| efficient exception handling so other Haskell functions that might
| deal with such exceptions may appear together in Cmm code.

Definitely *not* for ops in CmmExpr.  Definitely *yes* for CallishMachOps, as discussed above.


I hope this makes it clearer?  Perhaps you can write up the outcome of all this on the Cmm language wiki page?

Simon


More information about the Cvs-ghc mailing list