added new licence header
[libfirm] / ir / ir / iropt_t.h
1 /*
2  * Copyright (C) 1995-2007 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  * Project:     libFIRM
22  * File name:   ir/ir/iropt_t.h
23  * Purpose:     iropt --- optimizations intertwined with IR construction -- private header.
24  * Author:      Martin Trapp, Christian Schaefer
25  * Modified by: Goetz Lindenmaier, Michael Beck
26  * Created:
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 1998-2003 Universität Karlsruhe
29  */
30
31 /**
32  * @file iropt_t.h
33  *
34  * Declarations for optimizations intertwined with IR construction.
35  *
36  * @author Martin Trapp, Christian Schaefer
37  */
38
39 #ifndef _IROPT_T_H_
40 #define _IROPT_T_H_
41
42 #include "iropt.h"
43 #include "irnode_t.h"
44 #include "pset.h"
45 #include "tv.h"
46
47 ir_node *equivalent_node(ir_node *n);
48
49 /**
50  * Calculate a hash value of a node.
51  * The hash value is calculated from the nodes predecessors.
52  * Special handling for Const and SymConst nodes (these don't have predecessors).
53  *
54  * @param node  The IR-node
55  */
56 unsigned ir_node_hash(ir_node *node);
57
58 /**
59  * Creates a new value table used for storing CSE identities.
60  * The value table is used to identify common expressions.
61  *
62  */
63 pset *new_identities(void);
64
65 /**
66  * Deletes a identities value table.
67  *
68  * @param value_table  the identity set
69  */
70 void  del_identities(pset *value_table);
71
72 /**
73  * Add a node to the identities value table.
74  */
75 void  add_identities(pset *value_table, ir_node *node);
76
77 /**
78  * Compare function for two nodes in the hash table. Gets two
79  * nodes as parameters.  Returns 0 if the nodes are a cse.
80  */
81 int identities_cmp(const void *elt, const void *key);
82
83 /**
84  * Return the canonical node computing the same value as n.
85  * Looks up the node in a hash table, enters it in the table
86  * if it isn't there yet.
87  */
88 ir_node *identify_remember(pset *value_table, ir_node *n);
89
90 /** Visit each node in the value table of a graph. */
91 void visit_all_identities(ir_graph *irg, irg_walk_func visit, void *env);
92
93 ir_node *optimize_node(ir_node *n);
94
95 ir_node *optimize_in_place_2(ir_node *n);
96
97 /**
98  * Returns the tarval of a Const node or tarval_bad for all other nodes.
99  */
100 static INLINE tarval *
101 value_of(ir_node *n) {
102   if ((n != NULL) && (get_irn_op(n) == op_Const))
103     return get_Const_tarval(n); /* might return tarval_bad */
104   else
105     return tarval_bad;
106 }
107
108 /**
109  * Sets the default operations for an ir_op_ops.
110  *
111  * @param code   the opcode for the default operation
112  * @param ops    the operations initialized
113  *
114  * @return
115  *    The operations.
116  */
117 ir_op_ops *firm_set_default_operations(ir_opcode code, ir_op_ops *ops);
118
119 #endif /* _IROPT_T_H_ */