Re: the long way to the development of a compiler

"walter" <walter@nospamm-digitalmars.com>
2 Jul 2001 00:36:30 -0400

          From comp.compilers

Related articles
the long way to the development of a compiler stf@apl.it (Stefano Lanzavecchia) (2001-06-28)
Re: the long way to the development of a compiler lockner@chaos.cns.uni.edu (Matthew J.Lockner) (2001-07-01)
Re: the long way to the development of a compiler neelk@alum.mit.edu (2001-07-02)
Re: the long way to the development of a compiler dlindauer@notifier-is.net (david lindauer) (2001-07-02)
Re: the long way to the development of a compiler walter@nospamm-digitalmars.com (walter) (2001-07-02)
Re: the long way to the development of a compiler stf@apl.it (Stefano Lanzavecchia) (2001-07-02)
Re: the long way to the development of a compiler christian.bau@isltd.insignia.com (Christian Bau) (2001-07-02)
Re: the long way to the development of a compiler aleksey+@cs.cmu.edu (Aleksey Kliger) (2001-07-03)
Re: the long way to the development of a compiler neelk@alum.mit.edu (2001-07-03)
Re: the long way to the development of a compiler franck.pissotte@free.fr (Franck Pissotte) (2001-07-03)
Re: the long way to the development of a compiler marcov@toad.stack.nl (2001-07-06)
[1 later articles]
| List of all articles for this month |

From: "walter" <walter@nospamm-digitalmars.com>
Newsgroups: comp.compilers
Date: 2 Jul 2001 00:36:30 -0400
Organization: Excite@Home - The Leader in Broadband http://home.com/faster
References: 01-06-071
Keywords: design, optimize
Posted-Date: 02 Jul 2001 00:36:30 EDT

Stefano Lanzavecchia wrote
> The one topic that at the moment is at the top of my priority
>list of things to learn is code generation for real CPUs. It was easy
>to write a toy compiler targeting a simple stack machine and implement
>an interpreter for the stack machine, but when I started thinking
>about real CPUs (in particular x86 and its special purpose registers
>and its asymmetric instruction set, but also the 6502 with its 3
>registers or MIPS or Alpha) I discovered that I hadn't learned enough
>from the mentioned books. Both instruction selection and register
>allocation are topics that are still quite obscure to me from a
>practical point of view (one thing is to read about graph colouring
>and another one is to put it in practice). I've tried to read the
>source code of the native OCaml compiler, but it's a bit too advanced
>for my taste.


I ran into the same thing. The optimization books and clever
algorithms written up in papers don't work on a real machine. For
example, the algorithms for loop induction variable elimination don't
take into account signed/unsigned changes, pointer sizes different
from int sizes, and loops that cross over 0 or overflow. For another
example, the register allocation algorithms usually assume the
registers are all perfectly interchangable.


On the x86 we have several special purpose registers with overlapping
uses, strange subset H, L and X registers, a plethora of special case
instructions, and an FPU that is organized like an RPN stack, but if
you program it like an RPN stack, execution speed will be
miserable. Add to that to support longlong's you need to use register
pairs, not addressed in any standard register allocation algorithms I
know of.


All this adds up to writing a quality code generator for the x86 will
take several years. One technique won't get you there, you'll need to
mix and match a variety of algorithms. That's why the code generators
you looked at are of numbing complexity <g>.


-Walter
www.digitalmars.com Free C/C++ compilers


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.