- Bigger refactoring and cleanup in backend:
[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  * @version     $Id$
25  */
26 #ifndef BEPEEPHOLE_H
27 #define BEPEEPHOLE_H
28
29 #include "beirg.h"
30 #include "bearch.h"
31
32 extern ir_node ***register_values;
33
34 static inline ir_node *be_peephole_get_value(unsigned regclass_idx,
35                                              unsigned register_idx)
36 {
37         return register_values[regclass_idx][register_idx];
38 }
39
40 static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
41 {
42         unsigned regclass_idx = arch_register_class_index(arch_register_get_class(reg));
43         unsigned register_idx = arch_register_get_index(reg);
44
45         return be_peephole_get_value(regclass_idx, register_idx);
46 }
47
48 /**
49  * Datatype of the generic op handler for optimisation.
50  */
51 typedef void (*peephole_opt_func) (ir_node *node);
52
53 /**
54  * Notify the peephole phase about a newly added node, so it can update its
55  * internal state.  This is not needed for the new node, when
56  * be_peephole_exchange() is used. */
57 void be_peephole_new_node(ir_node *nw);
58
59 /**
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);
63
64 /**
65  * Tries to optimize a beIncSp node with it's previous IncSP node.
66  * Must be run from a be_peephole_opt() context.
67  *
68  * @param node  a be_IncSP node
69  *
70  * @return the new IncSP node or node itself
71  */
72 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
73
74 /**
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.
81  */
82 void be_peephole_opt(be_irg_t *birg);
83
84 #endif