convert remaining APIs from be_irg_t* to ir_graph*
[libfirm] / ir / be / beifg.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       Interface for interference graphs.
23  * @author      Sebastian Hack
24  * @date        18.11.2005
25  * @version     $Id$
26  */
27 #ifndef FIRM_BE_BEIFG_H
28 #define FIRM_BE_BEIFG_H
29
30 #include <stdio.h>
31
32 #include "irnode.h"
33 #include "irnodeset.h"
34
35 #include "becopyopt.h"
36 #include "beirg.h"
37
38 typedef struct be_ifg_t {
39         const be_chordal_env_t *env;
40 } be_ifg_t;
41
42 typedef struct nodes_iter_t {
43         const be_chordal_env_t *env;
44         struct obstack         obst;
45         int                    n;
46         int                    curr;
47         ir_node                **nodes;
48 } nodes_iter_t;
49
50 typedef struct neighbours_iter_t {
51         const be_chordal_env_t *env;
52         const ir_node        *irn;
53         int                   valid;
54         ir_nodeset_t          neighbours;
55         ir_nodeset_iterator_t iter;
56 } neighbours_iter_t;
57
58 typedef struct cliques_iter_t {
59         struct obstack ob;
60         const be_chordal_env_t *cenv;
61         ir_node **buf;
62         ir_node **blocks;
63         int n_blocks, blk;
64         struct list_head *bor;
65         pset *living;
66 } cliques_iter_t;
67
68 void     be_ifg_free(be_ifg_t *ifg);
69 int      be_ifg_connected(const be_ifg_t *ifg, const ir_node *a,
70                           const ir_node *b);
71 ir_node *be_ifg_neighbours_begin(const be_ifg_t *ifg, neighbours_iter_t *iter,
72                                  const ir_node *irn);
73 ir_node *be_ifg_neighbours_next(neighbours_iter_t *iter);
74 void     be_ifg_neighbours_break(neighbours_iter_t *iter);
75 ir_node *be_ifg_nodes_begin(const be_ifg_t *ifg, nodes_iter_t *iter);
76 ir_node *be_ifg_nodes_next(nodes_iter_t *iter);
77 void     be_ifg_nodes_break(nodes_iter_t *iter);
78 int      be_ifg_cliques_begin(const be_ifg_t *ifg, cliques_iter_t *iter,
79                               ir_node **buf);
80 int      be_ifg_cliques_next(cliques_iter_t *iter);
81 void     be_ifg_cliques_break(cliques_iter_t *iter);
82 int      be_ifg_degree(const be_ifg_t *ifg, const ir_node *irn);
83
84 #define be_ifg_foreach_neighbour(ifg, iter, irn, pos) \
85         for(pos = be_ifg_neighbours_begin(ifg, iter, irn); pos != NULL; pos = be_ifg_neighbours_next(iter))
86
87 #define be_ifg_foreach_node(ifg, iter, pos) \
88         for(pos = be_ifg_nodes_begin(ifg, iter); pos != NULL; pos = be_ifg_nodes_next(iter))
89
90 #define be_ifg_foreach_clique(ifg, iter, buf, count) \
91         for(*(count) = be_ifg_cliques_begin(ifg, iter, buf); \
92         *(count) != -1 ; \
93         *(count) = be_ifg_cliques_next(iter))
94
95 typedef struct {
96         int n_nodes;
97         int n_edges;
98         int n_comps;
99 } be_ifg_stat_t;
100
101 void be_ifg_stat(ir_graph *irg, be_ifg_t *ifg, be_ifg_stat_t *stat);
102
103 be_ifg_t *be_create_ifg(const be_chordal_env_t *env);
104
105 /*
106      ____                        _
107     |  _ \ _   _ _ __ ___  _ __ (_)_ __   __ _
108     | | | | | | | '_ ` _ \| '_ \| | '_ \ / _` |
109     | |_| | |_| | | | | | | |_) | | | | | (_| |
110     |____/ \__,_|_| |_| |_| .__/|_|_| |_|\__, |
111                           |_|            |___/
112 */
113
114 typedef struct _be_ifg_dump_dot_cb_t {
115         int  (*is_dump_node)(void *self, ir_node *irn);
116         void (*graph_attr)(FILE *f, void *self);
117         void (*node_attr)(FILE *f, void *self, ir_node *irn);
118         void (*edge_attr)(FILE *f, void *self, ir_node *from, ir_node *to);
119         void (*at_begin)(FILE *file, void *self);
120         void (*at_end)(FILE *file, void *self);
121 } be_ifg_dump_dot_cb_t;
122
123 void be_ifg_dump_dot(be_ifg_t *ifg, ir_graph *irg, FILE *file, const be_ifg_dump_dot_cb_t *cb, void *self);
124
125 #endif