ia32: prefere != over < or > relation where possible
[libfirm] / ir / ir / iropt_t.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    iropt --- optimizations intertwined with IR construction -- private header.
23  * @author   Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
24  * @version  $Id$
25  */
26 #ifndef FIRM_IR_IROPT_T_H
27 #define FIRM_IR_IROPT_T_H
28
29 #include <stdbool.h>
30 #include "irop_t.h"
31 #include "iropt.h"
32 #include "irnode_t.h"
33 #include "pset.h"
34 #include "tv.h"
35
36 /**
37  * Calculate a hash value of a node.
38  *
39  * @param node  The IR-node
40  */
41 unsigned ir_node_hash(const ir_node *node);
42
43 /**
44  * equivalent_node() returns a node equivalent to input n. It skips all nodes that
45  * perform no actual computation, as, e.g., the Id nodes.  It does not create
46  * new nodes.  It is therefore safe to free n if the node returned is not n.
47  * If a node returns a Tuple we can not just skip it.  If the size of the
48  * in array fits, we transform n into a tuple (e.g., Div).
49  */
50 ir_node *equivalent_node(ir_node *n);
51
52 /**
53  * Creates a new value table used for storing CSE identities.
54  * The value table is used to identify common expressions.
55  */
56 void new_identities(ir_graph *irg);
57
58 /**
59  * Deletes a identities value table.
60  *
61  * @param value_table  the identity set
62  */
63 void del_identities(ir_graph *irg);
64
65 /**
66  * Add a node to the identities value table.
67  */
68 void add_identities(ir_node *node);
69
70 /**
71  * Compare function for two nodes in the hash table. Gets two
72  * nodes as parameters.  Returns 0 if the nodes are a cse.
73  */
74 int identities_cmp(const void *elt, const void *key);
75
76 /**
77  * Return the canonical node computing the same value as n.
78  * Looks up the node in a hash table, enters it in the table
79  * if it isn't there yet.
80  */
81 ir_node *identify_remember(ir_node *n);
82
83 /** Visit each node in the value table of a graph. */
84 void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env);
85
86 /**
87  * Normalize a node by putting constants (and operands with larger
88  * node index) on the right (operator side).
89  *
90  * @param n   The node to normalize
91  */
92 void ir_normalize_node(ir_node *n);
93
94 ir_node *optimize_node(ir_node *n);
95
96 ir_node *optimize_in_place_2(ir_node *n);
97
98 /**
99  * The value_of operation.
100  * This operation returns for every IR node an associated tarval if existing,
101  * returning tarval_bad otherwise.
102  * No calculations are done here, just a lookup.
103  */
104 typedef ir_tarval *(*value_of_func)(const ir_node *self);
105
106 extern value_of_func value_of_ptr;
107
108 /**
109  * Set a new value_of function.
110  *
111  * @param func  the function, NULL restores the default behavior
112  */
113 void set_value_of_func(value_of_func func);
114
115 /**
116  * Returns the associated tarval of a node.
117  */
118 static inline ir_tarval *value_of(const ir_node *n)
119 {
120         return value_of_ptr(n);
121 }
122
123 /**
124  * Sets the default operations for an ir_op_ops.
125  *
126  * @param code   the opcode for the default operation
127  * @param ops    the operations initialized
128  *
129  * @return
130  *    The operations.
131  */
132 ir_op_ops *firm_set_default_operations(unsigned code, ir_op_ops *ops);
133
134 /** NOTE: Survive DCE is considered a bad hack - don't use */
135 typedef struct survive_dce_t survive_dce_t;
136
137 /**
138  * Make a new Survive DCE environment.
139  * NOTE: Survive DCE is considered a bad hack - don't use
140  */
141 survive_dce_t *new_survive_dce(void);
142
143 /**
144  * Free a Survive DCE environment.
145  * NOTE: Survive DCE is considered a bad hack - don't use
146  */
147 void free_survive_dce(survive_dce_t *sd);
148
149 /**
150  * Register a node pointer to be patched upon DCE.
151  * When DCE occurs, the node pointer specified by @p place will be
152  * patched to the new address of the node it is pointing to.
153  *
154  * @param sd    The Survive DCE environment.
155  * @param place The address of the node pointer.
156  */
157 void survive_dce_register_irn(survive_dce_t *sd, ir_node **place);
158
159 #endif