Saturday, 14 August 2010

[SSA] Two ways to implement it

I have evaluated two different approaches to SSAF in SBCL compiler. Both have some advantages and drawbacks, more or less significant from different points of view. So, here they are:


1. Insert the SSA pass after find-initial-dfo call, and modify the legacy IR1 component slightly (insert phi-functions & ensure unique assignments). Come out of SSA before ir1-phases call.

+ Faster to implement
+ Will probably fix the non-linear LVARs bug
- Does not allow to perform SSA-based optimisations (because it means the IR1 functionality duplication)
- Slows down the compilation process
- Requires a good bidirectional mapping algorithm between SSA form and IR1 representation.


2. Remove all IR1 code after make-functional-from-toplevel-lambda (including this function as well), and compile Lisp forms to SSAF. Apply SSA-based optimisations, and finally convert SSAF into VOPs, to use the existing backend.

+ Count all current IR1 bugs for sure
+ Easier conversion to SSAF (no need to analyse IR1 components)
+ Advanced SSA-based optimization, loops analysis, etc.
+ Probably faster compilation process?
+ More fun and interesting than the first variant
- A really huge project
- New bugs, as usual
- Merging perspectives are unclear (I do not believe that maintainers will throw out almost the whole compiler frontend).


As for now, I would prefer the second approach. I think that it will be a hobby project for me, and it will take a year or two before it can be announced as a beta or so, if at all. From my own development experience I can say that compilers should be designed and implemented by quite large (and preferably not remote) teams, not by a single person. So, this is just my own way to have fun with Common Lisp, and I feel that it is very likely to fail eventually. I do not expect brilliant results here, but I can't stop myself from giving it a try - at least to learn some new and cool things.

6 comments:

  1. Even though it is a hobby for you, you might attract more interest / developers if you commit to a publicly viewable git branch...

    ReplyDelete
  2. I do not hurry to invite more developers here, because the whole project future is very unclear. Also, our product is moving from SBCL to LW, so I feel that I should concentrate on my daily job instead of trying to improve SBCL (we are not going to use it anymore).


    Without a team, this SSA project may not evolve into a full frontend. But I am not ready to take the responsibility and build such a team. In that case it will be a _job_, not a hobby. But I already have a decent CL job, and I do not need the second weekend-based one:)

    ReplyDelete
  3. Здравствуйте, Роман.

    Я разработчик ПО, увлекающийся в свободное время архитектурой операционных систем. Нахожусь на раннем этапе проектирования системы, которую хотел бы базировать на lisp-подходе. Сейчас планирую разбираться с архитектурой SBCL runtime. У меня к вам есть несколько вопросов по принципам внуннего устройства лисп-компилятора. Если вам будет не сложно, свяжитесь со мною: semion.ababo собака gmail.com. Спасибо.

    ReplyDelete
  4. Hello!

    I am afraid that I am not the right person to answer such questions. The thing is that I only know something about IR1 part (frontend), but not about the whole system. That is, I am still learning the compiler internals. It will be better for you to send your questions to SBCL mailing list: sbcl-help@lists.sourceforge.net.

    Regarding CL and OS, please see http://common-lisp.net/project/movitz/movitz.html or ask on #lisp IRC channel.

    Also, I am on vacation now, and thus I do not have the regular access to PC and mail, sorry.

    Best Regards,
    Roman

    ReplyDelete
  5. P.S. In case you prefer Russian CL resources, there is the excellent one: http://lisper.ru/forum/common-lisp. I found it to be very interesting, and many mature CL developers from Russia/Ukraine are present on that forum (however, I haven't created my own account yet - I am a bit lazy when it comes to participation on forums:)

    Folks who are there know SBCL very good (there is the author of Win32 threads support, for example), so feel free to reach them with your questions.

    ReplyDelete