Keep flag added
[libfirm] / ir / be / beutil.h
1
2 #ifndef _BEUTIL_H
3 #define _BEUTIL_H
4
5 #include "firm_config.h"
6
7 #include <stdio.h>
8
9 #include "pset.h"
10 #include "irnode.h"
11 #include "bearch.h"
12
13 /** Undefine this to disable debugging mode. */
14 #define BE_DEBUG 1
15
16 /**
17  * Convenient block getter.
18  * Works also, if the given node is a block.
19  * @param  irn The node.
20  * @return The block of the node, or the node itself, if the node is a
21  *         block.
22  */
23 static INLINE const ir_node *get_block(const ir_node *irn)
24 {
25         return is_Block(irn) ? irn : get_nodes_block(irn);
26 }
27
28 static INLINE int is_firm_be_mode(const ir_mode *mode)
29 {
30         return mode_is_data(mode);
31 }
32
33 /**
34  * Check, if a node produces or consumes a data value.
35  * If it does, it is significant for scheduling and register allocation.
36  * A node produces/consumes a data value, if one of its operands is of
37  * mode datab, or his retuning mode is of mode datab.
38  * @param irn The node to check for.
39  * @return 1, if the node is a data node, 0 if not.
40  */
41 static INLINE int is_data_node(const ir_node *irn)
42 {
43         int i, n;
44
45         /* If the node produces a data value, return immediately. */
46         if(is_firm_be_mode(get_irn_mode(irn)))
47                 return 1;
48
49         /* else check, if it takes a data value, if that is so, return */
50         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
51                 ir_node *op = get_irn_n(irn, i);
52                 if(is_firm_be_mode(get_irn_mode(op)))
53                         return 1;
54         }
55
56         /* Else the node does not produce/consume a data value */
57         return 0;
58 }
59
60 /**
61  * Make each constant local to its use.
62  * This duplicates all constants in order to simulate a realistic
63  * register pressure.
64  * @param irg The graph.
65  */
66 void localize_consts(ir_graph *irg);
67
68 /**
69  * Dump a vcg graph containing the controlflow graph, the schedule and
70  * allocated registers.
71  * @param irg The irg. Note that scheduling, register allocation must
72  * have been performed.
73  */
74 void dump_allocated_irg(arch_env_t *env, ir_graph *irg, char *suffix);
75
76 void be_clear_links(ir_graph *irg);
77
78 static INLINE FILE *ffopen(const char *base, const char *ext, const char *mode) {
79         FILE *out;
80         char buf[1024];
81
82         snprintf(buf, sizeof(buf), "%s.%s", base, ext);
83         if (! (out = fopen(buf, mode))) {
84                 fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode);
85                 return NULL;
86         }
87         return out;
88 }
89
90 /**
91  * Dump a graph with schedule edges.
92  * @param irg The graph.
93  * @param suffix A suffix to its file name.
94  */
95 void dump_ir_block_graph_sched(ir_graph *irg, const char *suffix);
96
97 #endif
98
99 /**
100  * Search for an irn in @p accept.
101  * The search is started at @p start_point_exclusive and continues upwards the dom-tree
102  * @return The first node out of accept if found. Else NULL is returned.
103  */
104 ir_node *dom_up_search(pset *accept, ir_node *start_point_exclusive);