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 Contains some useful function for the backend.
23 * @author Sebastian Hack
26 #ifndef FIRM_BE_BEUTIL_H
27 #define FIRM_BE_BEUTIL_H
31 #include "firm_types.h"
37 typedef __int64 long64;
38 typedef unsigned __int64 ulong64;
41 #define ULL_FMT "ui64"
44 typedef long long long64;
45 typedef unsigned long long ulong64;
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)))
57 * This function always returns the same set.
59 pset *be_empty_set(void);
61 /** Undefine this to disable debugging mode. */
65 * Convenient block getter.
66 * Works also, if the given node is a block.
67 * @param irn The node.
68 * @return The block of the node, or the node itself, if the node is a
71 static inline ir_node *get_block(ir_node *irn)
73 return is_Block(irn) ? irn : get_nodes_block(irn);
76 static inline const ir_node *get_block_const(const ir_node *irn)
78 return is_Block(irn) ? irn : get_nodes_block(irn);
81 static inline int is_firm_be_mode(const ir_mode *mode)
83 return mode_is_data(mode);
87 * Check, if a node produces or consumes a data value.
88 * If it does, it is significant for scheduling and register allocation.
89 * A node produces/consumes a data value, if one of its operands is of
90 * mode datab, or his retuning mode is of mode datab.
91 * @param irn The node to check for.
92 * @return 1, if the node is a data node, 0 if not.
94 static inline int is_data_node(const ir_node *irn)
98 /* If the node produces a data value, return immediately. */
99 if (is_firm_be_mode(get_irn_mode(irn)))
102 /* else check, if it takes a data value, if that is so, return */
103 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
104 ir_node *op = get_irn_n(irn, i);
105 if (is_firm_be_mode(get_irn_mode(op)))
109 /* Else the node does not produce/consume a data value */
114 * Clears the link fields of all nodes of the given graph.
115 * @param irg The graph.
117 void be_clear_links(ir_graph *irg);
120 * Dump a graph with schedule edges.
121 * @param irg The graph.
122 * @param suffix A suffix to its file name.
124 void dump_ir_block_graph_sched(ir_graph *irg, const char *suffix);
127 * Dump a extended block graph with schedule edges.
128 * @param irg The graph.
129 * @param suffix A suffix to its file name.
131 void dump_ir_extblock_graph_sched(ir_graph *irg, const char *suffix);
134 * Dumps a graph and numbers all dumps.
135 * @param irg The graph
136 * @param suffix A suffix to its file name.
137 * @param dumper The dump function
139 void be_dump(ir_graph *irg, const char *suffix, void (*dumper)(ir_graph *, const char *));
142 * Returns the number of reachable nodes in an irg.
143 * @param irg The irg.
144 * @return The number of reachable nodes.
146 unsigned get_num_reachable_nodes(ir_graph *irg);
149 * Gets the Proj with number pn from irn.
151 ir_node *be_get_Proj_for_pn(const ir_node *irn, long pn);
154 * Opens a file named base.ext with the mode mode.
156 FILE *be_ffopen(const char *base, const char *ext, const char *mode);
158 #endif /* FIRM_BE_BEUTIL_H */