V největší diskuzní skupině o Delphi (borland.public.delphi.non-technical) se někdo zeptal jaké vlastně optimalizace Delphi používá a dočkal se odpovědi od Dannyho Thorpe (Delphi Compiler Core blog), nyní už ex borlandera. Stav odpovídá roku 2005.
Nechám ho v originále protože neznám přesnou českou terminologii (tučné je DT). Některé jsem tipoval, některé mne celkem překvapují. Vytahuji ho na světlo jelikož mne zaujal a jelikož je tam beznadějně zahrabaný.
Delphi compiler optimisation
The Delphi compiler is a one-pass, top-down parser with incremental code generation. The Delphi compiler does use intermediate representations and multi-stage AST tree trimming optimizations.
For your reference, following is, as complete as I could make it,
list of all optimizations that are used in todays compilers.
I've added notations for which of these the Delphi compiler implements.
-Aggregation of global references
No, if this is referring to global constant folding (strings, primarily)
-Algebraic simplifications, including reassociations
Yes, but to a limited degree. We don't replace division with multiply by reciprocal, for example, because of concerns about loss of precision at the edges.
-Basic-block and branch scheduling
- and conditional moves
-Global value numbering
-Induction-variable strength reduction
-Interprocedureal constant propagation
Unclear. A constant is constant everywhere, no?
-Interprocedureal register allocation
-Intraprocedureal instruction cache optimization
-Linear-function test replacement
-Local and global common-subexpression elimination
-Local and global copy propagation
-Loop-invariant code motion
Yes. (for pointer derefs)
-Procedure specialization and clonning
-Scalar replacement of aggregates
-Scalar replacement of array references
If this refers to constant expression evaluation, yes.
-Software pipelining, with loop unrolling, variable expansion,
register -renaming and hierarchical reduction
Codegen templates are hand-tuned to favor instruction scheduling for the U and V pipelines of the Pentium family of processors.
-Sparse conditional constant propagation
-Tail call optimization, including tail recursion elimination
-Unnecessary bounds checking elimination
Keep in mind that even very good compilers implement only a small number of those and that not all of those are speed optimizations.
Correct. The tail recursion optimizations in your list, for example, are astronomically rare in the wild. Such optimizations typically only kick in if you write you recursive routines "just so" which means only the illuminati will benefit by it.
The mantra for Delphi optimizations is to make everyday code work better. We don't the luxury of chasing after miraculous optimizations that almost never work. I leave that to the grad students. ;>
Now going back to Delphi. It has always been a solid compiler with two important features: it generates good code to begin with and it is one-pass (lightning fast). If you ever wandered why C++ takes ages to compile as compared to Delphi, this is the answer.
A lot of that Delphi has to thank to the language itself.
True, except for the one-pass assertion. The codegen phase is
multi-pass intermediate node tree traversals and pruning. We just do it many times faster than the more traditional compiler models that were originally concieved for batch processing of punched cards.
This brings me to another point. Delphi has never been designed to be high-end compiler. For the purpose that people use it, it is more than fast enough.
Correct. It could be said that Delphi is fast enough to lead some folks to believe it should be the best at every computational scenario.
Delphi's objective is to be the most productive software development tool for a very broad audience of developers. The compiler is one small part of that.
originální příspěvek na groups.google.com