Remove address name SymConsts.
[libfirm] / ir / be / beutil.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       Contains some useful function for the backend.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifndef FIRM_BE_BEUTIL_H
27 #define FIRM_BE_BEUTIL_H
28
29 #include <stdio.h>
30
31 #include "firm_types.h"
32 #include "pset.h"
33
34 #include "bearch.h"
35
36 #ifdef _MSC_VER
37 typedef          __int64 long64;
38 typedef unsigned __int64 ulong64;
39
40 #define LL_FMT  "i64"
41 #define ULL_FMT "ui64"
42
43 #else
44 typedef          long long long64;
45 typedef unsigned long long ulong64;
46
47 #define LL_FMT  "ll"
48 #define ULL_FMT "llu"
49
50 #endif /* _MSC_VER */
51
52 /* iterate over a list of ir_nodes linked by link field */
53 #define foreach_linked_irns(head, iter) for ((iter) = (head); (iter); (iter) = get_irn_link((iter)))
54
55 /**
56  * Get an empty set.
57  * This function always returns the same set.
58  */
59 pset *be_empty_set(void);
60
61 /**
62  * Convenient block getter.
63  * Works also, if the given node is a block.
64  * @param  irn The node.
65  * @return The block of the node, or the node itself, if the node is a
66  *         block.
67  */
68 static inline ir_node *get_block(ir_node *irn)
69 {
70         return is_Block(irn) ? irn : get_nodes_block(irn);
71 }
72
73 static inline const ir_node *get_block_const(const ir_node *irn)
74 {
75         return is_Block(irn) ? irn : get_nodes_block(irn);
76 }
77
78 /**
79  * Check, if a node produces or consumes a data value.
80  * If it does, it is significant for scheduling and register allocation.
81  * A node produces/consumes a data value, if one of its operands is of
82  * mode datab, or his retuning mode is of mode datab.
83  * @param irn The node to check for.
84  * @return 1, if the node is a data node, 0 if not.
85  */
86 static inline int is_data_node(const ir_node *irn)
87 {
88         int i, n;
89
90         /* If the node produces a data value, return immediately. */
91         if (mode_is_data(get_irn_mode(irn)))
92                 return 1;
93
94         /* else check, if it takes a data value, if that is so, return */
95         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
96                 ir_node *op = get_irn_n(irn, i);
97                 if (mode_is_data(get_irn_mode(op)))
98                         return 1;
99         }
100
101         /* Else the node does not produce/consume a data value */
102         return 0;
103 }
104
105 /**
106  * Clears the link fields of all nodes of the given graph.
107  * @param irg The graph.
108  */
109 void be_clear_links(ir_graph *irg);
110
111 /**
112  * Dump a graph with schedule edges.
113  * @param irg The graph.
114  * @param suffix A suffix to its file name.
115  */
116 void dump_ir_block_graph_sched(ir_graph *irg, const char *suffix);
117
118 /**
119  * Dump a extended block graph with schedule edges.
120  * @param irg The graph.
121  * @param suffix A suffix to its file name.
122  */
123 void dump_ir_extblock_graph_sched(ir_graph *irg, const char *suffix);
124
125 /**
126  * Dumps a graph and numbers all dumps.
127  * @param irg    The graph
128  * @param suffix A suffix to its file name.
129  * @param dumper The dump function
130  */
131 void be_dump(ir_graph *irg, const char *suffix, void (*dumper)(ir_graph *, const char *));
132
133 /**
134  * Returns the number of reachable nodes in an irg.
135  * @param irg The irg.
136  * @return The number of reachable nodes.
137  */
138 unsigned get_num_reachable_nodes(ir_graph *irg);
139
140 /**
141  * Gets the Proj with number pn from irn.
142  */
143 ir_node *be_get_Proj_for_pn(const ir_node *irn, long pn);
144
145 /**
146  * Returns an array (an ARR_F) of the programs blocks in reverse postorder
147  * (note: caller has to free the memory with DEL_ARR_F after use;
148  *  of course you can use ARR_LEN on the array too.)
149  */
150 ir_node **be_get_cfgpostorder(ir_graph *irg);
151
152 /**
153  * Opens a file named base.ext with the mode mode.
154  */
155 FILE *be_ffopen(const char *base, const char *ext, const char *mode);
156
157 #endif /* FIRM_BE_BEUTIL_H */