compiler plugin pass order

Anton Antich anton.antich at gmail.com
Fri Sep 13 09:57:34 UTC 2019


Dear all,

we started exploring Haskell-to-DotNet compiler in frames of a larger
project and would like to clarify one issue: is it possible to control the
order in the compilation pipeline in which the compiler plugins get called?
Inserting .Net compilation via Plugin seems a cleaner way than using GHC
API from scratch for a lot of reasons, but the challenge is as follows: we
compile from STG but inside the plugin core2core passes have not been
called yet, and without them some important optimizations are missing.

To illustrate the issue, this function "plus x = x + 4" gets compiled to a
nice stg function with core2core (core2core, corePrep, coreToStg, stg2stg):

plus :: forall a. Num a => a -> a

[LclIdX, Arity=2, Unf=OtherCon []] =

    [] \r [$dNum_s1bl x]

        let {

          sat_s1bz [Occ=Once] :: a

          [LclId] =

              [$dNum_s1bl] \u []

                  let {

                    sat_s1by [Occ=Once] :: Integer

                    [LclId] =

                        CCCS S#! [4#];

                  } in  fromInteger $dNum_s1bl sat_s1by;

        } in  + $dNum_s1bl x sat_s1bz;

Inside the plugin, it is only possible to do the same pipeline but
*without* the core2core passes, and it gets compiled with additional THUNK:

[sat_s1gp :: forall a. Num a => a -> a

 [LclId] =

     [] \r [$dNum_s1ga x]

         let {

           sat_s1go [Occ=Once] :: a

           [LclId] =

               [$dNum_s1ga] \u []

                   let {

                     sat_s1gn [Occ=Once] :: Integer

                     [LclId] =

                         CCCS S#! [4#];

                   } in  fromInteger $dNum_s1ga sat_s1gn;

         } in  + $dNum_s1ga x sat_s1go;,

 plus :: forall a. Num a => a -> a

 [LclIdX] =

     [] \u [] sat_s1gp;,

So the question is - is there any way to ask GHC to run the plugin as LAST
in the core2core passes process so that we get the optimized core and
convert it to stg?

Alternatively, maybe STG plugins should also be introduced? Should be an
easy enough change. Thank you for comments / suggestions / ideas!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20190913/96c9c633/attachment.html>


More information about the ghc-devs mailing list