compiler plugin pass order

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

compiler plugin pass order

Anton Antich
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!



_______________________________________________
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: compiler plugin pass order

Ben Gamari-2
Anton Antich <[hidden email]> writes:

> 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.
>
Just so we are all on the same page: Precisely what type of plugin are
you implementing?

If it's a Core plugin then you should be able install your plugin
anywhere in the list of CoreToDos given to the installCoreToDos
function.

Cheers,

- Ben


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

signature.asc (497 bytes) Download Attachment