typo fixed
[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 "firm_config.h"
30
31 #include <stdio.h>
32
33 #include "firm_types.h"
34 #include "pset.h"
35
36 #include "bearch_t.h"
37
38 #ifdef _MSC_VER
39 typedef          __int64 long64;
40 typedef unsigned __int64 ulong64;
41
42 #define LL_FMT  "i64"
43 #define ULL_FMT "ui64"
44
45 #else
46 typedef          long long long64;
47 typedef unsigned long long ulong64;
48
49 #define LL_FMT  "ll"
50 #define ULL_FMT "llu"
51
52 #endif /* _MSC_VER */
53
54 /* iterate over a list of ir_nodes linked by link field */
55 #define foreach_linked_irns(head, iter) for ((iter) = (head); (iter); (iter) = get_irn_link((iter)))
56
57 /**
58  * Get an empty set.
59  * This function always returns the same set.
60  */
61 pset *be_empty_set(void);
62
63 /** Undefine this to disable debugging mode. */
64 #define BE_DEBUG 1
65
66 /**
67  * Convenient block getter.
68  * Works also, if the given node is a block.
69  * @param  irn The node.
70  * @return The block of the node, or the node itself, if the node is a
71  *         block.
72  */
73 static INLINE ir_node *get_block(ir_node *irn)
74 {
75         return is_Block(irn) ? irn : get_nodes_block(irn);
76 }
77
78 static INLINE const ir_node *get_block_const(const ir_node *irn)
79 {
80         return is_Block(irn) ? irn : get_nodes_block(irn);
81 }
82
83 static INLINE int is_firm_be_mode(const ir_mode *mode)
84 {
85         return mode_is_data(mode);
86 }
87
88 /**
89  * Check, if a node produces or consumes a data value.
90  * If it does, it is significant for scheduling and register allocation.
91  * A node produces/consumes a data value, if one of its operands is of
92  * mode datab, or his retuning mode is of mode datab.
93  * @param irn The node to check for.
94  * @return 1, if the node is a data node, 0 if not.
95  */
96 static INLINE int is_data_node(const ir_node *irn)
97 {
98         int i, n;
99
100         /* If the node produces a data value, return immediately. */
101         if (is_firm_be_mode(get_irn_mode(irn)))
102                 return 1;
103
104         /* else check, if it takes a data value, if that is so, return */
105         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
106                 ir_node *op = get_irn_n(irn, i);
107                 if (is_firm_be_mode(get_irn_mode(op)))
108                         return 1;
109         }
110
111         /* Else the node does not produce/consume a data value */
112         return 0;
113 }
114
115 /**
116  * Dump a vcg graph containing the controlflow graph, the schedule and
117  * allocated registers.
118  * @param irg The irg. Note that scheduling, register allocation must
119  * have been performed.
120  */
121 void dump_allocated_irg(arch_env_t *env, ir_graph *irg, char *suffix);
122
123 void be_clear_links(ir_graph *irg);
124
125 /**
126  * Dump a graph with schedule edges.
127  * @param irg The graph.
128  * @param suffix A suffix to its file name.
129  */
130 void dump_ir_block_graph_sched(ir_graph *irg, const char *suffix);
131
132 /**
133  * Dump a extended block graph with schedule edges.
134  * @param irg The graph.
135  * @param suffix A suffix to its file name.
136  */
137 void dump_ir_extblock_graph_sched(ir_graph *irg, const char *suffix);
138
139 /**
140  * Dumps a graph and numbers all dumps.
141  * @param irg    The graph
142  * @param suffix A suffix to its file name.
143  * @param dumper The dump function
144  */
145 void be_dump(ir_graph *irg, const char *suffix, void (*dumper)(ir_graph *, const char *));
146
147 /**
148  * Returns the number of reachable nodes in an irg.
149  * @param irg The irg.
150  * @return The number of reachable nodes.
151  */
152 unsigned get_num_reachable_nodes(ir_graph *irg);
153
154 /**
155  * Gets the Proj with number pn from irn.
156  */
157 ir_node *be_get_Proj_for_pn(const ir_node *irn, long pn);
158
159 /**
160  * Opens a file named base.ext with the mode mode.
161  */
162 FILE *be_ffopen(const char *base, const char *ext, const char *mode);
163
164 #endif /* FIRM_BE_BEUTIL_H */