cleanup: Remove unnecessary #include "beirg.h".
[libfirm] / ir / be / bepeephole.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
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.
10  *
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.
14  *
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
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       peephole optimisation framework
23  * @author      Matthias Braun
24  */
25 #ifndef BEPEEPHOLE_H
26 #define BEPEEPHOLE_H
27
28 #include "bearch.h"
29
30 extern ir_node **register_values;
31
32 static inline ir_node *be_peephole_get_value(unsigned register_idx)
33 {
34         return register_values[register_idx];
35 }
36
37 static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
38 {
39         unsigned register_idx = reg->global_index;
40         return be_peephole_get_value(register_idx);
41 }
42
43 /**
44  * Datatype of the generic op handler for optimisation.
45  */
46 typedef void (*peephole_opt_func) (ir_node *node);
47
48 /**
49  * Notify the peephole phase about a newly added node, so it can update its
50  * internal state.  This is not needed for the new node, when
51  * be_peephole_exchange() is used.
52  * Note: Contrary to normal exchange you mustn't remove the node from the
53  * schedule either before exchange. Exchange will do that for you.
54  */
55 void be_peephole_new_node(ir_node *nw);
56
57 /**
58  * When doing peephole optimisation use this function instead of plain
59  * exchange(), so it can update its internal state. */
60 void be_peephole_exchange(ir_node *old, ir_node *nw);
61
62 /**
63  * Tries to optimize a beIncSp node with its previous IncSP node.
64  * Must be run from a be_peephole_opt() context.
65  *
66  * @param node  a be_IncSP node
67  *
68  * @return the new IncSP node or node itself
69  */
70 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
71
72 bool be_has_only_one_user(ir_node *node);
73
74 /**
75  * In a scheduled program with registers assigned,
76  * checks wether @p node can be moved before @p before without changing program
77  * semantics.
78  *
79  * Note: It is allowed to use this function without being in a peephole
80  * optimization phase.
81  */
82 bool be_can_move_down(ir_heights_t *heights, const ir_node *node,
83                       const ir_node *before);
84
85 bool be_can_move_up(ir_heights_t *heights, const ir_node *node,
86                     const ir_node *after);
87
88 /**
89  * Do peephole optimisations. It traverses the schedule of all blocks in
90  * backward direction. The register_values variable indicates which (live)
91  * values are stored in which register.
92  * The generic op handler is called for each node if it exists. That's where
93  * backend specific optimisations should be performed based on the
94  * register-liveness information.
95  */
96 void be_peephole_opt(ir_graph *irg);
97
98 #endif