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_optimize
int cfg_optimize
int optimize
const char *get_neg_op
static int if_branch
if cond L1
branch L2
L1
unless cond L2
static int strength_reduce
static int constant_propagation
Instruction *IMCC_subst_constants_umix
static int eval_ins
Instruction *IMCC_subst_constants
static int branch_branch
static int branch_reorg
static int branch_cond_loop_swap
static int branch_cond_loop
static int unused_label
static int dead_code_remove
static int used_once
static int _is_ins_save
static int is_ins_save
int max_loop_depth
int is_invariant
Basic_block *find_outer
int move_ins_out
int loop_one
int loop_optimization
|