disabled show after showgraph, as it is (or was?) buggy
[libfirm] / ir / ana2 / pto_util.c
1 /* -*- c -*- */
2
3 /*
4    Project:     libFIRM
5    File name:   ir/ana/pto_util.c
6    Purpose:     Utilitites for PTO
7    Author:      Florian
8    Modified by:
9    Created:     Sat Nov 13 19:35:27 CET 2004
10    CVS-ID:      $Id$
11    Copyright:   (c) 1999-2004 Universität Karlsruhe
12    Licence:     This file is protected by the GPL -  GNU GENERAL PUBLIC LICENSE.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 /*
20  pto_util: Utilitites for PTO
21 */
22
23 # include "pto_util.h"
24
25 # include "irnode_t.h"
26 # include "irgwalk.h"
27 # include "xmalloc.h"
28
29 # include "pto_debug.h"
30 # include "gnu_ext.h"
31
32 /* Local Defines: */
33 # ifndef TRUE
34 #  define TRUE 1
35 #  define FALSE 0
36 # endif /* not defined TRUE */
37
38 /* Local Data Types: */
39 /* Environment for find_irg_args */
40 typedef struct find_irg_args_env {
41   ir_node **args;
42   ir_node *arg;
43 } find_irg_args_env_t;
44
45
46 /* Local Variables: */
47
48 /* Local Prototypes: */
49
50 /* ===================================================
51    Local Implementation:
52    =================================================== */
53 /* Helper for find_irg_args */
54 static void find_irg_arg (ir_node *node, void *env)
55 {
56   find_irg_args_env_t *arg_env = (find_irg_args_env_t*) env;
57
58   if (iro_Proj == get_irn_opcode (node)) {
59     if (arg_env->arg == get_Proj_pred (node)) {
60       long n = get_Proj_proj (node);
61
62       assert (! arg_env->args [n]);
63
64       arg_env->args [n] = node;
65     }
66   }
67 }
68
69 /* ===================================================
70    Exported Implementation:
71    =================================================== */
72 /* Find the arguments of a graph. For a method that has n args, the
73   result array has 'n+1' entries, the last of which is written NULL.
74   Note that not all entries in [0..n-1] will be populated all the time.
75 */
76 ir_node **find_irg_args (ir_graph *graph)
77 {
78   ir_type *tp = get_entity_type (get_irg_entity (graph));
79   const int n_args = get_method_n_params (tp);
80   ir_node **args = xcalloc (n_args + 1, sizeof (ir_node*));
81   ir_node *arg = get_irg_args (graph);
82   find_irg_args_env_t *arg_env;
83
84   arg_env = (find_irg_args_env_t*) xmalloc (sizeof (find_irg_args_env_t));
85
86   arg_env->args = args;
87   arg_env->arg  = arg;
88
89   {
90     ir_graph *save = get_current_ir_graph ();
91
92     set_current_ir_graph (graph);
93     irg_walk (get_irg_end (graph), find_irg_arg, NULL, arg_env);
94     set_current_ir_graph (save);
95   }
96
97    memset (arg_env, 0x00, sizeof (find_irg_args_env_t));
98    free (arg_env);
99
100   args [n_args] = NULL;
101
102   return (args);
103 }
104
105 /* Get the entity of a ptr */
106 ir_entity *get_ptr_ent (ir_node *ptr)
107 {
108   ir_entity *ent = NULL;
109   const ir_opcode ptr_op = get_irn_opcode (ptr);
110   switch (ptr_op) {
111   case (iro_Cast): {
112     ent = get_ptr_ent (get_Cast_op (ptr));
113   } break;
114   case (iro_Sel): {
115     ent = get_Sel_entity (ptr);
116   } break;
117
118   case (iro_SymConst): {
119     ent = get_SymConst_entity (ptr);
120   } break;
121
122   default: {
123     fprintf (stderr, "%s: no ent for ptr=%s[%ld]\n",
124              __FUNCTION__,
125              get_op_name (get_irn_op (ptr)),
126              get_irn_node_nr (ptr));
127     assert (0);
128   }
129   }
130
131   return (ent);
132 }
133
134 /* Check whether the load of the given ptr is a dummy */
135 int is_dummy_load_ptr (ir_node *ptr)
136 {
137   const ir_opcode ptr_op = get_irn_opcode (ptr);
138
139   switch (ptr_op) {
140   case (iro_Cast): {
141     return (is_dummy_load_ptr (get_Cast_op (ptr)));
142   } break;
143   case (iro_Sel):
144   case (iro_SymConst): {
145     return (FALSE);
146   } break;
147
148   default: {
149     return (TRUE);
150   }
151   }
152 }
153
154 \f
155 /*
156   $Log$
157   Revision 1.19  2007/01/16 15:45:42  beck
158   renamed type opcode to ir_opcode
159
160   Revision 1.18  2006/12/13 19:46:47  beck
161   rename type entity into ir_entity
162
163   Revision 1.17  2006/06/08 10:49:07  beck
164   renamed type to ir_type
165
166   Revision 1.16  2005/01/14 14:13:32  liekweg
167   fix gnu extension
168
169   Revision 1.15  2005/01/10 17:26:34  liekweg
170   fixup printfs, don't put environments on the stack
171
172   Revision 1.14  2004/12/23 15:47:09  beck
173   removed uneeded allocations
174   used new xcalloc
175
176   Revision 1.13  2004/12/22 14:43:14  beck
177   made allocations C-like
178
179   Revision 1.12  2004/12/21 15:53:12  beck
180   removed GNUC constructs
181
182   Revision 1.11  2004/12/20 17:34:35  liekweg
183   fix recursion handling
184
185   Revision 1.10  2004/12/06 12:55:06  liekweg
186   actually iterate
187
188   Revision 1.9  2004/12/02 16:17:51  beck
189   fixed config.h include
190
191   Revision 1.8  2004/11/26 15:59:14  liekweg
192   recognize dummy loads
193
194   Revision 1.7  2004/11/24 14:53:56  liekweg
195   Bugfixes
196
197   Revision 1.6  2004/11/18 16:37:07  liekweg
198   rewrite
199
200
201 */