beifg: Factorise code to count interference components.
[libfirm] / ir / ir / iropt_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief    iropt --- optimizations intertwined with IR construction -- private header.
9  * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
10  */
11 #ifndef FIRM_IR_IROPT_T_H
12 #define FIRM_IR_IROPT_T_H
13
14 #include <stdbool.h>
15 #include "irop_t.h"
16 #include "iropt.h"
17 #include "irnode_t.h"
18 #include "pset.h"
19 #include "tv.h"
20
21 /**
22  * Calculate a hash value of a node.
23  *
24  * @param node  The IR-node
25  */
26 unsigned ir_node_hash(const ir_node *node);
27
28 /**
29  * equivalent_node() returns a node equivalent to input n. It skips all nodes that
30  * perform no actual computation, as, e.g., the Id nodes.  It does not create
31  * new nodes.  It is therefore safe to free n if the node returned is not n.
32  * If a node returns a Tuple we can not just skip it.  If the size of the
33  * in array fits, we transform n into a tuple (e.g., Div).
34  */
35 ir_node *equivalent_node(ir_node *n);
36
37 /**
38  * Creates a new value table used for storing CSE identities.
39  * The value table is used to identify common expressions.
40  */
41 void new_identities(ir_graph *irg);
42
43 /**
44  * Deletes a identities value table.
45  *
46  * @param value_table  the identity set
47  */
48 void del_identities(ir_graph *irg);
49
50 /**
51  * Add a node to the identities value table.
52  */
53 void add_identities(ir_node *node);
54
55 /**
56  * Compare function for two nodes in the hash table. Gets two
57  * nodes as parameters.  Returns 0 if the nodes are a cse.
58  */
59 int identities_cmp(const void *elt, const void *key);
60
61 /**
62  * Return the canonical node computing the same value as n.
63  * Looks up the node in a hash table, enters it in the table
64  * if it isn't there yet.
65  */
66 ir_node *identify_remember(ir_node *n);
67
68 /** Visit each node in the value table of a graph. */
69 void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env);
70
71 /**
72  * Normalize a node by putting constants (and operands with larger
73  * node index) on the right (operator side).
74  *
75  * @param n   The node to normalize
76  */
77 void ir_normalize_node(ir_node *n);
78
79 ir_node *optimize_node(ir_node *n);
80
81 ir_node *optimize_in_place_2(ir_node *n);
82
83 /**
84  * The value_of operation.
85  * This operation returns for every IR node an associated tarval if existing,
86  * returning tarval_bad otherwise.
87  * No calculations are done here, just a lookup.
88  */
89 typedef ir_tarval *(*value_of_func)(const ir_node *self);
90
91 extern value_of_func value_of_ptr;
92
93 /**
94  * Set a new value_of function.
95  *
96  * @param func  the function, NULL restores the default behavior
97  */
98 void set_value_of_func(value_of_func func);
99
100 /**
101  * Returns the associated tarval of a node.
102  */
103 static inline ir_tarval *value_of(const ir_node *n)
104 {
105         return value_of_ptr(n);
106 }
107
108 /**
109  * returns true if a value becomes zero when converted to mode @p mode
110  */
111 bool ir_zero_when_converted(const ir_node *node, ir_mode *dest_mode);
112
113 int ir_mux_is_abs(const ir_node *sel, const ir_node *mux_false,
114                   const ir_node *mux_true);
115
116 ir_node *ir_get_abs_op(const ir_node *sel, ir_node *mux_false,
117                        ir_node *mux_true);
118
119 /**
120  * return true if the Mux node will be optimized away. This can be used for
121  * the if-conversion callback. Allowing these Muxes should be always safe, even
122  * if the backend cannot handle them.
123  */
124 bool ir_is_optimizable_mux(const ir_node *sel, const ir_node *mux_false,
125                            const ir_node *mux_true);
126
127 /**
128  * Returns true if Conv_m0(Conv_m1( x_m2)) is equivalent to Conv_m0(x_m2)
129  */
130 bool may_leave_out_middle_conv(ir_mode *m0, ir_mode *m1, ir_mode *m2);
131
132 void ir_register_opt_node_ops(void);
133
134 #endif