32731a33d482fa2daa7c118c2321d45db0205c5b
[libfirm] / ir / ir / pseudo_irg.c
1 /*
2  * Copyright (C) 1995-2007 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 /* -*- c -*- */
21
22 /*
23  * Project:     libFIRM
24  * File name:   ir/external/pseudo_irg.c
25  * Purpose:     implementation
26  * Author:      G"otz Lindenmaier
27  * Modified by: Boris Boesler
28  * Created:     xx.10.2004
29  * CVS-ID:      $Id$
30  * Copyright:   (c) 1999-2004 Universität Karlsruhe
31  */
32
33 #ifdef HAVE_CONFIG_H
34 # include "config.h"
35 #endif
36
37
38 #include "pseudo_irg.h"
39
40 #include "irgraph_t.h"
41 #include "irprog_t.h"
42 #include "array.h"
43
44
45 /* Returns the number of pseudo graphs in the program. */
46 int get_irp_n_pseudo_irgs(void) {
47   assert (irp && irp->pseudo_graphs);
48   return ARR_LEN(irp->pseudo_graphs);
49 }
50
51 /* Returns the pos'th  pseudo graph in the program. */
52 ir_graph *get_irp_pseudo_irg(int pos) {
53   assert(0 <= pos && pos <= get_irp_n_pseudo_irgs());
54   return irp->pseudo_graphs[pos];
55 }
56
57 void add_irp_pseudo_irg(ir_graph *irg) {
58   assert (irp && irp->pseudo_graphs);
59   ARR_APP1(ir_graph *, irp->pseudo_graphs, irg);
60 }
61
62
63 /* Create a new ir graph to build a pseudo representation of a procedure.
64  *
65  *  The pseudo representation can only be used for analyses.  It may not be
66  *  optimized.  Pseudo graphs are kept in a separate graph list in irprog.
67  */
68 ir_graph *
69 new_pseudo_ir_graph(ir_entity *ent, int n_loc) {
70   ir_graph *res = new_r_ir_graph (ent, n_loc);
71   add_irp_pseudo_irg(res);          /* remember this graph global. */
72   return res;
73 }
74
75 /* Returns non-zero ir ir_graph is pseudo graph. */
76 int is_pseudo_ir_graph(ir_graph *irg)
77 {
78   int i, n_pseudo_irgs;
79
80   assert(irg && "nothing here");
81   assert(is_ir_graph(irg) && "no ir_graph given");
82
83   n_pseudo_irgs = get_irp_n_pseudo_irgs();
84   for (i = 0; i < n_pseudo_irgs; ++i) {
85     if (irg == get_irp_pseudo_irg(i)) return 1;
86   }
87   return 0;
88 }
89
90 static int visit_pseudo_irgs = 0;
91
92 void set_visit_pseudo_irgs(int x) {
93   visit_pseudo_irgs = x;
94 }
95
96 int get_visit_pseudo_irgs(void) {
97   return visit_pseudo_irgs;
98 }