config.h include added
[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  * Check, if a node produces or consumes a data value.
17  * If it does, it is significant for scheduling and register allocation.
18  * A node produces/consumes a data value, if one of its operands is of
19  * mode datab, or his retuning mode is of mode datab.
20  * @param irn The node to check for.
21  * @return 1, if the node is a data node, 0 if not.
22  */
23 static INLINE int is_data_node(const ir_node *irn)
24 {
25         int i, n;
26
27         /* If the node produces a data value, return immediately. */
28         if(mode_is_datab(get_irn_mode(irn)))
29                 return 1;
30
31         /* else check, if it takes a data value, if that is so, return */
32         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
33                 ir_node *op = get_irn_n(irn, i);
34                 if(mode_is_datab(get_irn_mode(op)))
35                         return 1;
36         }
37
38         /* Else the node does not produce/consume a data value */
39         return 0;
40 }
41
42 /**
43  * Make each constant local to its use.
44  * This duplicates all constants in order to simulate a realistic
45  * register pressure.
46  * @param irg The graph.
47  */
48 void localize_consts(ir_graph *irg);
49
50 /**
51  * Dump a vcg graph containing the controlflow graph, the schedule and
52  * allocated registers.
53  * @param irg The irg. Note that scheduling, register allocation must
54  * have been performed.
55  */
56 void dump_allocated_irg(arch_env_t *env, ir_graph *irg, char *suffix);
57
58
59
60 static INLINE FILE *ffopen(const char *base, const char *ext, const char *mode) {
61         FILE *out;
62         char buf[1024];
63
64         snprintf(buf, sizeof(buf), "%s.%s", base, ext);
65         if (! (out = fopen(buf, mode))) {
66                 fprintf(stderr, "Cannot open file %s in mode %s\n", buf, mode);
67                 return NULL;
68         }
69         return out;
70 }
71
72 #endif