class OPTIMIZE < $OPTIMIZE
****
This optimizer moves as many expressions as possible out of loops. An expression is movable if it is either * a constant * a constant from the beginning of the loop to its first call
___and_it_is_not_in_a_conditional_expression._We_have_to_check_two_cases:
____if_it_is_possible_that_the_expression_is_never_evaluated,_because_the_loop
____terminates_early_(iter_call,_return,_raise),_we_have_to_make_sure_that
____during_the_evaluation_of_the_code_there_is_no_fatal_error._Hence_we_
____move_only_local,_global_and_attr_expressions_out_of_the_loop._Attr_expressions
____are_guarded_against_void_accesses.
* if the code is in a conditional expression, we check that all it consists only of
___local,_global_or_attr_expressions_that_are_constant_during_the_whole_loop
___Attr_expressions_have_to_be_guarded_against_void_accesses.
NOTE: if an attr expression is guarded against void accesses, the program
_______will_not_stop_with_an_"void_access"_but_silently_continue._Therefore
_______you_should_not_use_-O_if_you_need_to_check_all_accesses.


Flattened version is here

Ancestors
$OPTIMIZE OPT_HELPER



Public


Features
create(p:PROG):SAME
do_loop_opt(func:AM_ROUT_DEF)
**** if func.sig.is_iter then mark_hot_args(func); end; unfortunatly it is very hard to do any optimizations within iters. The problem is that it not possible to move code or evaluate expressions before or after the yield statement where they were. It is for example impossible to move the expression 'a*b' out of a loop, as you don't know if the caller may change it or not:
____loop_yield_1.up!*a*b;_end;
This assumes that either a or b are attributes, and not locals of course. As it seems not worth the trouble, iters are not optimized at all (but we do inlining in iters, of course);
finalize
init
mark_hot_args(func:AM_ROUT_DEF)
no_optimize(func:AM_ROUT_DEF)
**** if no optimization option is on, but opt_debug is on the compiler dumps the AM form of all functions. Handy to get them, but definitly the wrong place for this code. This will most certainly be deleted in future versions of the optimizer.
optimize(func:AM_ROUT_DEF)


Private