Effects of time optimization

Time optimization causes loops that are not known at compile time if they will execute at least one time to have the loop test code generated at the top of the loop as well. This only happens when no function calls exist in the loop test code. FOR loops can fall into this category, and WHILE loops with 2 comparisons or less also will get top testing. BOOLEAN AND/OR/NOT operators do NOT count as comparisons, as they only affect the logic of the branches resulting from comparisons and generate no code.

Modula-2

WHILE (ptr <> NIL) AND (ptr^.boo <> done) DO

    (* 2 comparisons *)

END;

Ada95

while (ptr /= null) and then (ptr.boo /= done) loop

    -- 2 comparisons

end loop;

You can also force top testing for a loop.

Modula-2

<*/PUSH/LoopTopTest*>

WHILE (ptr <> NIL) AND (ptr^.boo <> done) DO

<*/POP*>

Ada95

Pragma Directive("/PUSH/LoopTopTest");

while (ptr /= null) and then (ptr.boo /= done) loop

Pragma Directive("/POP");

The register allocator enregisters variables that have the mostreferences. When time optimization is specified a reference to a variable withina loop gets a multiplier added to the reference count. This multiplier gets largerthe deeper the loops are nested. This only happens when loop optimizations such asinduction, invariant and rewriting are enabled, as the optimizer has the duty ofdetermining the loop depth.

Time optimization causes the code generator to be biased towards generating a jump table for CASEs rather than comparisons. CASE statements are generated as follows depending on the of case selector arms the statement has

To force a jump table to be generated you can use the Sparsecase compiler option to control this. To force a single CASE you do something liketo following.

Modula-2

<*/PUSH/NOSPARSE*>

CASE ... OF

<*/POP*>

Ada95

Pragma Directive("/PUSH/NOSPARSE");

CASE ... OF

Pragma Directive("/POP");

Sometimes jump tables can be huge and for performance you may still want a jump table on some specific code. We use the /NOSPARSE directives in the compiler for just such purposes.

If the comparison is a Modula-2 LONGINT type, or Ada95 Long_Integertype then the compiler is very biased towards jump tables.

Time optimization causes the code segment to become aligned, and jump tables and some other labels become aligned depending on processor.