2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief iropt --- optimizations intertwined with IR construction -- private header.
23 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Michael Beck
26 #ifndef FIRM_IR_IROPT_T_H
27 #define FIRM_IR_IROPT_T_H
37 * Calculate a hash value of a node.
39 * @param node The IR-node
41 unsigned ir_node_hash(const ir_node *node);
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).
50 ir_node *equivalent_node(ir_node *n);
53 * Creates a new value table used for storing CSE identities.
54 * The value table is used to identify common expressions.
57 pset *new_identities(void);
60 * Deletes a identities value table.
62 * @param value_table the identity set
64 void del_identities(pset *value_table);
67 * Add a node to the identities value table.
69 void add_identities(pset *value_table, ir_node *node);
72 * Compare function for two nodes in the hash table. Gets two
73 * nodes as parameters. Returns 0 if the nodes are a cse.
75 int identities_cmp(const void *elt, const void *key);
78 * Return the canonical node computing the same value as n.
79 * Looks up the node in a hash table, enters it in the table
80 * if it isn't there yet.
82 ir_node *identify_remember(pset *value_table, ir_node *n);
84 /** Visit each node in the value table of a graph. */
85 void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env);
88 * Normalize a node by putting constants (and operands with larger
89 * node index) on the right (operator side).
91 * @param n The node to normalize
93 void ir_normalize_node(ir_node *n);
95 ir_node *optimize_node(ir_node *n);
97 ir_node *optimize_in_place_2(ir_node *n);
100 * The value_of operation.
101 * This operation returns for every IR node an associated tarval if existing,
102 * returning tarval_bad otherwise.
103 * No calculations are done here, just a lookup.
105 typedef tarval *(*value_of_func)(const ir_node *self);
107 extern value_of_func value_of_ptr;
110 * Set a new value_of function.
112 * @param func the function, NULL restores the default behavior
114 void set_value_of_func(value_of_func func);
117 * Returns the associated tarval of a node.
119 static inline tarval *
120 value_of(const ir_node *n) {
121 return value_of_ptr(n);
125 * Sets the default operations for an ir_op_ops.
127 * @param code the opcode for the default operation
128 * @param ops the operations initialized
133 ir_op_ops *firm_set_default_operations(ir_opcode code, ir_op_ops *ops);
136 * Returns true if a == -b
138 bool is_negated_value(ir_node *a, ir_node *b);