bepeephole: Inline be_peephole_new_node() into its only caller.
[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  * When doing peephole optimisation use this function instead of plain
36  * exchange(), so it can update its internal state.  This function also removes
37  * the old node from the schedule.
38  */
39 void be_peephole_exchange(ir_node *old, ir_node *nw);
40
41 /**
42  * Tries to optimize a beIncSp node with its previous IncSP node.
43  * Must be run from a be_peephole_opt() context.
44  *
45  * @param node  a be_IncSP node
46  *
47  * @return the new IncSP node or node itself
48  */
49 ir_node *be_peephole_IncSP_IncSP(ir_node *node);
50
51 bool be_has_only_one_user(ir_node *node);
52
53 /**
54  * In a scheduled program with registers assigned,
55  * checks whether @p node can be moved before @p before without changing program
56  * semantics.
57  *
58  * Note: It is allowed to use this function without being in a peephole
59  * optimization phase.
60  */
61 bool be_can_move_down(ir_heights_t *heights, const ir_node *node,
62                       const ir_node *before);
63
64 bool be_can_move_up(ir_heights_t *heights, const ir_node *node,
65                     const ir_node *after);
66
67 /**
68  * Do peephole optimisations. It traverses the schedule of all blocks in
69  * backward direction. The register_values variable indicates which (live)
70  * values are stored in which register.
71  * The generic op handler is called for each node if it exists. That's where
72  * backend specific optimisations should be performed based on the
73  * register-liveness information.
74  */
75 void be_peephole_opt(ir_graph *irg);
76
77 #endif