2 * Copyright (C) 1995-2007 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 Some often needed tool-functions
23 * @author Michael Beck
26 #ifndef FIRM_COMMON_IRTOOLS_H
27 #define FIRM_COMMON_IRTOOLS_H
29 #include "firm_config.h"
30 #include "firm_types.h"
33 #include <libcore/lc_opts.h>
34 lc_opt_entry_t *firm_opt_get_root(void);
41 #define MAX(x, y) ((x) > (y) ? (x) : (y))
42 #define MIN(x, y) ((x) < (y) ? (x) : (y))
44 /* calculate the address of the one past last element of an array whose size is
46 #define ENDOF(x) ((x) + sizeof(x) / sizeof(*(x)))
49 * Three valued compare as demanded by e.g. qsort(3)
51 * @param d Another number.
52 * @return 0 if c == d, -1 if c < d, 1 if c > d.
54 #define QSORT_CMP(c, d) (((c) > (d)) - ((c) < (d)))
58 * convert an integer into pointer
60 #define INT_TO_PTR(v) ((void *)((char *)0 + (v)))
63 * convert a pointer into an integer
65 #define PTR_TO_INT(v) ((int)((char *)(v) - (char *)0))
68 * Dump a pset containing Firm objects.
70 void firm_pset_dump(pset *set);
73 * The famous clear_link() walker-function.
74 * Do not implement it by yourself, use this one
76 void firm_clear_link(ir_node *n, void *env);
79 * Copies a node to a new irg. The Ins of the new node point to
80 * the predecessors on the old irg. n->link points to the new node.
82 * @param n The node to be copied
83 * @param irg the new irg
85 * Does NOT copy standard nodes like Start, End etc that are fixed
86 * in an irg. Instead, the corresponding nodes of the new irg are returned.
87 * Note further, that the new nodes have no block.
89 void copy_irn_to_irg(ir_node *n, ir_graph *irg);
92 * Creates an exact copy of a node.
93 * The copy resists on the same graph in the same block.
95 * @param n the node to copy
97 * @note If the copy is not changed, the next CSE operation will
98 * replace it by the original, so beware.
100 ir_node *exact_copy(const ir_node *n);