remove license stuff from files
[libfirm] / ir / be / bepeephole.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       peephole optimisation framework
9  * @author      Matthias Braun
10  */
11 #ifndef BEPEEPHOLE_H
12 #define BEPEEPHOLE_H
13
14 #include "bearch.h"
15
16 extern ir_node **register_values;
17
18 static inline ir_node *be_peephole_get_value(unsigned register_idx)
19 {
20         return register_values[register_idx];
21 }
22
23 static inline ir_node *be_peephole_get_reg_value(const arch_register_t *reg)
24 {
25         unsigned register_idx = reg->global_index;
26         return be_peephole_get_value(register_idx);
27 }
28
29 /**
30  * Datatype of the generic op handler for optimisation.
31  */
32 typedef void (*peephole_opt_func) (ir_node *node);
33
34 /**
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.
40  */
41 void be_peephole_new_node(ir_node *nw);
42
43 /**
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);
47
48 /**
49  * Tries to optimize a beIncSp node with its previous IncSP node.
50  * Must be run from a be_peephole_opt() context.
51  *
52  * @param node  a be_IncSP node
53  *
54  * @return the new IncSP node or node itself
55  */
56 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
57
58 bool be_has_only_one_user(ir_node *node);
59
60 /**
61  * In a scheduled program with registers assigned,
62  * checks whether @p node can be moved before @p before without changing program
63  * semantics.
64  *
65  * Note: It is allowed to use this function without being in a peephole
66  * optimization phase.
67  */
68 bool be_can_move_down(ir_heights_t *heights, const ir_node *node,
69                       const ir_node *before);
70
71 bool be_can_move_up(ir_heights_t *heights, const ir_node *node,
72                     const ir_node *after);
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(ir_graph *irg);
83
84 #endif