2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
6 * This file may be distributed and/or modified under the terms of the
7 * GNU General Public License version 2 as published by the Free Software
8 * Foundation and appearing in the file LICENSE.GPL included in the
9 * packaging of this file.
11 * Licensees holding valid libFirm Professional Edition licenses may use
12 * this file in accordance with the libFirm Commercial License.
13 * Agreement provided with the Software.
15 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * @brief peephole optimisation framework
23 * @author Matthias Braun
32 extern ir_node **register_values;
34 static inline ir_node *be_peephole_get_value(unsigned register_idx)
36 return register_values[register_idx];
39 static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
41 unsigned register_idx = reg->global_index;
42 return be_peephole_get_value(register_idx);
46 * Datatype of the generic op handler for optimisation.
48 typedef void (*peephole_opt_func) (ir_node *node);
51 * Notify the peephole phase about a newly added node, so it can update its
52 * internal state. This is not needed for the new node, when
53 * be_peephole_exchange() is used.
54 * Note: Contrary to normal exchange you mustn't remove the node from the
55 * schedule either before exchange. Exchange will do that for you.
57 void be_peephole_new_node(ir_node *nw);
60 * When doing peephole optimisation use this function instead of plain
61 * exchange(), so it can update its internal state. */
62 void be_peephole_exchange(ir_node *old, ir_node *nw);
65 * Tries to optimize a beIncSp node with its previous IncSP node.
66 * Must be run from a be_peephole_opt() context.
68 * @param node a be_IncSP node
70 * @return the new IncSP node or node itself
72 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
74 bool be_has_only_one_user(ir_node *node);
77 * In a scheduled program with registers assigned,
78 * checks wether @p node can be moved before @p before without changing program
81 * Note: It is allowed to use this function without being in a peephole
84 bool be_can_move_before(const ir_node *node, const ir_node *before);
87 * Do peephole optimisations. It traverses the schedule of all blocks in
88 * backward direction. The register_values variable indicates which (live)
89 * values are stored in which register.
90 * The generic op handler is called for each node if it exists. That's where
91 * backend specific optimisations should be performed based on the
92 * register-liveness information.
94 void be_peephole_opt(ir_graph *irg);