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 * Notify the peephole phase about a newly added node, so it can update its
36 * internal state. This is not needed for the new node, when
37 * be_peephole_exchange() is used.
38 * Note: Contrary to normal exchange you mustn't remove the node from the
39 * schedule either before exchange. Exchange will do that for you.
41 void be_peephole_new_node(ir_node *nw);
44 * When doing peephole optimisation use this function instead of plain
45 * exchange(), so it can update its internal state. */
46 void be_peephole_exchange(ir_node *old, ir_node *nw);
49 * Tries to optimize a beIncSp node with its previous IncSP node.
50 * Must be run from a be_peephole_opt() context.
52 * @param node a be_IncSP node
54 * @return the new IncSP node or node itself
56 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
58 bool be_has_only_one_user(ir_node *node);
61 * In a scheduled program with registers assigned,
62 * checks whether @p node can be moved before @p before without changing program
65 * Note: It is allowed to use this function without being in a peephole
68 bool be_can_move_down(ir_heights_t *heights, const ir_node *node,
69 const ir_node *before);
71 bool be_can_move_up(ir_heights_t *heights, const ir_node *node,
72 const ir_node *after);
75 * Do peephole optimisations. It traverses the schedule of all blocks in
76 * backward direction. The register_values variable indicates which (live)
77 * values are stored in which register.
78 * The generic op handler is called for each node if it exists. That's where
79 * backend specific optimisations should be performed based on the
80 * register-liveness information.
82 void be_peephole_opt(ir_graph *irg);