| parrotcode: compilers/imcc/optimizer.c | |
| Contents | Compilers | 

compilers/imcc/optimizer.c

Optimization occurs in three stages: 1) pre_optimizer -- runs before control flow graph (CFG) is built 2) optimizer -- runs after CFG is built, but before register allocation 3) post_optimizer -- runs after register allocation
pre_optimizer -------------
During pre-optimization we perform optimizations which don't require full knowledge of the control flow graph and the life ranges of each variable. This phase is handled by two functions: pre_optimize() and cfg_optimize().
pre_optimize() runs before the construction of the CFG begins. It calls strength_reduce() to perform simple strength reduction, and if_branch() to rewrite certain if/branch/label constructs (for details, see if_branch() below).
[pre_optimize() may also be called later, during the main optimization phase, but this is not guaranteed.]
cfg_optimize() runs during the construction of the CFG. It calls branch_branch() to perform jump optimization (i.e. branches to branch statements or jumps to jumps are converted into single branches/jumps to the final destination), unused_label() to remove unused labels and dead_code_remove() to remove unreachable code (e.g. basic blocks which are never entered or instructions after and unconditional branch which are never branched to).
cfg_optimize may be called multiple times during the construction of the CFG depending on whether or not it finds anything to optimize.
RT#46277: subst_constants ... rewrite e.g. add_i_ic_ic -- where does this happen?
optimizer ---------
runs with CFG and life info
used_once ... deletes assignments, when LHS is unused loop_optimization ... pulls invariants out of loops RT#46279 e.g. constant_propagation
post_optimizer: currently pcc_optimize in pcc.c ---------------
runs after register alloocation
e.g. eliminate new Px .PerlUndef because Px where different before

int pre_optimizeint cfg_optimizeint optimizeconst char *get_neg_opstatic int if_branch  if cond L1
  branch L2
  L1
  unless cond L2
static int strength_reducestatic int constant_propagationInstruction *IMCC_subst_constants_umixstatic int eval_insInstruction *IMCC_subst_constantsstatic int branch_branchstatic int branch_reorgstatic int branch_cond_loop_swapstatic int branch_cond_loopstatic int unused_labelstatic int dead_code_removestatic int used_oncestatic int _is_ins_savestatic int is_ins_saveint max_loop_depthint is_invariantBasic_block *find_outerint move_ins_outint loop_oneint loop_optimization
|  |   |