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