2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief peephole optimisation framework
9 * @author Matthias Braun
16 extern ir_node **register_values;
18 static inline ir_node *be_peephole_get_value(unsigned register_idx)
20 return register_values[register_idx];
23 static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
25 unsigned register_idx = reg->global_index;
26 return be_peephole_get_value(register_idx);
30 * Datatype of the generic op handler for optimisation.
32 typedef void (*peephole_opt_func) (ir_node *node);
35 * When doing peephole optimisation use this function instead of plain
36 * exchange(), so it can update its internal state. This function also removes
37 * the old node from the schedule.
39 void be_peephole_exchange(ir_node *old, ir_node *nw);
42 * Tries to optimize a beIncSp node with its previous IncSP node.
43 * Must be run from a be_peephole_opt() context.
45 * @param node a be_IncSP node
47 * @return the new IncSP node or node itself
49 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
51 bool be_has_only_one_user(ir_node *node);
54 * In a scheduled program with registers assigned,
55 * checks whether @p node can be moved before @p before without changing program
58 * Note: It is allowed to use this function without being in a peephole
61 bool be_can_move_down(ir_heights_t *heights, const ir_node *node,
62 const ir_node *before);
64 bool be_can_move_up(ir_heights_t *heights, const ir_node *node,
65 const ir_node *after);
68 * Do peephole optimisations. It traverses the schedule of all blocks in
69 * backward direction. The register_values variable indicates which (live)
70 * values are stored in which register.
71 * The generic op handler is called for each node if it exists. That's where
72 * backend specific optimisations should be performed based on the
73 * register-liveness information.
75 void be_peephole_opt(ir_graph *irg);